I have a React Native app, and it's built into Android app well with the help of android gradle plugin(AGP) version 3.5.2., react native version 0.61.5.
I faced a quite bizzar issue when upgrade AGP to 4.1.2: I can build both debug and release versions of application, debug version work well without any complaints but when I start release version I've got a crash with such kind of error
E/AndroidRuntime: FATAL EXCEPTION: create_react_context
Process: com.app.qa, PID: 21103
java.lang.RuntimeException: Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:227)
at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:28)
at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:261)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1175)
at com.facebook.react.ReactInstanceManager.access$1000(ReactInstanceManager.java:125)
at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:951)
at java.lang.Thread.run(Thread.java:923)
So, with AGP 3.5.2 it's Ok, with AGP 4.1.2 I have some troubles with release bundle package.
Could it be fixed with the newest version of AGP or should I downgrade AGP? What changes should I make into build.gradle to fix it?
I found that issue at React Native issue dashboard https://github.com/facebook/react-native/issues/30761
So, I should downgrade AGP version to 4.0.1 (checked, it works) or use 4.1.2 with small changes for react.gradle script
// mergeResources task runs before the bundle file is copied to the intermediate asset directory from Android plugin 4.1+.
// This ensures to copy the bundle file before mergeResources task starts
def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")
mergeResourcesTask.dependsOn(currentAssetsCopyTask)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With