I tried to build APK for Android after upgrading my project from 0.61.5 to 062, however the build universal APK crashed.
I then tried to built the APK on a fresh React Native 0.62 project and similar thing happens.
I tried the APK on several emulators. On emulators with x86 CPU it crashed but on x86_64 the APK can run without problem.
I don't know if it is a bug in React Native or I somehow messed up my environments. I would appricate any help, thank you!
yarn run v1.22.4
$ D:\Codes\tryUniversalAPK\node_modules\.bin\react-native info
info Fetching system and libraries information...
System:
OS: Windows 10 10.0.18363
CPU: (12) x64 AMD Ryzen 5 2600 Six-Core Processor
Memory: 19.23 GB / 31.95 GB
Binaries:
Node: 13.11.0 - C:\Users\Indra\AppData\Local\Temp\yarn--1585793456760-0.2610294802603219\node.CMD
Yarn: 1.22.4 - C:\Users\Indra\AppData\Local\Temp\yarn--1585793456760-0.2610294802603219\yarn.CMD
npm: 6.13.7 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Version 3.6.0.0 AI-192.7142.36.36.6308749
Languages:
Python: 2.7.17 - C:\Python27\python.EXE
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.0 => 0.62.0
npmGlobalPackages:
*react-native*: Not Found
Done in 1.32s.
### 1 Initiate New Project
npx react-native init tryUniversalAPKcd tryUniversalAPKadb logcat *:S ReactNative:V ReactNativeJS:VtryUniversalAPK directoryyarn android --variant=releaseadb logcat running, it shows these errors
--------- beginning of main
--------- beginning of system
04-02 08:32:42.891 8782 8782 D ReactNative: ReactInstanceManager.ctor()
04-02 08:32:42.939 8782 8782 D ReactNative: ReactInstanceManager.createReactContextInBackground()
04-02 08:32:42.939 8782 8782 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
04-02 08:32:42.939 8782 8782 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundFromBundleLoader()
04-02 08:32:42.939 8782 8782 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
04-02 08:32:42.939 8782 8782 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
--------- beginning of crash
04-02 08:34:32.749 9021 9021 D ReactNative: ReactInstanceManager.ctor()
04-02 08:34:32.764 9021 9021 D ReactNative: ReactInstanceManager.createReactContextInBackground()
04-02 08:34:32.765 9021 9021 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundInner()
04-02 08:34:32.765 9021 9021 D ReactNative: ReactInstanceManager.recreateReactContextInBackgroundFromBundleLoader()
04-02 08:34:32.765 9021 9021 D ReactNative: ReactInstanceManager.recreateReactContextInBackground()
04-02 08:34:32.765 9021 9021 D ReactNative: ReactInstanceManager.runCreateReactContextOnNewThread()
tryUniversalAPK/android/app/build.gradle
def enableSeparateBuildPerCPUArchitecture = false
def enableSeparateBuildPerCPUArchitecture = true
universalApk false
universalApk true
cd tryUniversalAPK/android./gradlew cleancd ..yarn android --variant=releaseapp-x86-release.apk
> Task :app:installRelease
08:58:13 V/ddms: execute: running am get-config
08:58:13 V/ddms: execute 'am get-config' on 'emulator-5554' : EOF hit. Read: -1
08:58:13 V/ddms: execute: returning
Installing APK 'app-x86-release.apk' on 'Pixel_3_API_28(AVD) - 9' for app:release
08:58:13 D/app-x86-release.apk: Uploading app-x86-release.apk onto device 'emulator-5554'
08:58:13 D/Device: Uploading file onto device 'emulator-5554'
08:58:13 D/ddms: Reading file permision of D:\Codes\tryUniversalAPK\android\app\build\outputs\apk\release\app-x86-release.apk as: rwx------
08:58:13 V/ddms: execute: running pm install -r -t "/data/local/tmp/app-x86-release.apk"
08:58:14 V/ddms: execute 'pm install -r -t "/data/local/tmp/app-x86-release.apk"' on 'emulator-5554' : EOF hit. Read: -1
08:58:14 V/ddms: execute: returning
08:58:14 V/ddms: execute: running rm "/data/local/tmp/app-x86-release.apk"
08:58:14 V/ddms: execute 'rm "/data/local/tmp/app-x86-release.apk"' on 'emulator-5554' : EOF hit. Read: -1
08:58:14 V/ddms: execute: returning
Installed on 1 device.
tryUniversalAPK\android\app\build\outputs\apk\release foldertryUniversalAPK app in the android emulatorapp-universal-release.apk to the emulatortryUniversalAPK app (this is the app-universal-release.apk) in the emulatorapp-x86-release.apk to the emulatorThe universl APK able to run without crash

