react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[FIXED] Android build failures `No matching variant of com.facebook.react:react-native:0.71.0-rc.0 was found.`

Open cortinico opened this issue 3 years ago • 184 comments
trafficstars

Description

Hey all, I'd like to share an update on a series of build failures React Native & Expo users have been experiencing when building Android apps starting from November 4th 2022.

We'd like to apologize for the disruption this caused to your developer workflows. The React team is fully committed to delivering a smooth developer experience, and we take this type of issues extremely seriously.

📢 Patches for >= 0.63

We have prepared releases for all the main versions of react-native with an hotfix:

🛳 0.70.5: https://github.com/facebook/react-native/releases/tag/v0.70.5 🛳️ 0.69.7: https://github.com/facebook/react-native/releases/tag/v0.69.7 🛳 0.68.5: https://github.com/facebook/react-native/releases/tag/v0.68.5 🛳️ 0.67.5: https://github.com/facebook/react-native/releases/tag/v0.67.5 🛳️ 0.66.5: https://github.com/facebook/react-native/releases/tag/v0.66.5 🛳️ 0.65.3: https://github.com/facebook/react-native/releases/tag/v0.65.3 🛳️ 0.64.4: https://github.com/facebook/react-native/releases/tag/v0.64.4 🛳️ 0.63.5: https://github.com/facebook/react-native/releases/tag/v0.63.5

By updating to these patch versions, your Android build should start working again.

To do so, in your package.json change react-native's version to the relevant new patch (ex. if you are on 0.64.3, change to 0.64.4) and run yarn install. No other changes should be necessary, but you might want to clean your android artifacts with a cd android && ./gradlew clean before trying to re-run your Android app.

Fix for older react-native (< 0.63)

The fix above only works on gradle 6.2 and higher. Older react-native used older gradle.

You may determine your gradle version by looking in your /android/gradle/wrapper/gradle-wrapper.properties file.

If you are on an older version of react-native (for example 0.63 or earlier) that uses gradle version 6.1 or below, you must use a different workaround as gradle 6.1 does not support exclusiveContent.

Add this in the allprojects area of your android/buld.gradle file.

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())

