react-native: React Native 0.62 Universal APK crashed on x86 CPU Android
Description
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!
React Native version:
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.
Steps To Reproduce
1 Initiate New Project
- Open terminal
npx react-native init tryUniversalAPK
cd tryUniversalAPK
2 Create an x86 CPU/ABI based emulator
- Open Android Virtual Device Manager
- Create virtual device with x86 CPU
- Launch the emulator
3 Build (crashed) and Native android log
- Open new terminal
adb logcat *:S ReactNative:V ReactNativeJS:V
- Open the terminal with
tryUniversalAPK
directory - run
yarn android --variant=release
- The app will crash
- Open the terminal with
adb 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()
4 Modify gradle to build APK on separate build per CPU architecture
- Open
tryUniversalAPK/android/app/build.gradle
- change
intodef enableSeparateBuildPerCPUArchitecture = false
def enableSeparateBuildPerCPUArchitecture = true
- change
intouniversalApk false
universalApk true
5 Rebuild
cd tryUniversalAPK/android
- run
./gradlew clean
cd ..
- run
yarn android --variant=release
- The app able to run without crash
- I noticed these in the terminal. The APK installed seems to be the
app-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.
6 Testing the built APKs
- Navigate to
tryUniversalAPK\android\app\build\outputs\apk\release
folder - There are five different APKs
- I uninstalled the
tryUniversalAPK
app in the android emulator - I drag and drop the
app-universal-release.apk
to the emulator - The app crashed
- Uninstalled the
tryUniversalAPK
app (this is theapp-universal-release.apk
) in the emulator - I drag and drop the
app-x86-release.apk
to the emulator - The app can run
Expected Results
The universl APK able to run without crash
ZIP file containing the built APKs
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 10
- Comments: 20
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 withyarn android --variant=release
and not crashing.tryUniversalAPK/android/app/build.gradle
fileOnly two lines were changed
def enableSeparateBuildPerCPUArchitecture = true
anduniversalApk true
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
Might be related with:
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.
Additional Info from Android Studio Logcat
Finally, I tried this answer and it works now https://github.com/facebook/SoLoader/issues/55#issuecomment-653890808
same issue in
react-native@0.62.2