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
Asked Answered
I

5

50

Note: Error may be different but if you are getting any error when taking android build without any changes in code for past two days

My Error - Failed to install the app. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

error Failed to install the app. Make sure you have the Android development environment set up:

Error: Command failed: ./gradlew app:installDebug
-PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* Where: Build file '/Users/....../node_modules/react-native-month-year-picker/android/build.gradle' line: 115

* What went wrong: A problem occurred configuring project ':react-native-month-year-picker'.

> Could not resolve all files for configuration ':react-native-month-year-picker:implementation'.
   > Could not resolve com.facebook.react:react-native:+.
     Required by:
         project :react-native-month-year-picker
      > Cannot choose between the following variants of com.facebook.react:react-native:0.71.0-rc.0:
          - debugVariantDefaultRuntimePublication
          - releaseVariantDefaultRuntimePublication
        All of them match the consumer attributes:
          - Variant 'debugVariantDefaultRuntimePublication' capability com.facebook.react:react-native:0.71.0-rc.0:
Ivelisseivens answered 6/11, 2022 at 7:59 Comment(0)
I
100

The build failures for Android was due to the publish of the React Native version 0.71.0-rc0.

Note: Error may be different but this would be the solution if you are getting android build failures without any changes in code for past two days

before trying these methods please revert back every changes you have done : https://mcmap.net/q/355480/-app-is-being-crashed-instantly-after-build-java-lang-unsatisfiedlinkerror-couldn-39-t-find-dso-to-load-libturbomodulejsijni-so

Method 1

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

Method 2

If your gradle doesn't support above, then add this to your android -> build.gradle file as follows:

def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())


buildscript {
     // ...
}
    
    
allprojects {
    configurations.all {
          resolutionStrategy {
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
          }
    }
    // ...  
}

Ref: Fix and updates on Android build failures happening since Nov 4th 2022 #35210

Ivelisseivens answered 6/11, 2022 at 7:59 Comment(6)
Okay, thanks again. But mate, do you know why ? Is this due to the + in the end of this line implementation "com.facebook.react:react-native:+" ? in android/app/build.gradleStramonium
Reason and all mentioned here : github.com/facebook/react-native/issues/35210Ivelisseivens
#74336982 solved this issue tooAlaynaalayne
I was having react native 0.66.3 and i updated it with 0.66.5 as suggested by react native latest fix. But unfortunately it is still not working and I am getting Execution failed for task ':app:checkDebugAarMetadata'. > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction > The minCompileSdk (31) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-30)Tatter
@RavisFarooq please try rebuilding by changing the compileSdkVersion in build.gradle file to 31..... If that doesn't workout please revert back the changes and downgrade react-native to 0.66.3 which was worked fine before and apply the solution mentioned here and try againIvelisseivens
https://mcmap.net/q/355480/-app-is-being-crashed-instantly-after-build-java-lang-unsatisfiedlinkerror-couldn-39-t-find-dso-to-load-libturbomodulejsijni-soIvelisseivens
N
7

Adding on to the voted answer to do some knowledge sharing.

To reiterate, as @Thanhal has posted, the solution and official explanation can be found here: Android build failures No matching variant of com.facebook.react:react-native:0.71.0-rc.0 was found.

The biggest question I needed answer following the error was:

After specifying my react-native version in package.json, why does my project still download another react-native version?

I even used npm install --save-exact to ensure I am getting the correct version

The error message I was given left me even more confused:

The class is loaded from ~/.gradle/caches/transforms-3/9a8c596b7e1788d5bad7c80991eefff1/transformed/jetified-kotlin-stdlib-1.6.10.jar!/kotlin/Unit.class e: .../node_modules/expo-modules-core/android/src/main/java/expo/modules/adapters/react/permissions/PermissionsService.kt: (351, 32): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.1.

Somehow Kotlin became an issue for me as well.

Who / What is asking for the latest react-native?

For my case, the issue here wasn't about the version of react-native my project is using. It was about what my libraries are using.

The react-native team had been shipping a Maven Repository inside the NPM package (node_modules/react-native/android/) up till 0.71.0-rc.0. Most of the libraries have their build.gradle configured to reference to this directory. This is done through declaring a custom repository in the libraries' build.gradle:

maven {
    url "$rootDir/../node_modules/react-native/android"
}

But in the libraries' build.gradle files, more repositories are declared, which may look like this:

repositories {
  maven {
    url "$rootDir/../node_modules/react-native/android"
  }
  google()
  mavenLocal()
  mavenCentral()
}

Then, the dependency for the library is declared as so:

dependencies {
  implementation 'com.facebook.react:react-native:+'
}

Because the "+" as version for the react-native dependency, Gradle will take the latest react-native version from the various declared repositories.

Since in the past react-native was shipped with npm package, the latest which Gradle will always take the react-native in node_modules. However, now that the react-native team is publishing the library to public repositories including MavenCentral, Gradle honours the "+" and take the version on MavenCentral instead.

Why did I get the Kotlin error?

My project uses an older version of react-native and as of version 0.68 react-native started using Kotlin version 1.6.10 (see the change history). So yes, the difference in react-native version would also result in Kotlin error.

Nursemaid answered 8/11, 2022 at 16:47 Comment(0)
T
1

Facebook has release bugfix versions for >=0.63. You can upgrade instead of apply the hotfix also.

https://github.com/facebook/react-native/issues/35210

Thaddeusthaddus answered 8/11, 2022 at 19:12 Comment(0)
A
0

I have tried to generate an APK for my React Native application, but I don't know what issue is causing the newly created APK file to have no changes compared to the previous APK.

I am using the command ./gradlew assembleRelease to create the APK.

I have deleted the file android/app/src/main/assets/index.android.bundle and run the following:

npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

I have also cleaned the project and rebuilt it, but the issue still persists.

I have fix it. The issue was with the versionName in the android/build.gradle file. I was using versionName '4.0.2', and now I have changed it to versionName '4.0.3', and it's working fine.

Analyst answered 20/6, 2023 at 4:18 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewWeisbrodt
A
-1

This fix works:

Reason for Failures : The build failures for Android was due to the publish of the React Native version 0.71.0-rc0 to Maven and because of which when the gradle is syncing its picking this 0.71.0-rc0 version of react-native rather then your current version of react-native.

Made it work without upgrading react-native version and by adding this in build.gradle, this works (hermes enabled or not, along with flipper too)

 exclusiveContent {
            // We get React Native's Android binaries exclusively through npm,
            // from a local Maven repo inside node_modules/react-native/.
            // (The use of exclusiveContent prevents looking elsewhere like Maven Central
            // and potentially getting a wrong version.)
            filter {
                includeGroup "com.facebook.react"
            }
            forRepository {
                maven {
                    url "$rootDir/../node_modules/react-native/android"
                }
            }
        }

final snippet looks like this

allprojects {
    repositories {
        exclusiveContent {
            // We get React Native's Android binaries exclusively through npm,
            // from a local Maven repo inside node_modules/react-native/.
            // (The use of exclusiveContent prevents looking elsewhere like Maven Central
            // and potentially getting a wrong version.)
            filter {
                includeGroup "com.facebook.react"
            }
            forRepository {
                maven {
                    url "$rootDir/../node_modules/react-native/android"
                }
            }
        }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")

gradle clean and rebuild after this fix. Then you can react native run android successfully.

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

Now,

There are some patch releases from react native for different versions, If you dont want to put this fix, you can update your current react native version to the react native patch version as mentioned here

https://github.com/facebook/react-native/issues/35210

Adhibit answered 8/11, 2022 at 16:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.