oppia-android icon indicating copy to clipboard operation
oppia-android copied to clipboard

Bazel mobile-install crashes for Real devices

Open FareesHussain opened this issue 4 years ago • 13 comments

Describe the bug Bazel mobile-install crashes for real devices (works for emulator)

To Reproduce Steps to reproduce the behavior:

  1. Build and install the app using bazel
  2. Open the app
  3. It crashes after splash screen

Expected behavior To work similar to gradle build

Device

  • Redmi note 7 pro
  • SDK version 29

Error Message Crash error

E/g.oppia.androi: Unknown bits set in runtime_flags: 0x8000
E/LoadedApk: Unable to instantiate appComponentFactory
    java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/data/app/org.oppia.android-Nz5_Caj0D5mUK14P9UHeHw==/base.apk"],nativeLibraryDirectories=[/data/app/org.oppia.android-Nz5_Caj0D5mUK14P9UHeHw==/lib/arm64, /system/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:230)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.LoadedApk.createAppFactory(LoadedApk.java:258)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:857)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:952)
        at android.app.LoadedApk.getResources(LoadedApk.java:1190)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2474)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2466)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6481)
        at android.app.ActivityThread.access$1400(ActivityThread.java:227)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1890)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7592)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
I/Perf: Connecting to perf service.
V/StubApplication: StubApplication created. Android package is org.oppia.android, real application class is org.oppia.android.app.application.OppiaApplication.
V/StubApplication: Found external resources at /data/local/tmp/incrementaldeployment/org.oppia.android/resources.ap_
V/IncrementalClassLoader: Incremental dex path is /data/local/tmp/incrementaldeployment/org.oppia.android/dex/incremental_classes1.dex:/data/local/tmp/incrementaldeployment/org.oppia.android/dex/incremental_classes2.dex
V/IncrementalClassLoader: Native lib dir is /data/user/0/org.oppia.android/lib
W/g.oppia.androi: Unsupported class loader
W/g.oppia.android: type=1400 audit(0.0:30808): avc: denied { write } for name="dex" dev="mmcblk0p87" ino=1578050 scontext=u:r:untrusted_app:s0:c216,c258,c512,c768 tcontext=u:object_r:shell_data_file:s0 tclass=dir permissive=0
W/g.oppia.androi: Unsupported class loader
W/g.oppia.android: type=1400 audit(0.0:30809): avc: denied { write } for name="dex" dev="mmcblk0p87" ino=1578050 scontext=u:r:untrusted_app:s0:c216,c258,c512,c768 tcontext=u:object_r:shell_data_file:s0 tclass=dir permissive=0
W/g.oppia.androi: Accessing hidden field Ljava/lang/ClassLoader;->parent:Ljava/lang/ClassLoader; (greylist, reflection, allowed)
I/MultiDex: VM with version 2.1.0 has multidex support
I/MultiDex: Installing application
I/MultiDex: VM has multidex support, MultiDex support library is disabled.
V/INCREMENTAL: disableContentProviders
W/g.oppia.androi: Accessing hidden method Landroid/app/ActivityThread;->currentActivityThread()Landroid/app/ActivityThread; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden field Landroid/app/ActivityThread;->mBoundApplication:Landroid/app/ActivityThread$AppBindData; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden field Landroid/app/ActivityThread$AppBindData;->providers:Ljava/util/List; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden field Landroid/app/ActivityThread;->mInitialApplication:Landroid/app/Application; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden field Landroid/app/ActivityThread;->mAllApplications:Ljava/util/ArrayList; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden field Landroid/app/LoadedApk;->mApplication:Landroid/app/Application; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden field Landroid/app/LoadedApk;->mResDir:Ljava/lang/String; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden field Landroid/app/Application;->mLoadedApk:Landroid/app/LoadedApk; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden field Landroid/app/ActivityThread;->mPackages:Landroid/util/ArrayMap; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden field Landroid/app/ActivityThread;->mResourcePackages:Landroid/util/ArrayMap; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden method Landroid/content/res/AssetManager;-><init>()V (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden method Landroid/content/res/AssetManager;->addAssetPath(Ljava/lang/String;)I (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden method Landroid/app/ResourcesManager;->getInstance()Landroid/app/ResourcesManager; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden field Landroid/app/ResourcesManager;->mResourceReferences:Ljava/util/ArrayList; (greylist, reflection, allowed)
W/g.oppia.androi: Accessing hidden field Landroid/content/res/Resources;->mResourcesImpl:Landroid/content/res/ResourcesImpl; (greylist, reflection, allowed)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.oppia.android, PID: 4243
    java.lang.RuntimeException: Unable to create application com.google.devtools.build.android.incrementaldeployment.StubApplication: java.lang.IllegalStateException: java.lang.NoSuchFieldException: No field mAssets in class Landroid/content/res/MiuiResourcesImpl; (declaration of 'android.content.res.MiuiResourcesImpl' appears in /system/framework/framework.jar)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6617)
        at android.app.ActivityThread.access$1400(ActivityThread.java:227)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1890)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7592)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
     Caused by: java.lang.IllegalStateException: java.lang.NoSuchFieldException: No field mAssets in class Landroid/content/res/MiuiResourcesImpl; (declaration of 'android.content.res.MiuiResourcesImpl' appears in /system/framework/framework.jar)
        at com.google.devtools.build.android.incrementaldeployment.StubApplication.monkeyPatchExistingResources(StubApplication.java:320)
        at com.google.devtools.build.android.incrementaldeployment.StubApplication.onCreate(StubApplication.java:569)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1190)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6612)
        at android.app.ActivityThread.access$1400(ActivityThread.java:227) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1890) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:224) 
        at android.app.ActivityThread.main(ActivityThread.java:7592) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) 
     Caused by: java.lang.NoSuchFieldException: No field mAssets in class Landroid/content/res/MiuiResourcesImpl; (declaration of 'android.content.res.MiuiResourcesImpl' appears in /system/framework/framework.jar)
        at java.lang.Class.getDeclaredField(Native Method)
        at com.google.devtools.build.android.incrementaldeployment.StubApplication.monkeyPatchExistingResources(StubApplication.java:312)
        at com.google.devtools.build.android.incrementaldeployment.StubApplication.onCreate(StubApplication.java:569) 
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1190) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6612) 
        at android.app.ActivityThread.access$1400(ActivityThread.java:227) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1890) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:224) 
        at android.app.ActivityThread.main(ActivityThread.java:7592) 

