5

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?

5 Answers5

3

Ran into this myself.

The android getting started documents aren't quite right.

Instead of installing Android 8.0 & SDK Platform 26.0.3, choose Android 8.1 & 27.0.3

Note this is for React-Native 0.57.3

MrNickel
  • 426
  • 4
  • 9
1

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.

-1

Ok I bumped into this error and i was able to solve it, don't know if it's the right way, buh it solved my problem.

your app/build.gradle should look like this!!

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"
   .....
}
Moplio
  • 250
  • 2
  • 5
  • 15
-1

I solve this error by this:

Project.gradle:

buildscript {

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:

android {

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

}

dependencies {

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

i think the gradle tools of 3.2.1 and gradle-4.6-all.zip ara not match yet.

-1

I have achieved like this:

  1. Open a new Product in Android Studio .
  2. Upgrade the gradle completely and
  3. then try react-native run-android . Worked for me .
karan
  • 3,319
  • 1
  • 35
  • 44