【问题标题】:React-native project Build failed: Could not find com.android.tools.lint:lint-gradle:26.1.0React-native 项目构建失败:找不到 com.android.tools.lint:lint-gradle:26.1.0
【发布时间】:2018-09-18 23:18:24
【问题描述】:

我在尝试生成我的 apk 的新版本时遇到了一些问题。 (但是应用程序在使用react-native run-android 进行调试时正常运行)

首先我有这个输出消息:

Task :react-native-maps:compileReleaseJavaWithJavac 注意:一些输入 文件使用或覆盖已弃用的 API。注意:重新编译 -Xlint:deprecation 了解详情。注意:某些输入文件使用未经检查或不安全的操作。注意:使用 -Xlint:unchecked 重新编译 详情。

FAILURE:构建失败并出现异常。

>出了什么问题:无法解析配置':react-native-maps:lintClassPath'的所有文件。

找不到 com.android.tools.lint:lint-gradle:26.1.0。在以下位置搜索: 文件:/C:/Users/kev_w/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.pom 文件:/C:/Users/kev_w/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.jar 文件:/C:/Users/kev_w/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.pom 文件:/C:/Users/kev_w/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.jar 文件:/C:/Users/kev_w/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.pom 文件:/C:/Users/kev_w/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.jar 文件:/C:/Users/kev_w/.m2/repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.pom 文件:/C:/Users/kev_w/.m2/repository/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.jar https://jcenter.bintray.com/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.pom https://jcenter.bintray.com/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0.jar 文件:/C:/Users/kev_w/Desktop/Ulabs/appreactnative/testApp/node_modules/react-native/android/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0。绒球 文件:/C:/Users/kev_w/Desktop/Ulabs/appreactnative/testApp/node_modules/react-native/android/com/android/tools/lint/lint-gradle/26.1.0/lint-gradle-26.1.0。罐 要求: 项目:react-native-maps*

1.我做了什么来解决这个问题: 在我的 android/build.gradle >> allprojects {...} 中添加 google()

buildscript {
    repositories {
        mavenLocal()
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        google()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

添加后,构建成功,但是当我打开它时我的apk立即崩溃......

正如我一开始所说,在添加google() 之前,我的项目在react-native run-android 的调试中正常运行。 但是现在,apk 和调试项目都不起作用。

它在没有任何日志的情况下崩溃。

然后我尝试运行 apk build 删除 google() 并在我的 android/app/build.gradle 中添加 lintOptions

android {
 (...)
    lintOptions {

        checkReleaseBuilds false
        abortOnError false
    }
}

在我的android/app/build.gradle 中,为了避免 lint-gradle 错误 > 它不起作用。

这是我的全部android/app/build.gradle

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.testapp"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }

    android {
        lintOptions {
            abortOnError false
            checkReleaseBuilds false
        }
    }

    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    compile project(':react-native-linear-gradient')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile project(':react-native-linear-gradient')
    compile project(':react-native-device-info')
    /*implementation project('react-native-maps')*/
    implementation(project(':react-native-maps')){
        exclude group: 'com.google.android.gms', module: 'play-services-base'
        exclude group: 'com.google.android.gms', module: 'play-services-maps'
    }
    implementation 'com.google.android.gms:play-services-base:11.0.4'
    implementation 'com.google.android.gms:play-services-maps:11.0.4'
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

我花了几个小时试图在网上找到解决方案,但对我没有任何帮助。要么我的run-android 工作并且应用程序没有崩溃但无法构建任何 apk,或者我可以构建它但当我运行它时它立即崩溃(apk 或 run-android)......

如果有人可以拯救我的心理健康,请^^...

【问题讨论】:

  • 你解决了吗?

标签: android react-native gradle


【解决方案1】:

您在 jcenter() 之前尝试过 google() 吗?它对我有用:

buildscript {
    repositories {
        google()
        jcenter()
        gradlePluginPortal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'
        // NOTE: Do not place your application dependencies here;
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

【讨论】:

  • 当我在jcenter() 之前将google() 添加到allprojects 时,这对我有帮助。但是,当我尝试将google() 放在buildscript 的首位时,出现错误。它可以编译,所以我会满足于不是 100% 理解这里发生的事情。
  • 顺序对我来说并不重要,可能与您项目中的依赖构建有关。
【解决方案2】:

我们遇到了完全相同的问题,并找到了两种解决方法。

第一个:将gradle降级到2.2.3版

更好的一个:对我来说,问题是由 react-native-map 创建的,要解决它,您必须从

编辑 app/build.gradle
implementation 'com.google.android.gms:play-services-base:11.0.4'
implementation 'com.google.android.gms:play-services-maps:11.0.4'

到:

implementation "com.google.android.gms:play-services-base:+"
implementation "com.google.android.gms:play-services-maps:+"

【讨论】:

  • 不建议使用“+”指定依赖版本,因为您的构建将来可能无法重现。
  • 确实,这是个问题。但我尝试了很多版本,只有“+”在工作。有没有办法知道哪个版本是好版本? (没有尝试所有这些)
【解决方案3】:

以下代码对我有用。

 // Top-level build file where you can add configuration options common to all sub- 
  projects/modules.

 buildscript {
repositories {
    google()
    jcenter()

}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.3'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    google()
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

【讨论】:

  • 请显示此答案添加到other answer
  • 不鼓励仅使用代码回答,因为它们没有为未来的读者提供太多信息,请对您所写的内容提供一些解释
猜你喜欢
  • 2021-12-25
  • 2021-01-05
  • 2018-10-31
  • 1970-01-01
  • 1970-01-01
  • 2019-05-04
  • 2018-10-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多