【问题标题】:Could not resolve com.android.tools.build:gradle:3.1.4, react-native run-android无法解析 com.android.tools.build:gradle:3.1.4,react-native run-android
【发布时间】:2019-02-27 22:33:28
【问题描述】:

我正在尝试做我的第一个react-native run-android,但我收到以下错误:

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

我的 build.gradle 文件是这样的:

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

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
    repositories {
        // mavenCentral()

        google()
        // maven {
        //     url "https://maven.google.com"
        // }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'

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

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


task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin", "all")
}

正如您从注释掉的行中看到的那样,我根据以前的答案here尝试了多种组合

每个错误消息的共同点是

java.lang.RuntimeException:意外错误: java.security.InvalidAlgorithmParameterException:trustAnchors 参数必须为非空

我也尝试过 cd android/ && gradlew clean,我也尝试过将 gradle 版本更改为类路径。结果都一样。

有什么建议吗?

【问题讨论】:

    标签: java android react-native


    【解决方案1】:

    我自己也遇到了。

    android 入门文档不太对。

    不要安装 Android 8.0 和 SDK 平台 26.0.3,而是选择 Android 8.1 和 27.0.3

    注意这是针对 React-Native 0.57.3

    【讨论】:

      【解决方案2】:

      实际上,我能够通过卸载并重新安装所有东西(java jdk、react-native-cli、android-studio、watchman)来解决我的问题。

      这可能是 java 问题,因为在我的第一次 react-native 设置中,我错误地安装了 java-jdk-11,它 与 android sdk 不兼容react-native 依赖,而 java-jdk-8 是需要的 (例如here)。但是当我降级到 jdk-8 并安装了所有其他东西时,由于某些与认证相关的问题,它无法正常工作,我无法按照建议的 elsewhere 修复。

      所以我做了一个新的开始,在卸载所有东西之后,从 java-jdk-8 开始,然后是 react-native-cli 和其他所有东西,如 react-native official "Getting started" guide 中所述。然后它就可以工作了,根本没有改变 build.gradle 文件。

      很遗憾,官方指南说: “如果需要,请下载并安装 Oracle JDK 8 或更新版本。您也可以使用 OpenJDK 8 或更新版本作为替代方案”,但似乎并非如此。

      【讨论】:

        【解决方案3】:

        好的,我遇到了这个错误,我能够解决它,不知道这是不是正确的方法,但它解决了我的问题。

        你的 app/build.gradle 应该是这样的!!

        android {
            compileSdkVersion 27
            buildToolsVersion '27.0.3'
        
            defaultConfig {
                ...
                minSdkVersion 16
                targetSdkVersion 27
                versionCode 1
                versionName "1.0"
                ndk {
                    abiFilters "armeabi-v7a", "x86"
                }
            }
        }
        
        
        dependencies {
           ...
            compile "com.android.support:appcompat-v7:27.1.0"
           .....
        }
        

        【讨论】:

          【解决方案4】:

          我通过这个解决了这个错误:

          项目.gradle:

          构建脚本 {

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

          }

          app.gradle:

          安卓{

          compileSdkVersion 26
          defaultConfig {
            ...
              minSdkVersion 19
              targetSdkVersion 26
            ...
          }
          buildTypes {
              release {
                  minifyEnabled false
                  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
              }
          }
          

          }

          依赖{

          implementation fileTree(dir: 'libs', include: ['*.jar'])
          implementation 'com.android.support:appcompat-v7:27.1.1'
          implementation 'com.android.support.constraint:constraint-layout:1.1.3'
          testImplementation 'junit:junit:4.12'
          androidTestImplementation 'com.android.support.test:runner:1.0.2'
          androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
          

          }

          gradle-wrapper.properties

          distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip

          我认为 3.2.1 和 gradle-4.6-all.zip 的 gradle 工具还不匹配。

          【讨论】:

            【解决方案5】:

            我是这样实现的:

            1. 在 Android Studio 中打开一个新产品。
            2. 完全升级gradle和
            3. 然后试试 react-native run-android 。 为我工作。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2021-02-23
              • 2016-10-03
              • 2019-01-14
              • 1970-01-01
              • 1970-01-01
              • 2019-05-19
              相关资源
              最近更新 更多