FareesHussain avatar Feb 03 '21 16:02 FareesHussain

Can this https://stackoverflow.com/a/60291944 be a solution to this issue ?

kartikeysaran avatar Feb 03 '21 17:02 kartikeysaran

Can this https://stackoverflow.com/a/60291944 be a solution to this issue ?

This issue is related to Bazel build

FareesHussain avatar Feb 03 '21 17:02 FareesHussain

Odd, I don't see this. Will try a fresh build again later this week and see if I can repro it.

BenHenning avatar Feb 03 '21 18:02 BenHenning

@FareesHussain Did you try uninstalling the app from your real device completely and then re-running the app? Like some android phones also have a "Second Space", so you must ensure that it gets uninstalled from there too.

prayutsu avatar Feb 03 '21 19:02 prayutsu

@FareesHussain Did you try uninstalling the app from your real device completely and then re-running the app? Like some android phones also have a "Second Space", so you must ensure that it gets uninstalled from there too.

Yes, I tried it. I've also tried to install the app using

  • Bazel mobile-installl
  • adb install app-incremental.apk
  • Directly installing the apk through mobile

FareesHussain avatar Feb 04 '21 01:02 FareesHussain

It's working for me, tried on pixel 3a XL real device.

anandwana001 avatar Feb 04 '21 04:02 anandwana001

is this issue still exist? @FareesHussain

anandwana001 avatar Feb 08 '21 06:02 anandwana001

Yeah for my device. There is also the same issue when I tried to install the example app (from documentation).

FareesHussain avatar Feb 08 '21 06:02 FareesHussain

Builds and runs on Pixel 4a fine

jcqli avatar Feb 11 '21 20:02 jcqli

I suggest switching the top-level build to use legacy multidex & use 3 shards and see if that works--this might be a bug with the device's Multidex loader.

BenHenning avatar Feb 18 '21 16:02 BenHenning

I tried installing it through bazel, it got installed successfully and SplashActivity appeared for a second and it got crashed. Device - Redmi K20 Pro API - 29

prayutsu avatar Feb 19 '21 09:02 prayutsu

So interestingly, I noticed the LoadedApk error myself locally. It seems like an unrelated issue since the app wasn't crashing for me. We should still dig into why it's happening, but the crash might be due to something else.

BenHenning avatar Feb 23 '21 18:02 BenHenning

@fsharpasharp can you check if you can reproduce this

also mention the device in which you've installed

FareesHussain avatar Mar 11 '21 13:03 FareesHussain