Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel demo app is crashing at startup on API 34 #19

Open
pablo-guardiola opened this issue Aug 30, 2024 · 4 comments
Open

Bazel demo app is crashing at startup on API 34 #19

pablo-guardiola opened this issue Aug 30, 2024 · 4 comments
Labels

Comments

@pablo-guardiola
Copy link
Contributor

pablo-guardiola commented Aug 30, 2024

I'm building the Bazel demo app using $> ./bazelw mobile-install --fat_apk_cpu=arm64-v8a --config=android :android_app (after getting it working #13 (comment)), the app gets generated and deployed to the connected device but when I open it, it crashes 💥

Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/data/app/~~wZbw6NKzRqj9th9Rtukf-A==/io.bitdrift.capture.helloworld-EkpwOd-TE_FE6PLK4wj9kA==/base.apk"],nativeLibraryDirectories=[/data/app/~~wZbw6NKzRqj9th9Rtukf-A==/io.bitdrift.capture.helloworld-EkpwOd-TE_FE6PLK4wj9kA==/lib/arm64, /data/app/~~wZbw6NKzRqj9th9Rtukf-A==/io.bitdrift.capture.helloworld-EkpwOd-TE_FE6PLK4wj9kA==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
	at android.app.LoadedApk.createAppFactory(LoadedApk.java:273)
	at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:1039)
	at android.app.LoadedApk.getClassLoader(LoadedApk.java:1126)
	at android.app.LoadedApk.getResources(LoadedApk.java:1374)
	at android.app.ContextImpl.createAppContext(ContextImpl.java:3324)
	at android.app.ContextImpl.createAppContext(ContextImpl.java:3316)
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6879)
	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2236)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:205)
	at android.os.Looper.loop(Looper.java:294)
	at android.app.ActivityThread.main(ActivityThread.java:8177)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

and

FATAL EXCEPTION: main
Process: io.bitdrift.capture.helloworld, PID: 19154
java.lang.RuntimeException: Unable to instantiate application com.google.devtools.build.android.incrementaldeployment.StubApplication package io.bitdrift.capture.helloworld: java.lang.SecurityException: Writable dex file '/data/local/tmp/incrementaldeployment/io.bitdrift.capture.helloworld/dex/incremental_classes1.dex' is not allowed.
	at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1555)
	at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1484)
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7666)
	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2478)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:230)
	at android.os.Looper.loop(Looper.java:319)
	at android.app.ActivityThread.main(ActivityThread.java:8934)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Caused by: java.lang.SecurityException: Writable dex file '/data/local/tmp/incrementaldeployment/io.bitdrift.capture.helloworld/dex/incremental_classes1.dex' is not allowed.
	at dalvik.system.DexFile.openDexFileNative(Native Method)
	at dalvik.system.DexFile.openDexFile(DexFile.java:406)
	at dalvik.system.DexFile.<init>(DexFile.java:128)
	at dalvik.system.DexFile.<init>(DexFile.java:101)
	at dalvik.system.DexPathList.loadDexFile(DexPathList.java:438)
	at dalvik.system.DexPathList.makeDexElements(DexPathList.java:387)
	at dalvik.system.DexPathList.<init>(DexPathList.java:166)
	at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:160)
	at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:105)
	at com.google.devtools.build.android.incrementaldeployment.IncrementalClassLoader$DelegateClassLoader.<init>(IncrementalClassLoader.java:57)
	at com.google.devtools.build.android.incrementaldeployment.IncrementalClassLoader$DelegateClassLoader.<init>(IncrementalClassLoader.java:54)
	at com.google.devtools.build.android.incrementaldeployment.IncrementalClassLoader.createDelegateClassLoader(IncrementalClassLoader.java:96)
	at com.google.devtools.build.android.incrementaldeployment.IncrementalClassLoader.<init>(IncrementalClassLoader.java:38)
	at com.google.devtools.build.android.incrementaldeployment.IncrementalClassLoader.inject(IncrementalClassLoader.java:113)
	at com.google.devtools.build.android.incrementaldeployment.StubApplication.instantiateRealApplication(StubApplication.java:338)
	at com.google.devtools.build.android.incrementaldeployment.StubApplication.attachBaseContext(StubApplication.java:546)
	at android.app.Application.attach(Application.java:365)
	at android.app.Instrumentation.newApplication(Instrumentation.java:1283)
	at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1547)
	at android.app.LoadedApk.makeApplicationInner(LoadedApk.java:1484) 
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7666) 
	at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) 
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2478) 
	at android.os.Handler.dispatchMessage(Handler.java:106) 
	at android.os.Looper.loopOnce(Looper.java:230) 
	at android.os.Looper.loop(Looper.java:319) 
	at android.app.ActivityThread.main(ActivityThread.java:8934) 
	at java.lang.reflect.Method.invoke(Native Method) 
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578) 
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103) 

It seems like an issue with the mobile-install toolchain.

cc @murki @mattklein123

@murki
Copy link
Contributor

murki commented Aug 30, 2024

Thanks for your report, I was able to repro and it does indeed look like an issue between bazel's mobile-install and the packaging of androidx.core.app.CoreComponentFactory which was added in API 28. May be related to this bazel issue: bazelbuild/bazel#17481

Here are some workarounds for now while we investigate:

  1. The app should run fine in devices or emulators with API < 28 (Android 9).
  2. Running the app via the bazel plugin directly from Android Studio as described in the README should work for all API levels.

Screenshot 2024-08-29 at 6 08 04 PM

@snowp
Copy link
Contributor

snowp commented Aug 30, 2024

I dug into this a little bit and I suspect that androidx.core.app.CoreComponentFactory is a red herring and that the issue is really due to

Caused by: java.lang.SecurityException: Writable dex file '/data/local/tmp/incrementaldeployment/io.bitdrift.capture.helloworld/dex/incremental_classes1.dex' is not allowed.

CoreComponentFactory is potentially just the first class loaded that hits this issue.

This seems to come down to a change in API 34 to not allow writeable dex files as part of the security posture, so it seems likely that some part of the toolchain is erroneously including a writeable file.

Next steps on our end is likely to try updating the rules_android toolchain since we are running an older version, then spend some more time trying to figure out what part of the toolchain is doing the wrong thing

@murki
Copy link
Contributor

murki commented Aug 30, 2024

Can confirm that the app also installs and runs fine for me on an emulator with API 33

@murki murki changed the title Bazel demo app is crashing at startup Bazel demo app is crashing at startup on API 34 Aug 30, 2024
@pablo-guardiola
Copy link
Contributor Author

Can confirm that the app also installs and runs fine for me on an emulator with API 33

Can confirm as well, tested on a Pixel 3 with API 31 👀


Running the app via the bazel plugin directly from Android Studio as described in the README should work for all API levels.

I can't quickly test that because the Bazel for Android Studio plugin doesn't work on Android Studio Koala | 2024.1.1 Patch 2

Screenshot 2024-09-01 at 6 57 36 PM

@murki murki added the android label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants