Android apps crash at startup on .2518

On .2518, Android apps that use external libraries crash at startup on a NoClassDefFoundError.

Here’s a sample project - new project with Google’s appcompat library added.

org.me.androidapplication2.zip (1.4 MB)

:(. whats the last version you used that worked? nothing really changed on that front in forever. What class does it fail on, and are there more details in logcat?

Last version I used that worked was .2503 - I keep having to revert to this one because that “inheritance tree” error starts showing up after 2503.

05-27 12:20:02.048 30857 30857 E AndroidRuntime: FATAL EXCEPTION: main
05-27 12:20:02.048 30857 30857 E AndroidRuntime: Process: com.accordancebible.accordance, PID: 30857
05-27 12:20:02.048 30857 30857 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/R$drawable;
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at androidx.appcompat.widget.AppCompatDrawableManager$1.<init>(AppCompatDrawableManager.java:63)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at androidx.appcompat.widget.AppCompatDrawableManager.preload(AppCompatDrawableManager.java:57)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:328)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:278)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:221)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:543)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at androidx.appcompat.app.AppCompatActivity.attachBaseContext(AppCompatActivity.java:98)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at android.app.Activity.attach(Activity.java:7731)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3224)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:107)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:214)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:7356)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
05-27 12:20:02.048 30857 30857 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.appcompat.R$drawable" on path: DexPathList[[zip file "/data/app/com.accordancebible.accordance-FsOpGqm6vymh8sfjabzn5A==/base.apk"],nativeLibraryDirectories=[/data/app/com.accordancebible.accordance-FsOpGqm6vymh8sfjabzn5A==/lib/arm64, /system/lib64, /product/lib64]]
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
05-27 12:20:02.048 30857 30857 E AndroidRuntime:        ... 20 more

androidx.appcompat.R$drawable

damn. thats my fix for not generating 287 copies of the R class. guess those are needed after all? Either that or androidx.appcompat.R is in androidx.appcompat’s .jar and the design is broken :(. lemme find out which…

Ah, yeah I do need the R class copies :slightly_smiling_face: It’s actually not uncommon practice to reference them directly (e.g., google.android.material.R.snackbar_text)

Yeah, according to ebuild --dump the original jars don’t have em. I’ll add em back.

Started a new build for you with the fix; problem is, someone else reported hitting .dex size limits with D8 with these classes (for a trivially small main project), which is weird on its own, since D8 is supposed to always multi-dex on its now, right?)

1 Like

I’m pretty sure that EBuild is manually splitting off multiple dex files, right? I’ve noticed when I analyze an APK built in Android Studio that I’ll have a few large dex files but my main project from EBuild has ~50 small dex files. That could just be because my main EBuild project is larger than anything I’m doing in Android Studio though.

But if that is the case, perhaps EBuild splits at the class level but the user that reported the problem has a single class that exceeds the 64k method limit? Just a wild guess

Well, I predex each reference independently, and then I separately dex the compiler output. In the other users case just the compiler output itself failed to dex, because the jar hav more than 65k items (from like 200 copies of R files). I had expected D8 to automatically multi-dex and generate two (or more) .dex files fro the single jar, but instead it failed (on old DEX, multi-deximng was an option, on d8 its no longer), so not sure why that was failing (just that dropping the extra Rs mitigated the issue :wink:

so you shouldered up with 1+ dex per reference and 1+ dex for your own code

No , the user’s code was virtually empty (one standard Activity class-from-template, plus a few hundred R classes (each with a few hundred members => over 65k members total, all in the main jar.

.2518 (B) fixes the runtime exception, but I am still getting a compiler error that seems related to this. I’m not able to reference R.java constants from library project. For example, I should be able to do something like this

findViewById(com.google.android.material.R.id.snackbar_text)

On .2503 I can, but on 2518 and 2518(B) I get an “unknown identifier” compiler error.

org.android2518.zip (2.2 MB)

Hmm. But do yours we all the R.java files passed to the compiler? is com.google.android.material.R.id.snackbar_text in there?

What do you mean? Does com.google.android.material.R.id.snackbar_text exist in the library? It’s the same code that compiles and works correctly in .2503, but in .2518 I get the “unknown identifier” error

If you check the build log, are all the R.java files being passed to the compiler? If so, if you look at the actual file, is com.google.android.material.R.id.snackbar_text actually declared in any of em?

Nope, the source files aren’t there, just

                  Source file: /Users/mh/Library/Application Support/RemObjects Software/EBuild/Obj/org.android2518-B103C3A5E6DEEB5EAF7D5706579A9D7AB527565E/Debug/Cooper-Android/java/org/android2518/R.java

so in essence it’s as if nothing changed. investigating…

Ah damn, this is in two places, for aapt and aapt2. I only fixed one ;).

What doesnt make sense is

.2518 (B) fixes the runtime exception,

because that should also still fail, as thats the same underlying cause…

Fixed, & works (only tested then compile error, not running the app, as I don’t have my Android test device handy).

1 Like

Up.

1 Like

So on .2518[C] I am able to add the reference and build successfully (I think) but when I try to run my project I immediately get an error “Target(s) 'Cooper-Android' not found in project.

Hmm, strange. that seems to be an entirely unrelated issue though? lemme see…