2020-04-02 09:52:53.796 4952-4952/? E/SoLoader: couldn't find DSO to load: libc++_shared.so caused by: dlopen failed: "/data/data/com.tryuniversalapk/lib-main/libc++_shared.so" has unexpected e_machine: 40 (EM_ARM)
2020-04-02 09:52:53.797 4952-4952/? E/SoLoader: couldn't find DSO to load: libfb.so caused by: APK was built for a different platform
2020-04-02 09:52:53.799 4952-4952/? E/SoLoader: couldn't find DSO to load: libjscexecutor.so caused by: couldn't find DSO to load: libfb.so caused by: APK was built for a different platform
2020-04-02 09:52:53.831 4952-4967/? E/SoLoader: couldn't find DSO to load: libhermes.so
--------- beginning of crash
2020-04-02 09:52:53.834 4952-4967/? E/AndroidRuntime: FATAL EXCEPTION: create_react_context
Process: com.tryuniversalapk, PID: 4952
java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so
at com.facebook.soloader.SoLoader.doLoadLibraryBySoName(SoLoader.java:789)
at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:639)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:577)
at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:525)
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:997)
at java.lang.Thread.run(Thread.java:764)
tryUniversalAPK/android/app/build.gradle fileOnly two lines were changed def enableSeparateBuildPerCPUArchitecture = true and universalApk true
apply plugin: "com.android.application"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation. If none specified and
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
* // default. Can be overridden with ENTRY_FILE environment variable.
* entryFile: "index.android.js",
*
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
* bundleCommand: "ram-bundle",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
enableHermes: false, // clean and rebuild if changing
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = true
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore.
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.tryuniversalapk"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk true // 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'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
packagingOptions {
pickFirst "lib/armeabi-v7a/libc++_shared.so"
pickFirst "lib/arm64-v8a/libc++_shared.so"
pickFirst "lib/x86/libc++_shared.so"
pickFirst "lib/x86_64/libc++_shared.so"
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
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
}
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
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'
}
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
}
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
This needs attention!
We can't switch to 62.x in production if it happens on user devices. Basically anyone upgrading is affected by this.
@indralukmana do you have any updates? I'm stucking with this exact error 鈽癸笍
same issue in [email protected]
hi @dzuncoi ,
Unfortunately no. I didn't find a solution specifically for the issue. However, my team work around the issue by changing our way of releasing android app.
From .apk we switch to .aab (Android App Bundle) as explained in https://reactnative.dev/docs/signed-apk-android. We are releasing apps in Play Store and utilising the release channels for testing there.
However, as far as I know we can only use .aab in Play Store. I tried to install .aab app in emulator but cannot figured out how to do it. My team was also trying the Firebase Crashlytics, but currently the Firebase Crashlytics only support .apk so we cannot really use them because the universal .apk doesn't work on some cases.
I think you can try to target specific CPU architecture by enabling enableSeparateBuildPerCPUArchitecture flag. And strategize how to test the APK by specific devices. Then release them in markets that support device targetting.
@indralukmana
The best way now is to forget 0.62.2 version. Instead, just use 0.61.5 - a stable version and still good to release an app.
And with 0.61.5, don't generate multiple apk sometimes it will cause error for special CPU. Set all those flag to false.
If u want to test the release apk, let's use the react command, it will burn your .aab file to a single apk then install (you know already).
If u want to submit to store, let's use app.aab file. Google will handle it with your upload keystore and generate the best suit for each device and it will work well, we shouldn't upload multiple apk to store file as before!
If u upgraded the project from 0.61.5 to 0.62.2 already, now you need to reverse it by creating a new project with command:
npx react-native init The_Same_Name_With_Your_Project --version 0.61.5
Then copy all source code and assets, config... to the new project then enjoy!
(Note that you must create a new project with specific version by that way, if you only change the version in package.json file, and update it won't work)
Once facebook fix those issues or release a newer version, we will update, but not now!
Hope this will help you
Thank you @q-bird for pointing me here.
We are experiencing the same issue.
As far as I understood the issue comes from the soloader. See: https://github.com/facebook/SoLoader/issues/55
I guess we will stay on React Native 0.61.5 then for now.
Good news is I just checked the 0.63.0-rc.1 and the issue seems to have gone in that version 馃帀
I haven't checked all the differences yet, though.
As it seems the issue is solved with version 0.8.2 of the soloader, which also is used in the 0.63.0-rc.1.
I found this comment helping me fixing the issue for our app: https://github.com/facebook/react-native/issues/25923#issuecomment-594047945
@okwast
Thank you for your info
Hope they will launch the official version soon!
add this code to your android/app/proguard-rules.pro
-keep class com.facebook.jni.** { *; }
add this code to your android/app/proguard-rules.pro
-keep class com.facebook.jni.** { *; }
Thank you, I just had some time to try it.
I don't think this solve the issue. I did not activate proguard so the the setting did not applied.
Alternatively, I also tried to activate proguard with the setting but the app still crash when I do yarn andoid --variant=release. So the issue still persist.
I found a solution from here https://github.com/facebook/react-native/issues/25923#issuecomment-594047945
I added this piece of code in android/app/build.gradle and the app can run with yarn android --variant=release and not crashing.
configurations.all {
resolutionStrategy {
force "com.facebook.soloader:soloader:0.8.2"
}
}
I found a solution from here #25923 (comment)
I added this piece of code in
android/app/build.gradleand the app can run withyarn android --variant=releaseand not crashing.configurations.all { resolutionStrategy { force "com.facebook.soloader:soloader:0.8.2" } }
@indralukmana I did try your suggestion but it's is not working yet =/
Ubuntu - [email protected]
run app with enableProguardInReleaseBuilds = false. App work fine
But
enableHermes: true
and
enableProguardInReleaseBuilds = true
I try to enable enableProguardInReleaseBuilds and got a issue.
added
configurations.all {
resolutionStrategy {
force "com.facebook.soloader:soloader:0.8.2"
}
}
to app/build.gradle
app still crash on android. Here is logcat:
--------- beginning of crash
2020-06-16 18:41:41.063 31481-31547/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
Process: com.app.stg, PID: 31481
com.facebook.react.common.d: TypeError: Cannot read property 'match' of undefined, js engine: hermes, stack:
anonymous@1:631356
v@1:62747
d@1:62440
o@1:62068
anonymous@1:630081
v@1:62747
d@1:62440
o@1:62068
anonymous@1:624214
v@1:62747
d@1:62440
o@1:62068
anonymous@1:588435
v@1:62747
d@1:62440
o@1:62068
anonymous@1:569279
v@1:62747
d@1:62440
o@1:62068
anonymous@1:69167
v@1:62747
d@1:62397
o@1:62068
global@1:61800
at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(Unknown Source:134)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(Unknown Source:149)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:21)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(Unknown Source:0)
at android.os.Looper.loop(Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37)
at java.lang.Thread.run(Thread.java:764)
@indralukmana Sir, Same issue(As you described above) happening to me. React-Native 0.63.0
I found a solution from here #25923 (comment)
I added this piece of code in
android/app/build.gradleand the app can run withyarn android --variant=releaseand not crashing.configurations.all { resolutionStrategy { force "com.facebook.soloader:soloader:0.8.2" } }
It's not working as well here. React-Native 0.62.2
I found a solution from here #25923 (comment)
I added this piece of code inandroid/app/build.gradleand the app can run withyarn android --variant=releaseand not crashing.configurations.all { resolutionStrategy { force "com.facebook.soloader:soloader:0.8.2" } }It's not working as well here. React-Native 0.62.2
Finally, I tried this answer and it works now https://github.com/facebook/SoLoader/issues/55#issuecomment-653890808
@pxmage thank you! It works!! :)
Most helpful comment
I found a solution from here https://github.com/facebook/react-native/issues/25923#issuecomment-594047945
I added this piece of code in
android/app/build.gradleand the app can run withyarn android --variant=releaseand not crashing.