Could not resolve com.android.tools.build:gradle:3.1.4, react-native run-android

Dimitris Papazacharias :

I am trying to do my first react-native run-android but I get the following error:

FAILURE: Build failed with an exception.

My build.gradle file is this:

// 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")
}

As you can see from the commented out lines, I have tried multiple combinations based to former answers here

The common denominator of every error message is the

java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

I have also tried cd android/ && gradlew clean, and I have also tried changing gradle versions to classpath. All with the same result.

Any suggestions?

Dimitris Papazacharias :

Actually, I was able to get past my problem, by uninstalling and re-installing everything (java jdk, react-native-cli, android-studio, watchman).

It probably was a java issue, because on my first react-native setup, I mistakenly installed java-jdk-11, which is not compatible with android sdk that react-native depends on, and java-jdk-8 is needed instead (as mentioned here, for example). But when I downgraded to jdk-8 with all the other stuff already installed, it wasn't working, due to some certification related issue, that I couldn't fix as suggested elsewhere.

So I did a fresh start, after uninstalling everything, starting from java-jdk-8, then react-native-cli, and everything else, as documented in the react-native official "Getting started" guide. Then it it worked, without altering build.gradle file at all.

It is sad that the official guide says: "Download and install Oracle JDK 8 or newer if needed. You can also use OpenJDK 8 or newer as an alternative", which, as it seems, is not the case.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=82233&siteId=1