8

I created a new react native project and ran react-native run-android.

However, I am getting this error:

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade

Here's the screenshot: error 1

Here's my android/build.gradle:

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

buildscript {
    ext {
        buildToolsVersion = "29.0.2"
        minSdkVersion = 16
        compileSdkVersion = 29
        targetSdkVersion = 29
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.3")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
}

I am new with react native and this is a new project so any help will be appreciated.

Beep Boop
  • 327
  • 6
  • 30
  • https://stackoverflow.com/questions/57606462/a-failure-occurred-while-executing-com-android-build-gradle-internal-tasks – Hend El-Sahli Nov 04 '20 at 08:28
  • @Hend El-Sahli Apparently none of the solutions helped and I am still getting the error. – Beep Boop Nov 04 '20 at 09:16
  • Did you get this issue only in this specific project? I mean try creating a new project, to see if it has to do with your RN-installation – Hend El-Sahli Nov 04 '20 at 09:26
  • Yeah I created another new React Native project and faced the same issue. At first it says it's missing `android.jar` which I added manually to its designated folder. And after that I get this problem which I have posted here. – Beep Boop Nov 04 '20 at 12:49
  • 3
    Then It's an installation issue ... I guess it's not the best way to resolve this issue by **copying the missing android.jar file** ... The error indicates that **You have Android API not installed ... or partially installed** ...From your Android-Studio > Configure > Sdk Manager --> check installed api-levels and make sure API Level-29 is installed ... and make sure **buildToolsVersion = "29.0.2** is installed OR set buildToolsVersion to the once installed in your device – Hend El-Sahli Nov 04 '20 at 15:37
  • Thank you so much! I installed the Level-29 and it solved the issue. – Beep Boop Nov 04 '20 at 18:07
  • Happy coding...! – Hend El-Sahli Nov 04 '20 at 18:18

2 Answers2

1

Solution-1: The problem was resolved by deleting and re-creating the AVD (Android Virtual Device) file. The AVD can be deleted from Android Studio. It is usually saved at C:\Users\<userName>\.android\avd

Most likely, you also need to execute the following commands.

cd <project_filder> 
cd android
gradlew clean

In case you did not notice the comments on the question (above), please check them out. They include more suggestions, which might be relevant to the problem.

1st Update:

Solution-2: In some other instance, in addition to deleting and re-creating the AVD, I had to do the following steps.

REM 1. Removing cache files
rd %localappdata%\Temp\metro-cache /s /q 
del %localappdata%\Temp\haste-map*

REM 2. Cleaning Gradle files
cd <project_filder> 
cd android & gradlew clean & cd .. 

REM 3. Deleting node_modules
rd node_modules /q /s 

REM 4. Cleaning npm cache
npm cache clean --force 

REM 5. Re-installing npm modules
npm install

2nd Update:

Solution-3: In a 3rd instance, I had to add the following line in the file <proj-folder>/android/gradle.properties

org.gradle.jvmargs=-Xmx4608m
Bilal Abdeen
  • 1,627
  • 1
  • 19
  • 41
0

Worth noting I encountered this in a native (Kotlin) Android project. For me this was caused by having densities specified in my resConfigs:

build.grade (:app)

developLint {
    dimension "version"
    resConfigs "en",  "he-rIL", "iw-rIL", "xxhdpi"
}

(Note the "xxhdpi" above)

Removing the density solved the problem.

Eran Boudjnah
  • 1,228
  • 20
  • 22