5

I'm new on react, and i tried to run my app but i got this following error

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.bits.bee.bwc, PID: 12601
    java.lang.AssertionError: APK bundle must contain the expected embedded asset asset_c2f3d742a18a28238b7cd34a5d4b7316.png
        at expo.modules.updates.loader.EmbeddedLoader.copyAllAssets(EmbeddedLoader.java:174)
        at expo.modules.updates.loader.EmbeddedLoader.processManifest(EmbeddedLoader.java:137)
        at expo.modules.updates.loader.EmbeddedLoader.loadEmbeddedUpdate(EmbeddedLoader.java:57)
        at expo.modules.updates.UpdatesController.start(UpdatesController.java:286)
        at expo.modules.updates.UpdatesController.initialize(UpdatesController.java:96)
        at com.bits.bee.bwc.MainApplication.onCreate(MainApplication.java:98)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4552)
        at android.app.ActivityThread.access$1500(ActivityThread.java:147)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5255)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)

Can someone explain to me how it's work because i looked it up in my asset folder there's nothing named like that. And how do i fix this? Thanks

Hanif Nr
  • 432
  • 1
  • 5
  • 15
  • When you look at your `android/app/src/main/assets/app.manifest` file, is that asset from the exception message the first one in the `bundledAssets` array? In my case it is. – Andru Jul 20 '20 at 22:57

1 Answers1

0

Info

This exception only happened to me when running a debug build with react-native run-android and the exception did not appear when running a release build with react-native run-android --variant=release.

Solution

Check whether you have the following line in MainApplication.java and if it's there then remove that line:

import com.facebook.react.BuildConfig;

Explanation

The line import com.facebook.react.BuildConfig; causes UpdatesController.initialize(this); to be called in Debug mode which shouldn't happen.

More detail:

When you look at your Stacktrace you posted the line

at com.bits.bee.bwc.MainApplication.onCreate(MainApplication.java:98)

points to UpdatesController.initialize(this);. Including the line above and below that's how it looks like:

if (!BuildConfig.DEBUG) {
  UpdatesController.initialize(this);
}

This BuildConfig here points to the BuildConfig class of your package (com.bits.bee.bwc in your case) which is created during the build. If you import com.facebook.react.BuildConfig it will point to another BuildConfig class which does not contain the correct DEBUG value you want.

Since BuildConfig.DEBUG will then be undefined or false, UpdatesController.initialize(this); is called although it shouldn't during a debug build. Hence, because assets will be not embedded for debug builds, the copyAllAssets function which is eventually called will not find any assets and we get the above error.


Some Context of why I ended up importing com.facebook.react.BuildConfig;

I was facing the issue of java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so in my release build and followed the advice to add that line as stated here https://stackoverflow.com/questions/57036317/react-native-java-lang-unsatisfiedlinkerror-couldnt-find-dso-to-load-libherm/63048532#answer-62119615. It didn't make a change for the release build and I forgot about it. Only later when I attempted to make a debug build I got this error.. took me quite a while to realize that this added line is the cause of the issue!

What I learned from debugging this issue:

  1. Don't just add things because you think it won't hurt. If it doesn't fulfill a certain purpose or has no effect, remove the change immediately. It can otherwise cause strange side effects later.
  2. If you have build issues with Android, debug with Android Studio instead of Flipper. Flipper doesn't display you the entire Stacktrace and in Android Studio you can easily browse through all the Java files which eventually helped me to understand this Exception.
Andru
  • 5,954
  • 3
  • 39
  • 56