15

I am having problems running my React Native application that was running fine just yesterday. Therefore I ran the command:

npx react-native run-android -- --warning-mode=all

Which gives information starting with:

> Task :react-native-async-storage_async-storage:generateDebugRFile FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

FAILURE: Build failed with an exception.

...

* What went wrong:
Execution failed for task ':react-native-async-storage_async-storage:generateDebugRFile'.
> Could not resolve all files for configuration ':react-native-async-storage_async-storage:debugCompileClasspath'.
> Failed to transform react-native-0.71.0-rc.0-debug.aar (com.facebook.react:react-native:0.71.0-rc.0) to match attributes {artifactType=android-symbol-with-package-name, com.android.build.api.attributes.BuildTypeAttr=debug, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-api}.
  > Execution failed for JetifyTransform: C:\Users\pangi\.gradle\caches\modules-2\files-2.1\com.facebook.react\react-native\0.71.0-rc.0\7a7f5a0af6ebd8eb94f7e5f7495e9d9684b4f543\react-native-0.71.0-rc.0-debug.aar.
     > Java heap space

My first problem is how to resolve this issue? I seem to be unable to find resolutions for this particular issue on the Internet. Obviously it is related to the 'async storage' package and I did update it, however that did not resolve the issue.

Supposedly using the "--warning-mode=all" verbiage should provide links to Gradle to help resolve the issue...however I see none. I also notice in that output mention is given of 'react-native-0.71' however I am using a lower version...not sure if that is related to the issue. Any advice appreciated.

My second question is more general. Why do nonsensical and ridiculous things like this CONSTANTLY happen in React Native? As mentioned, the code worked fine last time I booted up. I can make no changes whatsoever to my code (or minimal ones) and suddenly the code is broken and non-functional...through no fault of my own but relating to some npm package or some other reason (Gradle for example) that has nothing to do with me. I have never seen, nor imagined...that such an unreliable and 'bug-ridden' piece of software could be released to the general public. Why are issues like this consistently occurring in React Native? Is it just incompetence or is there a better answer? I am always dealing with unending frustration and anger due to these practices causing me problems with this particular platform. If somebody could explain why this development 'environment' is riddled with these problems I would be most appreciative.

Pangit
  • 564
  • 1
  • 7
  • 23
  • Does this answer your question? [Android Build Failure: Common Issue- Failed to install the app. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081](https://stackoverflow.com/questions/74334162/android-build-failure-common-issue-failed-to-install-the-app-error-command-f) – Thanhal P A Nov 06 '22 at 13:10
  • 1
    Yes your response seems to be the problem solver...thanks again for your input. Regards. – Pangit Nov 07 '22 at 01:19

4 Answers4

41

There will be build failures for Android due to the publish of the React Native version 0.71.0-rc0.

Add this fix to your android -> build.gradle file as follows:

buildscript {
    // ...
}


allprojects {
    repositories {
       exclusiveContent {
           filter {
               includeGroup "com.facebook.react"
           }
           forRepository {
               maven {
                   url "$rootDir/../node_modules/react-native/android"
               }
           }
       }
        // ...
    }
}

What this fix will do is apply an exclusiveContent resolution rule that will force the resolution of React Native Android library, to use the one inside node_modules

If the above doesn't fix your issue then, try the Method 2 mentioned here : React Native Android build failure with different errors without any changes in code for past days due to publish of React Native version 0.71.0-rc.0

Thanhal P A
  • 4,097
  • 3
  • 18
  • 38
16

The OP seem angry and honestly, i do understand why he is and i doubt why he shouldnt. I havent run build for 2 days until yesterday, 5th of november when i ran npx react-native run-android then this error was noticed. I had spent close to 24 hours searching the solution until i stumbled on this question.

This fix according to @Thanhal works for me.

I tweaked my android/build.gradle. Here is the full content of my gradle file and the fix.

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

buildscript {

    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        ndkVersion = "21.4.7075529"
        kotlinVersion = '1.6.0'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.2")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {

        // ------ Fix starts here

        exclusiveContent {
           filter {
               includeGroup "com.facebook.react"
           }
           forRepository {
               maven {
                   url "$rootDir/../node_modules/react-native/android"
               }
           }
       }
       
       // --------- Fix ends here

       
        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")
        }
        mavenCentral {
            // We don't want to fetch react-native from Maven Central as there are
            // older versions over there.
            content {
                excludeGroup "com.facebook.react"
            }
        }
        google()
        maven { url 'https://www.jitpack.io' }
    }
}

I hope this also helps somebody out there.

Sir'Energieman
  • 237
  • 1
  • 6
  • Thanks for your post, the response from @Thanhal seems to work for me as well however it was still nice to see your build.gradle file to compare with mine, regards. – Pangit Nov 07 '22 at 01:17
3
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
# distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

enter image description here

update distributionUrl

Sourabh Gera
  • 862
  • 7
  • 7
2

Recently I fix this issue b update the version of React Native. I had this 0.68.1 version when I stuck in this error. you can easily update your version From here how to update your version From here

after that I clean android Gradle by run this command. go to your project a android directory and run this

./gradlew clean

then comes back to project and run

npm install

after that uninstall the application From your mobile and run your project again

ABDULLAH
  • 550
  • 3
  • 13
  • Thanks for your post, but I wish to stay at my current version of React Native without updating to another version. Build issues are one reason I prefer to stay with a lower version, as I consider it more stable. The response(s) above (the code added into build.gradle) did solve the issue as well. Regards – Pangit Nov 11 '22 at 21:01