skip to Main Content

I’m getting this error:

   > Failed to transform react-native-0.71.0-rc.0-release.aar (com.facebook.react:react-native:0.71.0-rc.0) to match attributes {artifactType=android-art-profile, com.android.build.api.attributes.BuildTypeAttr=release, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Could not find react-native-0.71.0-rc.0-release.aar (com.facebook.react:react-native:0.71.0-rc.0).
        Searched in the following locations:
            https://jcenter.bintray.com/com/facebook/react/react-native/0.71.0-rc.0/react-native-0.71.0-rc.0-release.aar

when I’m trying to create a bundle on Android by hitting:
"ENV=production ./envscript.sh && ENVFILE=.env.production && cd android && npx react-native run-android –mode=ProductionRelease && ./gradlew bundleRelease"

at some point when I was trying to upgrade react-native or trying to add apply plugin: "com.facebook.react" to build.gralde I got errors saying:
... Could not find Hermes.so
or SoLoader: couldn't find DSO to load ...
of Plugin with id 'com.facebook.react' not found

envscript.sh is only specifying the google-services file location

I also tried hitting the bundleRelease command at the stage it was working on my branches a while ago and it did not work!

  • upgrading react-native to v0.72.0 but it does not fix the error either…
  • all the stuff suggested here

Here is what react-native info gives me:

System:
    OS: macOS 13.4
    CPU: (8) arm64 Apple M1 Pro
    Memory: 1.61 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.2.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 9.6.6 - /usr/local/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.12.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
    Android SDK:
      API Levels: 28, 29, 30, 31, 32, 33
      Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 33.0.0, 34.0.0
      System Images: android-28 | Google APIs ARM 64 v8a, android-28 | Google ARM64-V8a Play ARM 64 v8a, android-29 | Google APIs ARM 64 v8a, android-29 | Google Play ARM 64 v8a, android-30 | Google APIs ARM 64 v8a, android-31 | Google Play ARM 64 v8a, android-32 | Google APIs ARM 64 v8a, android-33 | Google Play ARM 64 v8a
      Android NDK: 22.1.7171670
  IDEs:
    Android Studio: 2020.3 AI-203.7717.56.2031.7935034
    Xcode: 14.3.1/14E300c - /usr/bin/xcodebuild
  Languages:
    Java: 17.0.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.6 => 0.71.6 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Here is the android/build.gradle:

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

buildscript {
    ext {
        minSdkVersion = 23
        compileSdkVersion = 33
        targetSdkVersion = 31
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:7.0.4')
        classpath 'com.google.gms:google-services:4.3.10'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:1.3.0"
    }
}

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' }
    }
}

android/app/build.gradle:

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'

project.ext.envConfigFiles = [
   productiondebug: ".env.production",
   productionrelease: ".env.production",
   developmentrelease: ".env.development",
   developmentdebug: ".env.development",
   stagingrelease: ".env.staging",
   stagingdebug: ".env.staging"
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

import com.android.build.OutputFile
import groovy.json.JsonSlurper

project.ext.react = [
    enableHermes: false,  // clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = true
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);

def getPackageJsonObjectFromNpm() {
    def inputFile = new File("$rootDir/../package.json")
    def packageJson = new JsonSlurper().parseText(inputFile.text)

    return packageJson
}

def getVersionCodeFromNpm() {
    return getPackageJsonObjectFromNpm()["Android"]["versionCode"]
}

def getVersionNameFromNpm() {
    return getPackageJsonObjectFromNpm()["Android"]["versionName"]
}

def getPassword(String currentUser, String keyChain) {
   def stdout = new ByteArrayOutputStream()
   def stderr = new ByteArrayOutputStream()
   exec {
       commandLine 'security', '-q', 'find-generic-password', '-a', currentUser, '-s', keyChain, '-w'
       standardOutput = stdout
       errorOutput = stderr
       ignoreExitValue true
   }
      stdout.toString().trim()
}

def pass = getPassword("PASSWORD","android_keystore_PASSWORD")

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        multiDexEnabled true
        versionCode getVersionCodeFromNpm()
        versionName getVersionNameFromNpm()
        manifestPlaceholders = [ANDROID_GEO_API_KEY: "$System.env.ANDROID_GEO_API_KEY"]
        applicationId "com.example.equitazone"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
            matchingFallbacks = ['debug', 'release']
        }
        release {
            signingConfig signingConfigs.release

            debuggable false
            minifyEnabled true
            shrinkResources true
            zipAlignEnabled true
            setProguardFiles([getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'])

            ndk {
                debugSymbolLevel = 'FULL'
            }
        }
    }
    flavorDimensions "default"
    productFlavors {
        production {

        }
        staging {

        }
        development {

        }
    }

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }

        }
    }

    packagingOptions {
        pickFirst '**/libjsc.so'
        pickFirst '**/libc++_shared.so'
        pickFirst '**/libfbjni.so'
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:0.63.4"

    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }

    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }

    implementation platform('com.google.firebase:firebase-bom:31.2.1')

    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-analytics:17.3.0'

    implementation 'androidx.multidex:multidex:2.0.1'

    implementation 'com.google.android.gms:play-services-location:18.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'

    implementation project(':react-native-vector-icons')
    implementation project(':react-native-push-notification')
}