allprojects {
    configurations.all {
        resolutionStrategy {
            // Remove this override in 0.65+, as a proper fix is included in react-native itself.
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }

Instead of using exclusiveContent, the hotfix must force the version of React Native. The recommended hotfix shells out to node to read your current version of react-native. If you hard code the version of react-native, when you upgrade your project in the future, your build will fail if you forget to remove this hotfix.

Note that this fix is fragile as the location of your package.json could be different if you are in a monorepo, and node might not be available if you use a node package manager like nvm.

Thank you @mikehardy for finding and providing this fix in your comment.

Technical Details

The issue

On November 4th 2022 we published the React Native version 0.71.0-rc0, the first release candidate for the 71 release series, on several public repositories. Specifically, this version was also published on Maven Central as we're updating our artifacts distribution strategy (technical details are explained below).

This event resulted in build failures for Android on several users as they ended up downloading the wrong React Native version (0.71.0-rc0 instead of the version they were using in their project, say 0.68.0).

The build error looks something like this:

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

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'My Project'.
Could not determine the dependencies of null.
Could not resolve all task dependencies for configuration ':classpath'.
    > Could not resolve com.facebook.react:react-native:+.
      Required by:
          project :
    > No matching variant of com.facebook.react:react-native:0.71.0-rc.0 was found. 
      The consumer was configured to find a runtime of a library compatible with Java 11, 
      packaged as a jar, and its dependencies declared externally, as well 
      as attribute 'org.gradle.plugin.api-version' with value '7.3.3' but:

Sadly, due to how older projects of React Native were created in the past, we couldn't simply re-publish older versions, and we're asking users to update their template using the fix suggested below.

Why this happened

Historically, the React Native template provided build.gradle files that contain a dependency on the React Native Android library as follows: implementation("com.facebook.react:react-native:+").

Specifically, the + part of this dependency declaration is causing Gradle to pick the highest version among all the declared repositories (often referred as Gradle Dynamic versions). Till React Native version 0.70, we were shipping a Maven Repository inside the NPM package (inside the ./android folder). Starting from 0.71, we moved such folder and uploaded it to Maven Central.

Using Gradle Dynamic versions (i.e. a + dependency) is considered an antipattern (see the various warnings and notes on this page), specifically as it can lead to scenarios like this one and generally exposes users to less-reproducible builds. This is exactly what happened in this scenario, as builds started failing without any changes to user projects.

In 0.71 we cleaned up the new app template and removed all the + dependencies (see here) and we moved the template to use the React Native Gradle Plugin, which will allow us to prevent scenarios like this from happening in the future.

Sadly, users on older versions, say 0.66.0, were still using a + version. This caused their build to query all the repositories for the highest available versions of the React Native. While the node_modules/react-native/android folder contained a valid 0.66.0 version, Gradle honoured the + version and fetched version 0.71.0-rc0 from Maven Central as it's higher from the semantic versioning ordering.

The resolutionStrategy block in the fix is forcing the version of com.facebook.react:react-native to all the projects to the one provided by the version of React Native you're effectively using.

Who is affected?

All the React Native users on versions till 0.66.x are affected.

React Native users on versions from 0.67 till 0.70 could be affected, based on which third-party library they're using.

We verified that empty projects created on versions from 0.67 till 0.70 are not affected.

However, some of your dependencies might end up causing a wrong resolution of the React Native Android library, resulting in build failures. For instance, we verified that a project on React Native 0.68.4 works well with Reanimated 2.12.0 but fails with Reanimated 2.10.0.

We also worked with Expo to make sure that users on eas build received the aforementioned fix, so those users should not be affected.

Why React Native Android was published on Maven Central?

As mentioned, this was done as part of the implementation of the RFC #580.

The summary of that RFC is to allow us to overcome the limitation of NPM in terms of package size. Moving to Maven Central will allow us to reduce the build time for our users and distribute more granular artifacts which will end up benefitting the overall developer experience. We'll be able to share information on this in the near future.

In the initial Github Issue, several users suggest to remove the publishing from Maven Central or re-publish older artifacts to overcome the build failure without requesting a fix.

This is sadly not an option as:

  1. Maven Central is an immutable artifacts storage and doesn't allow deletion.
  2. The publishing on 0.71.0-rc0 was effectively correct. We believe this episode is essentially a "mis-configuration" in user projects, and we believe the better solution is to distribute this fix to our users.

How could this have been prevented

We were already aware of the risk of having Gradle dynamic dependencies, so since React Native 0.67 we introduced an exclude rule on the Maven Central dependency inside the default template (see here for more context):

        mavenCentral {
            content {
                excludeGroup("com.facebook.react")
            }
        }

React Native used to be published on Maven Central till version 0.20.1 (published in 2016). We had users in the past accidentally fetching older versions of React from Maven Central, causing their build to fail.

This exclude directive assured that you won't ever download React Native from Maven Central. However, third party libraries could declare repositories inside their repositories{} block which might not contain the exclude directive, resulting in potentially broken dependency resolution.

React Native version 0.71.0 will ship with an updated template that relies on React Native Gradle Plugin. This new integration will allow us to protect us against future distributed build failures like this one, by allowing to re-distribute updated build logic across the whole ecosystem if needed (this should protect us also against similar outages like the JCenter outage happened last year).


I'd like to thank everyone for your patience and understanding and I'd like to call out some members our our community, specifically @mikehardy, @Titozzz, @brentvatne, @inckie and all the other folks involved in the initial investigation and fix for this issue.

We'll follow up with more updates in the future if needed.

Nicola On behalf of the React team

cortinico avatar Nov 05 '22 03:11 cortinico

I can confirm the fix works just fine with 0.70.3

enahum avatar Nov 05 '22 08:11 enahum

My build issue started yesterday but the fix works for me

olafashade avatar Nov 05 '22 08:11 olafashade

Thank you @cortinico this fix works 👍🏻

darkhorse-coder avatar Nov 05 '22 09:11 darkhorse-coder

Thank you @cortinico, this fix works just fine with RN 0.63.2

ItsAmanOP avatar Nov 05 '22 10:11 ItsAmanOP

Thanks @cortinico everything is working fine. So once our projects updated to RN 0.71+ we must remove this workaround, right?

oleksandr-dziuban avatar Nov 05 '22 10:11 oleksandr-dziuban

fix works on Rn v.0.64.2

jouiniyassine49 avatar Nov 05 '22 11:11 jouiniyassine49

@JodiRaina that likely indicates your gradle plugin or gradle is too old to use this advice - it appears gradle 6.1 and older does not have the exclusiveContent / include filter in the preferred solution.

If you cannot upgrade gradle (and react-native...), you might try one of the fallback workarounds for old react-native using very old gradle plugin / gradle, specifically this one, which was the best-known solution if exclusiveContent is not available / until the exclusiveContent idea occurred

https://github.com/facebook/react-native/issues/35204#issuecomment-1304281740


@brentvatne @ Expo proposes this as a refinement to avoid the hard coded version, it is the same as the previous best-known solution but now with dynamic version powers, otherwise same idea - you put this in the allprojects area of your android/buld.gradle file

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())

allprojects {
    configurations.all {
        resolutionStrategy {
            // Remove this override in 0.66, as a proper fix is included in react-native itself.
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }

Note that the exclusiveContent idea is a cleaner solution, but of course only if your gradle supports it

mikehardy avatar Nov 05 '22 12:11 mikehardy

Thanks @cortinico. I can confirm this fix working fine with react native 0.68.2 & 0.70.1 .

devinkg avatar Nov 05 '22 14:11 devinkg

Thanks a lot @cortinico I am confirming about version 0.68.0

gagal18 avatar Nov 05 '22 14:11 gagal18

Hey everyone :wave: ! We know the fix works in almost all cases. We have one failure case where your gradle is 6.1 or lower, with a separate workaround as described above.

There is no need to report success here as it will just clutter up the thread and hide real problems, if any.

If you have a case that does not work, then it is worth commenting and pursuing.

Thanks!

mikehardy avatar Nov 05 '22 14:11 mikehardy

I searched for 10 Hours for this Fix - pls provide this more publicly! It perfect fixes hours of searching why i got this error

A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction 2 files found with path 'lib/armeabi-v7a/libfbjni.so' from inputs: - C:\Users\Louis.gradle\caches\transforms-3\9fe0af513f6b028d441d24b0da4a585e\transformed\jetified-react-native-0.71.0-rc.0-release\jni - C:\Users\Louis.gradle\caches\transforms-3\10cc45bff922d10dfa305b6219e85a22\transformed\jetified-fbjni-0.3.0\jni If you are using jniLibs and CMake IMPORTED targets, see

Libero793 avatar Nov 05 '22 15:11 Libero793

@Libero793 the issue is pinned in this repository (at the top of the issues list), has been tweeted by a few people and is searchable. Please publicize it any other way you can if you feel it is missing publicity @kaishuvam7 unfortunately, I think you may have some unrelated issue. Your stackoverflow does not in general meet stackoverflow guidelines: https://stackoverflow.com/help/how-to-ask / https://stackoverflow.com/help/minimal-reproducible-example so does not have the information required to help

mikehardy avatar Nov 05 '22 15:11 mikehardy

Not working for the react-native: 0.64.2

akhileshsinha avatar Nov 05 '22 22:11 akhileshsinha

I am having the same problem with this version 0.64.0. I tried to figure it out but still can not figure out

muhammadsarim555 avatar Nov 05 '22 23:11 muhammadsarim555

I am having the same problem with this version 0.64.0. I tried to figure it out but still can not figure out

try this bro : build.gradle

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

        mavenCentral {
            content {
                excludeGroup("com.facebook.react")
            }
        }        

    

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

then remove node modules, npm install, run gradlew clean in android directory, and run apps

a7chax avatar Nov 06 '22 02:11 a7chax

Hi, after applying the fix the build in eas works correctly, but when running the application in production in android it crashes at startup. Does it happen to anyone else? any solution?

Pakvothe avatar Nov 06 '22 03:11 Pakvothe

Hi, after applying the fix the build in eas works correctly, but when running the application in production in android it crashes at startup. Does it happen to anyone else? any solution?

+1.

in my case after digging around, it was looking for hermes.so file (which I don't use, disabled in the gradle file, and remove it after the build is done). And I still don't know how to fix it.

--------- beginning of crash
2022-11-06 11:39:26.214 8631-8696/*** E/AndroidRuntime: FATAL EXCEPTION: create_react_context
    Process: ***, PID: 8631
    java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
    	SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/***/lib-main flags = 1]
    	SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/~~-dS-qsYgLMRevGULTgeUdA==/***-ScQbcqeVLMVx2AtUh_jKrQ==/lib/x86 flags = 0]
    	SoSource 2: com.facebook.soloader.DirectorySoSource[root = /vendor/lib flags = 2]
    	SoSource 3: com.facebook.soloader.DirectorySoSource[root = /system/lib flags = 2]
    	Native lib dir: /data/app/~~-dS-qsYgLMRevGULTgeUdA==/***-ScQbcqeVLMVx2AtUh_jKrQ==/lib/x86
     result: 0
        at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:918)
        at com.facebook.soloader.SoLoader.loadLibraryBySoNameImpl(SoLoader.java:740)
        at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:654)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:634)
        at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:582)
        at com.facebook.hermes.reactexecutor.HermesExecutor.<clinit>(HermesExecutor.java:20)
        at com.facebook.hermes.reactexecutor.HermesExecutorFactory.create(HermesExecutorFactory.java:29)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:1054)
        at java.lang.Thread.run(Thread.java:923)

mardikarifqi avatar Nov 06 '22 05:11 mardikarifqi

Hi there, im still getting this error . Can anyone please help Task :react-native-blob-util:verifyReleaseResources FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':react-native-blob-util:verifyReleaseResources'.

A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade 1 exception was raised by workers: com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed /Users/brightsmac/.gradle/caches/transforms-2/files-2.1/62387f6979a345c65eb55946f8f1a3ff/core-1.7.0/res/values/values.xml:105:5-114:25: AAPT: error: resource android:attr/lStar not found.

This is my package.json

{

"version": "5.0.6", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint ." }, "dependencies": { "@react-native-community/async-storage": "^1.12.0", "@react-native-community/masked-view": "^0.1.10", "@react-native-community/netinfo": "^5.9.7", "@react-native-picker/picker": "^2.4.7", "@redux-devtools/extension": "^3.2.3", "moment": "^2.29.0", "native-base": "^2.13.14", "react": "16.13.1", "react-native": "0.63.3", "react-native-animatable": "^1.3.3", "react-native-blob-util": "^0.15.0", "react-native-device-info": "^8.7.1", "react-native-draggable": "^3.3.0", "react-native-element-dropdown": "^2.3.0", "react-native-elements": "^3.4.2", "react-native-fs": "^2.19.0", "react-native-gesture-handler": "^1.8.0", "react-native-image-picker": "^4.10.0", "react-native-in-app-review": "^3.3.3", "react-native-modalbox": "^2.0.2", "react-native-pdf": "^6.5.0", "react-native-progress": "^5.0.0", "react-native-render-html": "^4.2.4", "react-native-safe-area-context": "^3.1.8", "react-native-screens": "^2.11.0", "react-native-sqlite-storage": "^6.0.1", "react-native-vector-icons": "^9.2.0", "react-native-webview": "^11.23.1", "react-navigation": "^4.4.1", "react-navigation-stack": "^2.8.3", "react-redux": "^7.2.1", "redux": "^4.0.5" }, "devDependencies": { "@babel/core": "^7.11.6", "@babel/runtime": "^7.11.2", "@react-native-community/eslint-config": "^2.0.0", "babel-jest": "^26.3.0", "eslint": "^7.10.0", "jest": "^26.4.2", "metro-react-native-babel-preset": "^0.63.0", "react-test-renderer": "16.13.1" }, "jest": { "preset": "react-native" } }

godbright avatar Nov 06 '22 06:11 godbright

Hi, I'm using react-native 0.67.2 in which the fix is already there. However the error is caused by one of my dependencies "@react-native-async-storage/async-storage": "^1.16.1" saying something about Java heap space.

Here is my error log

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: /home/optimusprime/.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

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s

I checked the build.gradle file of that dependency, which uses RN 0.66.0-0 which causes the above-mentioned error Here is the build.gradle file of @react-native-async-storage/async-storage

import java.nio.file.Paths

def resolveModulePath(packageName) {
    def basePath = rootDir.toPath().normalize()

    // Node's module resolution algorithm searches up to the root directory,
    // after which the base path will be null
    while (basePath) {
        def candidatePath = Paths.get(basePath.toString(), 'node_modules', packageName)
        if (candidatePath.toFile().exists()) {
            return candidatePath.toString()
        }

        basePath = basePath.getParent()
    }

    return null
}

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

def getFlagOrDefault(flagName, defaultValue) {
    rootProject.hasProperty(flagName) ? rootProject.properties[flagName] == "true" : defaultValue
}

def getVersionOrDefault(String flagName, String defaultVersion) {
    rootProject.hasProperty(flagName) ? rootProject.properties[flagName] : defaultVersion
}

configurations {
    compileClasspath
}

buildscript {
    // kotlin version is dictated by rootProject extension or property in gradle.properties
    ext.asyncStorageKtVersion = rootProject.ext.has('kotlinVersion')
            ? rootProject.ext['kotlinVersion']
            : rootProject.hasProperty('AsyncStorage_kotlinVersion')
            ? rootProject.properties['AsyncStorage_kotlinVersion']
            : '1.6.10'

    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        if (project == rootProject) {
            classpath 'com.android.tools.build:gradle:4.2.2'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$asyncStorageKtVersion"
        }
    }
}

// AsyncStorage has default size of 6MB.
// This is a sane limit to protect the user from the app storing too much data in the database.
// This also protects the database from filling up the disk cache and becoming malformed.
// If you really need bigger size, please keep in mind the potential consequences.
long dbSizeInMB = 6L
def newDbSize = rootProject.properties['AsyncStorage_db_size_in_MB']
if (newDbSize != null && newDbSize.isLong()) {
    dbSizeInMB = newDbSize.toLong()
}

// Instead of reusing AsyncTask thread pool, AsyncStorage can use its own executor
def useDedicatedExecutor = getFlagOrDefault('AsyncStorage_dedicatedExecutor', false)

// Use next storage implementation
def useNextStorage = getFlagOrDefault("AsyncStorage_useNextStorage", false)

apply plugin: 'com.android.library'
if (useNextStorage) {
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-kapt'
    apply from: './testresults.gradle'
}

android {
    compileSdkVersion safeExtGet('compileSdkVersion', 31)
    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 21)
        targetSdkVersion safeExtGet('targetSdkVersion', 31)
        buildConfigField "Long", "AsyncStorage_db_size", "${dbSizeInMB}L"
        buildConfigField "boolean", "AsyncStorage_useDedicatedExecutor", "${useDedicatedExecutor}"
        buildConfigField "boolean", "AsyncStorage_useNextStorage", "${useNextStorage}"
    }
    lintOptions {
        abortOnError false
    }

    if (useNextStorage) {
        testOptions {
            unitTests {
                returnDefaultValues = true
                includeAndroidResources = true
            }
        }
    }
}

repositories {
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "${resolveModulePath("react-native")}/android"
    }
    google()
    mavenCentral()
}

dependencies {

    if (useNextStorage) {
        def room_version = getVersionOrDefault('AsyncStorage_next_roomVersion', '2.4.2')
        def coroutines_version = "1.6.0"
        def coroutinesTest_version = "1.6.0"
        // if we don't provide explicit dependency on reflection, kotlin plugin
        // would add one automatically, probably a version that is not compatible with
        // used kotlin
        def kotlinReflect_version = project.ext.asyncStorageKtVersion
        def junit_version = "4.13.2"
        def robolectric_version = "4.7.3"
        def truth_version = "1.1.3"
        def androidxtest_version = "1.4.0"
        def androidtest_junit_version = "1.1.3"

        implementation "androidx.room:room-runtime:$room_version"
        implementation "androidx.room:room-ktx:$room_version"
        implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinReflect_version"

        implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
        kapt "androidx.room:room-compiler:$room_version"

        testImplementation "junit:junit:$junit_version"
        testImplementation "androidx.test:runner:$androidxtest_version"
        testImplementation "androidx.test:rules:$androidxtest_version"
        testImplementation "androidx.test.ext:junit:$androidtest_junit_version"
        testImplementation "org.robolectric:robolectric:$robolectric_version"
        testImplementation "com.google.truth:truth:$truth_version"
        testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesTest_version"
    }

    //noinspection GradleDynamicVersion
    implementation 'com.facebook.react:react-native:+'  // From node_modules
}

Here is my android/build.gradle file

// 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"
    }
    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 {
        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' }
    }
}

Even though my top level build.gradle resolves RN locally, the dependencies are fetching from the maven.

ABIBV avatar Nov 06 '22 07:11 ABIBV

I added it to the top-level gradle file

`// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "28.0.3" compileSdkVersion = 28 minSdkVersion = 21 targetSdkVersion = 28 } repositories { google() jcenter() } dependencies { classpath("com.android.tools.build:gradle:3.6.4") classpath 'com.yanzhenjie.andserver:plugin:2.1.10' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }

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"
           }
       }
   }**
   
    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()
    mavenCentral()
    maven { url 'https://www.jitpack.io' }

   
}

} `

An error is as follows

`* What went wrong: A problem occurred evaluating root project 'xwPad'.

Could not find method exclusiveContent() for arguments [build_el079orh1l6qkb8jbdvy6yi4f$_run_closure1$_closure2$_closure3@201b8227] on repository container of type org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler.`

Does anyone know how to fix rn version 0.62

a554878526 avatar Nov 06 '22 09:11 a554878526

Couldn't run the project after 4th Nov. When I am trying to run the project every time build is failing with these message.

@error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring root project 'Peace Garden'.

Could not determine the dependencies of null. Could not resolve all task dependencies for configuration ':classpath'. > Could not resolve com.facebook.react:react-native:+. Required by: project : > No matching variant of com.facebook.react:react-native:0.71.0-rc.0 was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.3.3' but:

my app.gradle file

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

buildscript { ext { buildToolsVersion = "31.0.0" minSdkVersion = 21 compileSdkVersion = 31 targetSdkVersion = 31 kotlinVersion = "1.5.31"

    if (System.properties['os.arch'] == "aarch64") {
        // For M1 Users we need to use the NDK 24 which added support for aarch64
        ndkVersion = "24.0.8215888"
    } else {
        // Otherwise we default to the side-by-side NDK version from AGP.
        ndkVersion = "21.4.7075529"
    }
}
repositories {
    google()
    mavenCentral()
}
dependencies {
    classpath("com.android.tools.build:gradle:7.1.1")
    classpath("com.facebook.react:react-native-gradle-plugin")
    classpath("de.undercouch:gradle-download-task:5.0.1")
    classpath("com.facebook.react:react-native:+")
    classpath('com.google.gms:google-services:4.3.14')
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

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") } 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' } } }**

anyone facing the same ?

KhNishad avatar Nov 06 '22 09:11 KhNishad

exclusiveContent is not working, I'm using React-native version 0.66.3

ankitagnihotri avatar Nov 06 '22 09:11 ankitagnihotri

I used version 0.62.2 for the same problem. Does anyone know how to solve it

a554878526 avatar Nov 06 '22 09:11 a554878526

@ankitagnihotri
I used version 0.62.2 for the same problem. Does anyone know how to solve it

a554878526 avatar Nov 06 '22 09:11 a554878526

@cortinico I don't know whether to thank you for this fix, or to curse that you guys have cost me half of my weekend!

I'll go with a thank you instead :) but please, if you could be a bit more careful with things like this, and perhaps have test app builds with lower androidSDK versions to catch these before they get published that would be awesome.

jzaynal avatar Nov 06 '22 09:11 jzaynal

For old react-native versions on gradle 6.1 and below you need a different workaround:

@yuvital-render please take a look at https://github.com/facebook/react-native/issues/35210#issuecomment-1304536693

phuongwd avatar Nov 06 '22 10:11 phuongwd

@cortinico I am still getting an issue after I added the code block you instructed with, I followed the upgrade from 0.70.3 to 0.71.0rc

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

image

AdhamMahmoud98 avatar Nov 06 '22 12:11 AdhamMahmoud98

I've fixed it! Sharing the steps:

CleanShot 2022-11-06 at 14 23 12@2x

CleanShot 2022-11-06 at 14 23 32@2x

CleanShot 2022-11-06 at 14 23 43@2x

CleanShot 2022-11-06 at 14 23 58@2x

Hope it helps someone 🙏

yuvital-render avatar Nov 06 '22 12:11 yuvital-render

Hi, after applying the fix the build in eas works correctly, but when running the application in production in android it crashes at startup. Does it happen to anyone else? any solution?

+1.

in my case after digging around, it was looking for hermes.so file (which I don't use, disabled in the gradle file, and remove it after the build is done). And I still don't know how to fix it.

--------- beginning of crash
2022-11-06 11:39:26.214 8631-8696/*** E/AndroidRuntime: FATAL EXCEPTION: create_react_context
    Process: ***, PID: 8631
    java.lang.UnsatisfiedLinkError: **couldn't find DSO to load: libhermes.so**

We had the exact same problem. Forced us to move to hermes, as all the known approaches to resolve the above error didn't work.

nklomp avatar Nov 06 '22 13:11 nklomp

Do not post "me too" comments

This issue affects nearly everyone and github issues do not handle enormous numbers of comments well.

If you post metoo comments (or even "thank you"s) you are actively making it harder on your fellow developers to fix their builds by making it harder for them to find the relevant information.

If it works for you please share the solution with developers you know or retweet https://twitter.com/reactnative/status/1589296764678705155 - that will have a positive impact for other developers

It appears there may be a problem related to people not using hermes, though this has not been confirmed.

It is still our understanding that if applied correctly, we have these choices for a fix:

1- for the actual 0.71.0-rc.0 version you do not need a workaround 2- for "current" (react-native 0.64+ or 0.65, using gradle 6.2 or higher as determined in your gradle wrapper) - adding the exclusive repository definition described all the way at the top in the main description above works 3- for "old" (react-native 0.63 or lower, using gradle 6.1 or lower) - pinning the version via this workaround works https://github.com/facebook/react-native/issues/35210#issuecomment-1304536693

mikehardy avatar Nov 06 '22 15:11 mikehardy