task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.implementation
    into 'libs'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

My MainApplication.java:

package com.mariongourlaouen.equitazone;

import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import androidx.multidex.MultiDexApplication;
import java.util.List;
// import androidx.appcompat.app.AppCompatActivity;

public class MainApplication extends MultiDexApplication implements ReactApplication {

  private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
          return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
          @SuppressWarnings("UnnecessaryLocalVariable")
          List<ReactPackage> packages = new PackageList(this).getPackages();
          // Packages that cannot be autolinked yet can be added manually here, for example:
          // packages.add(new MyReactNativePackage());
          return packages;
        }

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }
      };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
    // AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
  }

  /**
   * Loads Flipper in React Native templates. Call this in the onCreate method with something like
   * initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
   *
   * @param context
   * @param reactInstanceManager
   */
  private static void initializeFlipper(
      Context context, ReactInstanceManager reactInstanceManager) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
        Class<?> aClass = Class.forName("com.mariongourlaouen.equitazone.ReactNativeFlipper");
        aClass
            .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
            .invoke(null, context, reactInstanceManager);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
}

Any idea of what I can do to finally create my bundle? Help me please 🙏🏻

2

Answers


  1. Chosen as BEST ANSWER

    Here are the updated files: android/app/build.gradle:

    apply plugin: "com.android.application"
    apply plugin: "com.facebook.react"
    apply plugin: 'com.google.gms.google-services'
    
    project.ext.envConfigFiles = [
       productiondebug: ".env.production",
       productionrelease: ".env.production",
       developmentrelease: ".env.development",
       developmentdebug: ".env.development",
       stagingrelease: ".env.staging",
       stagingdebug: ".env.staging"
    ]
    apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
    
    import com.android.build.OutputFile
    import groovy.json.JsonSlurper
    
    project.ext.react = [
        enableHermes: false,  // clean and rebuild if changing
    ]
    
    // apply from: "../../node_modules/react-native/react.gradle"
    
    def enableSeparateBuildPerCPUArchitecture = false
    
    def enableProguardInReleaseBuilds = true
    
    def jscFlavor = 'org.webkit:android-jsc:+'
    
    
    def enableHermes = project.ext.react.get("enableHermes", false);
    
    def getPackageJsonObjectFromNpm() {
        def inputFile = new File("$rootDir/../package.json")
        def packageJson = new JsonSlurper().parseText(inputFile.text)
    
        return packageJson
    }
    
    def getVersionCodeFromNpm() {
        return getPackageJsonObjectFromNpm()["Android"]["versionCode"]
    }
    
    def getVersionNameFromNpm() {
        return getPackageJsonObjectFromNpm()["Android"]["versionName"]
    }
    
    def getPassword(String currentUser, String keyChain) {
       def stdout = new ByteArrayOutputStream()
       def stderr = new ByteArrayOutputStream()
       exec {
           commandLine 'security', '-q', 'find-generic-password', '-a', currentUser, '-s', keyChain, '-w'
           standardOutput = stdout
           errorOutput = stderr
           ignoreExitValue true
       }
       //noinspection GroovyAssignabilityCheck
          stdout.toString().trim()
    }
    
    def pass = getPassword("marion","android_keystore_PASSWORD")
    
    android {
        ndkVersion rootProject.ext.ndkVersion
    
        compileSdkVersion rootProject.ext.compileSdkVersion
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    
        defaultConfig {
            minSdkVersion rootProject.ext.minSdkVersion
            targetSdkVersion rootProject.ext.targetSdkVersion
            multiDexEnabled true
            versionCode getVersionCodeFromNpm()
            versionName getVersionNameFromNpm()
            manifestPlaceholders = [ANDROID_GEO_API_KEY: "$System.env.ANDROID_GEO_API_KEY"]
            applicationId "com.example.equitazone"
        }
        splits {
            abi {
                reset()
                enable enableSeparateBuildPerCPUArchitecture
                universalApk false  // If true, also generate a universal APK
                include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
            }
        }
        signingConfigs {
            debug {
                storeFile file('debug.keystore')
                storePassword 'android'
                keyAlias 'androiddebugkey'
                keyPassword 'android'
            }
            release {
                if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                    storeFile file(MYAPP_UPLOAD_STORE_FILE)
                    storePassword MYAPP_UPLOAD_STORE_PASSWORD
                    keyAlias MYAPP_UPLOAD_KEY_ALIAS
                    keyPassword MYAPP_UPLOAD_KEY_PASSWORD
                }
            }
        }
        buildTypes {
            debug {
                signingConfig signingConfigs.debug
                matchingFallbacks = ['debug', 'release']
            }
            release {
                signingConfig signingConfigs.release
    
                debuggable false
                minifyEnabled true
                shrinkResources true
                zipAlignEnabled true
                setProguardFiles([getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'])
    
                ndk {
                    debugSymbolLevel = 'FULL'
                }
            }
        }
        flavorDimensions "default"
        productFlavors {
            production {
            }
            staging {
            }
            development {
            }
        }
    
        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
                def abi = output.getFilter(OutputFile.ABI)
                if (abi != null) {  // null for the universal-debug, universal-release variants
                    output.versionCodeOverride =
                            versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
                }
    
            }
        }
    
        packagingOptions {
            pickFirst '**/libjsc.so'
            pickFirst '**/libc++_shared.so'
            pickFirst '**/libfbjni.so'
        }
    }
    
    dependencies {
        implementation("com.facebook.react:react-android")
    
        implementation fileTree(dir: "libs", include: ["*.jar"])
    
        implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    
        debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
          exclude group:'com.facebook.fbjni'
        }
    
        debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
            exclude group:'com.facebook.flipper'
            exclude group:'com.squareup.okhttp3', module:'okhttp'
        }
    
        debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
            exclude group:'com.facebook.flipper'
        }
    
        if (enableHermes) {
            def hermesPath = "../../node_modules/hermes-engine/android/";
            debugImplementation files(hermesPath + "hermes-debug.aar")
            releaseImplementation files(hermesPath + "hermes-release.aar")
        } else {
            implementation jscFlavor
        }
    
        implementation platform('com.google.firebase:firebase-bom:31.2.1')
    
        implementation 'com.google.firebase:firebase-analytics-ktx'
        implementation 'com.google.firebase:firebase-analytics:17.3.0'
        // implementation 'com.google.firebase:firebase-messaging:20.1.5'
    
        implementation 'androidx.multidex:multidex:2.0.1'
    
        implementation 'com.google.android.gms:play-services-location:18.0.0'
        implementation 'com.google.android.gms:play-services-maps:17.0.0'
    
        implementation project(':react-native-vector-icons')
        implementation project(':react-native-push-notification')
    }
    task copyDownloadableDepsToLibs(type: Copy) {
        from configurations.implementation
        into 'libs'
    }
    
    apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
    apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
    

    android/build.gradle:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        ext {
            buildToolsVersion = "33.0.0"
            minSdkVersion = 21
            compileSdkVersion = 33
            targetSdkVersion = 33
            // supportLibVersion = "28.0.0"
            ndkVersion = "23.1.7779620"
        }
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath("com.android.tools.build:gradle")
            classpath("com.facebook.react:react-native-gradle-plugin")
            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
            classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:1.3.0"
        }
    }
    
    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' }
        }
    }
    

    and I've added this includeBuild('../node_modules/@react-native/gradle-plugin') to the android/settings.gradle file

    Hope this will help someone else... and that we won't have this issue again 😬


  2. react-native-0.71.0-rc available on Jcenter,
    but today (23-june-2023) Jcenter stop there services,

    February 3, 2021 jFrog announced that they will be shutting down Jcenter

    so just upgrade you react-native version and check with stable version of React-native and also try to remove Jcenter() from build.gradle file in Android folder

    also you can check this link
    https://github.com/facebook/react-native/releases/tag/v0.71.0-rc.0
    https://developer.android.com/build/jcenter-migration

    jcneter status: https://status.gradle.com/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search