Fixed
Status Update
Comments
he...@google.com <he...@google.com> #2
Thank you for reporting this Jeff. Would it be possible to share the project that triggers this? That would greatly help with reproducing the issue. Sharing via drive or sending via email to herhut@google.com would be great.
ga...@google.com <ga...@google.com> #3
The warning in == 1 ==, about the keep rules, is due to main dex list calculation. List of classes that you see with 3.1.0-alpha06 and 3.1.0-alpha07 are the main dex classes.
In == 2 ==, instead of switching to 3.0.1, can you please try running with -Pandroid.enableD8=false? Does it fix this issue?
In == 2 ==, instead of switching to 3.0.1, can you please try running with -Pandroid.enableD8=false? Does it fix this issue?
je...@gmail.com <je...@gmail.com> #4
I just tried a build with -Pandroid.enableD8=false and it produces the same issue (app crashes at runtime)
he...@google.com <he...@google.com> #5
I suspect this to be a legacy multi-dex issue. I assume your app has multiple dex files? Does the app also fail on recent versions of Android? If so, could you attach or email me the list of classes contained in a working build using gradle plugin 3.0 and the list of classes contained in a non-working build using the 3.1 plugin?
You can compute that list by extracting the classes.dex file from the APK and then running
dexdump classes.dex | grep "Class descriptor" > classlist
If you prefer not to share the whole list, you can also share just the diff between the two.
You can compute that list by extracting the classes.dex file from the APK and then running
dexdump classes.dex | grep "Class descriptor" > classlist
If you prefer not to share the whole list, you can also share just the diff between the two.
he...@google.com <he...@google.com> #6
Ivan hinted me to the fact that this is already running on art. So it cannot be a direct multi-dex issue. It would still be interesting to see the contained classes, or their diff. As this is not multi-dex, please provide the diff for all dex file pairs (classes.dex, classes2.dex, etc.).
je...@gmail.com <je...@gmail.com> #7
I have an "android-template" app that I have put up on Github that has the same issue.
https://github.com/jeffdcamp/android-template
To reproduce the issue:
1. Checkout the code fromhttps://github.com/jeffdcamp/android-template
2. Change the gradle plugin to
classpath 'com.android.tools.build:gradle:3.1.0-alpha08'
3. From AS3.1 do a Build > Rebuild Project.
Note: The following will appear in RED in the Build log
Warning: The rule `-keep public class *extends java.lang.annotation.Annotation {
<all>;
}` uses extends but actually matches implements.
FYI... Anytime I see this warning, I know the app will crash at runtime
4. Run the app
Result:
The app will crash
To reproduce the issue:
1. Checkout the code from
2. Change the gradle plugin to
classpath 'com.android.tools.build:gradle:3.1.0-alpha08'
3. From AS3.1 do a Build > Rebuild Project.
Note: The following will appear in RED in the Build log
Warning: The rule `-keep public class *extends java.lang.annotation.Annotation {
<all>;
}` uses extends but actually matches implements.
FYI... Anytime I see this warning, I know the app will crash at runtime
4. Run the app
Result:
The app will crash
ga...@google.com <ga...@google.com> #8
Ok, there are 2 issues that I've found so far:
1) when building legacy multidex, main dex list is incomplete when using R8. Running the project on emulator API 19, fails with
java.lang.NoClassDefFoundError: org.jdc.template.log.DebugTree
at org.jdc.template.App.setupLogging(App.kt:39)
at org.jdc.template.App.onCreate(App.kt:28)
Reason is that superclass of org.jdc.template.log.DebugTree, which is timber.log.Timber$DebugTree.
2) second issue is duplicate ofhttps://issuetracker.google.com/72085541 . The issue is that with Build -> Rebuild Project will build the legacy multdex version of the apk. Then if you run on device/emulator 21+, it fails because classes are missing.
1) when building legacy multidex, main dex list is incomplete when using R8. Running the project on emulator API 19, fails with
java.lang.NoClassDefFoundError: org.jdc.template.log.DebugTree
at org.jdc.template.App.setupLogging(App.kt:39)
at org.jdc.template.App.onCreate(App.kt:28)
Reason is that superclass of org.jdc.template.log.DebugTree, which is timber.log.Timber$DebugTree.
2) second issue is duplicate of
ga...@google.com <ga...@google.com> #9
Regarding 1), the issue is that linking org.jdc.template.log.DebugTree fails, as timber.log.Timber$DebugTree is not linked nor initialized when instance is created, and it is in secondary dex file. Simply linking and initializing the superclass before instance is created solves the issue.
I've attached a simple repro project, that fails on API 19. However, if a line in App.onCreate() is uncommented, it works.
I've attached a simple repro project, that fails on API 19. However, if a line in App.onCreate() is uncommented, it works.
je...@gmail.com <je...@gmail.com> #10
Trying to follow along.... cannot download attachment in #9 SeparateDexForSuperClass.zip... error: "Failed - Forbidden"
ga...@google.com <ga...@google.com> #11
Re #10:
You can also use your test project (it seems attachment from #9 is only for internal members). To fix:
1) The main dex lssue, add to gradle.properties: android.enableD8MainDexList=false
2) To fix the packaging issue, please clean the project, and just click run directly (without Build -> Rebuilt project first)
Please let us know if these 2 workarounds fix the issues for you.
You can also use your test project (it seems attachment from #9 is only for internal members). To fix:
1) The main dex lssue, add to gradle.properties: android.enableD8MainDexList=false
2) To fix the packaging issue, please clean the project, and just click run directly (without Build -> Rebuilt project first)
Please let us know if these 2 workarounds fix the issues for you.
he...@google.com <he...@google.com>
mt...@gmail.com <mt...@gmail.com> #12
Install app everytime failed on Sencor Element Andorid 4.1.2 on NoClassDefFound until I set: android.enableD8MainDexList=false
After set: android.enableD8MainDexList=false app start again!
It didn't help to switch android.enableD8=false or android.enableD8=true or disable or dexOptions.preDexLibraries = true/false
After set: android.enableD8MainDexList=false app start again!
It didn't help to switch android.enableD8=false or android.enableD8=true or disable or dexOptions.preDexLibraries = true/false
mt...@gmail.com <mt...@gmail.com> #13
clean/rebuild or anything else never help for this device
je...@gmail.com <je...@gmail.com> #14
I followed the instructions on #11 on both the test project and our main production project (which had the original issue).... and the apps run without crashing
So it seems that after I add android.enableD8MainDexList=false to the gradle.properties, then...
1. If I do a "./gradlew clean", then clicking on Run makes the apps work!
2. If I do a Build -> Rebuild, then a Run, then the apps crashes at runtime
3. If I do a "./gradlew clean aDebug", then do an "adb install build/outputs/apk/debug/android-template-debug.apk ", then the apps works!
So it seems that after I add android.enableD8MainDexList=false to the gradle.properties, then...
1. If I do a "./gradlew clean", then clicking on Run makes the apps work!
2. If I do a Build -> Rebuild, then a Run, then the apps crashes at runtime
3. If I do a "./gradlew clean aDebug", then do an "adb install build/outputs/apk/debug/android-template-debug.apk ", then the apps works!
ap...@google.com <ap...@google.com> #15
Project: r8
Branch: master
commit 1f1f068cc7d1112fb3417ebbaed83bf5696a4ddb
Author: Yohann Roussel <yroussel@google.com>
Date: Mon Jan 22 16:12:20 2018
Include hierarchy of direct dependencies
Direct dependency classes may be loaded before secondary dex
installation: so their hierarchy is needed in the main dex or they
will be rejected at load and cause NoClassDefFoundError at first use.
Bug: 72039872
Change-Id: Ida42c70f9c8e1c7e16ad779bce7ea038a8124782
M src/main/java/com/android/tools/r8/shaking/MainDexListBuilder.java
A src/test/examples/multidex005/ClassReference.java
A src/test/examples/multidex005/DirectlyReferenced.java
A src/test/examples/multidex005/FieldReference.java
A src/test/examples/multidex005/GetFieldReference.java
A src/test/examples/multidex005/IndirectlyReferenced.java
A src/test/examples/multidex005/IndirectlyReferencedInterface.java
A src/test/examples/multidex005/IndirectlyReferencedSuperClass.java
A src/test/examples/multidex005/Interface1.java
A src/test/examples/multidex005/Interface2.java
A src/test/examples/multidex005/Interface3.java
A src/test/examples/multidex005/InvokeReference.java
A src/test/examples/multidex005/NewReference.java
A src/test/examples/multidex005/ParameterReference.java
A src/test/examples/multidex005/ReturnReference.java
A src/test/examples/multidex005/SuperClass.java
A src/test/examples/multidex005/SuperInterface.java
A src/test/examples/multidex005/SuperSuperClass.java
A src/test/examples/multidex005/main-dex-rules-1.txt
A src/test/examples/multidex005/main-dex-rules-2.txt
A src/test/examples/multidex005/main-dex-rules-3.txt
A src/test/examples/multidex005/main-dex-rules-4.txt
A src/test/examples/multidex005/main-dex-rules-5.txt
A src/test/examples/multidex005/main-dex-rules-6.txt
A src/test/examples/multidex005/ref-list-1.txt
A src/test/examples/multidex005/ref-list-2.txt
A src/test/examples/multidex005/ref-list-3.txt
A src/test/examples/multidex005/ref-list-4.txt
A src/test/examples/multidex005/ref-list-5.txt
A src/test/examples/multidex005/ref-list-6.txt
M src/test/java/com/android/tools/r8/maindexlist/MainDexTracingTest.java
https://r8-review.googlesource.com/14800
Branch: master
commit 1f1f068cc7d1112fb3417ebbaed83bf5696a4ddb
Author: Yohann Roussel <yroussel@google.com>
Date: Mon Jan 22 16:12:20 2018
Include hierarchy of direct dependencies
Direct dependency classes may be loaded before secondary dex
installation: so their hierarchy is needed in the main dex or they
will be rejected at load and cause NoClassDefFoundError at first use.
Bug: 72039872
Change-Id: Ida42c70f9c8e1c7e16ad779bce7ea038a8124782
M src/main/java/com/android/tools/r8/shaking/MainDexListBuilder.java
A src/test/examples/multidex005/ClassReference.java
A src/test/examples/multidex005/DirectlyReferenced.java
A src/test/examples/multidex005/FieldReference.java
A src/test/examples/multidex005/GetFieldReference.java
A src/test/examples/multidex005/IndirectlyReferenced.java
A src/test/examples/multidex005/IndirectlyReferencedInterface.java
A src/test/examples/multidex005/IndirectlyReferencedSuperClass.java
A src/test/examples/multidex005/Interface1.java
A src/test/examples/multidex005/Interface2.java
A src/test/examples/multidex005/Interface3.java
A src/test/examples/multidex005/InvokeReference.java
A src/test/examples/multidex005/NewReference.java
A src/test/examples/multidex005/ParameterReference.java
A src/test/examples/multidex005/ReturnReference.java
A src/test/examples/multidex005/SuperClass.java
A src/test/examples/multidex005/SuperInterface.java
A src/test/examples/multidex005/SuperSuperClass.java
A src/test/examples/multidex005/main-dex-rules-1.txt
A src/test/examples/multidex005/main-dex-rules-2.txt
A src/test/examples/multidex005/main-dex-rules-3.txt
A src/test/examples/multidex005/main-dex-rules-4.txt
A src/test/examples/multidex005/main-dex-rules-5.txt
A src/test/examples/multidex005/main-dex-rules-6.txt
A src/test/examples/multidex005/ref-list-1.txt
A src/test/examples/multidex005/ref-list-2.txt
A src/test/examples/multidex005/ref-list-3.txt
A src/test/examples/multidex005/ref-list-4.txt
A src/test/examples/multidex005/ref-list-5.txt
A src/test/examples/multidex005/ref-list-6.txt
M src/test/java/com/android/tools/r8/maindexlist/MainDexTracingTest.java
mt...@gmail.com <mt...@gmail.com> #16
Isn't it a bit broken, when I have: android.enableD8=false but it still use R8 for build and crash on NoClassDefFound? And is required to add: android.enableD8MainDexList=false for success build?
D8/R8 I read, that's something different, but think, that it's developed together and should not influence current builds which don't use D8.
D8/R8 I read, that's something different, but think, that it's developed together and should not influence current builds which don't use D8.
yr...@google.com <yr...@google.com> #17
android.enableD8 is selecting only the dexer which is independent from the main dex list calculation. It just happen that D8/R8 is also providing a main dex list calculation.
I agree though, that the naming of the properties may be confusing.
I agree though, that the naming of the properties may be confusing.
ma...@gmail.com <ma...@gmail.com> #18
we also noticed this issue, I dont know how to reproduce it exactly but it feels like it happens when I switch branches e.g. master -> feature (couple of classes added) then it fails, to fix it I need to switch back and forth between flavors e.g. release/debug and then it works again
yr...@google.com <yr...@google.com> #19
The fix reached R8 1.0.3 and should be in Android Studio 3.1 Beta 2 (3.1.0.10)
az...@lyft.com <az...@lyft.com> #20
Confirming that switching to Android Gradle Plugin 3.2.0-alpha01 fixes the problem (we were seeing it on AGP 3.1.0-alpha09)
le...@gmail.com <le...@gmail.com> #21
When the Android Gradle Plugin 3.2.0-alpha01 version will be released on a normal version(for example 3.2.0)?
sh...@gmail.com <sh...@gmail.com> #22
to reproduce it exactly but it feels like it happens when I switch branches e.g. master -> feature (couple of classes added) then it fails, to fix it I need to switch back and forth between flavors e.g. release/debug and
Description
Also See:
Which was CLOSED with comment: "This doesn't appear to be a dagger issue but rather an Android buildtools one...
As long as Dagger generates code that javac compiles, we have nothing more we can really do."
Sample RUNTIME Logcat:
12-20 15:22:15.722 3758-3758/? I/art: Rejecting re-init on previously-failed class java.lang.Class<dagger.internal.Factory>: java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/inject/Provider;
12-20 15:22:15.722 3758-3758/? I/art: at com.yourpackagename.v2.di.components.DaggerApplicationComponent$Builder com.yourpackagename.v2.di.components.DaggerApplicationComponent.builder() (DaggerApplicationComponent.java:67)
12-20 15:22:15.722 3758-3758/? I/art: at void com.yourpackagename.AppController.initializeApplicationComponent() (AppController.java:97)
12-20 15:22:15.722 3758-3758/? I/art: at void com.yourpackagename.AppController.onCreate() (AppController.java:59)
12-20 15:22:15.722 3758-3758/? I/art: at void android.app.Instrumentation.callApplicationOnCreate(android.app.Application) (Instrumentation.java:1024)
12-20 15:22:15.722 3758-3758/? I/art: at void android.app.ActivityThread.handleBindApplication(android.app.ActivityThread$AppBindData) (ActivityThread.java:5361)
12-20 15:22:15.722 3758-3758/? I/art: at void android.app.ActivityThread.-wrap2(android.app.ActivityThread, android.app.ActivityThread$AppBindData) (ActivityThread.java:-1)
12-20 15:22:15.722 3758-3758/? I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1528)
12-20 15:22:15.722 3758-3758/? I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
12-20 15:22:15.722 3758-3758/? I/art: at void android.os.Looper.loop() (Looper.java:154)
12-20 15:22:15.722 3758-3758/? I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6077)
12-20 15:22:15.722 3758-3758/? I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
12-20 15:22:15.722 3758-3758/? I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:866)
12-20 15:22:15.722 3758-3758/? I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:756)
12-20 15:22:15.722 3758-3758/? I/art: Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.inject.Provider" on path: DexPathList[[zip file "/data/app/com.yourpackagename.dev-1/base.apk"],nativeLibraryDirectories=[/data/app/com.yourpackagename.dev-1/lib/x86, /data/app/com.yourpackagename.dev-1/base.apk!/lib/x86, /system/lib, /vendor/lib]]
12-20 15:22:15.722 3758-3758/? I/art: at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
12-20 15:22:15.722 3758-3758/? I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
12-20 15:22:15.722 3758-3758/? I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
12-20 15:22:15.722 3758-3758/? I/art: at com.yourpackagename.v2.di.components.DaggerApplicationComponent$Builder com.yourpackagename.v2.di.components.DaggerApplicationComponent.builder() (DaggerApplicationComponent.java:67)
12-20 15:22:15.722 3758-3758/? I/art: at void com.yourpackagename.AppController.initializeApplicationComponent() (AppController.java:97)
12-20 15:22:15.722 3758-3758/? I/art: at void com.yourpackagename.AppController.onCreate() (AppController.java:59)
12-20 15:22:15.722 3758-3758/? I/art: at void android.app.Instrumentation.callApplicationOnCreate(android.app.Application) (Instrumentation.java:1024)
12-20 15:22:15.722 3758-3758/? I/art: at void android.app.ActivityThread.handleBindApplication(android.app.ActivityThread$AppBindData) (ActivityThread.java:5361)
12-20 15:22:15.722 3758-3758/? I/art: at void android.app.ActivityThread.-wrap2(android.app.ActivityThread, android.app.ActivityThread$AppBindData) (ActivityThread.java:-1)
12-20 15:22:15.722 3758-3758/? I/art: at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1528)
12-20 15:22:15.722 3758-3758/? I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
12-20 15:22:15.722 3758-3758/? I/art: at void android.os.Looper.loop() (Looper.java:154)
12-20 15:22:15.722 3758-3758/? I/art: at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6077)
12-20 15:22:15.722 3758-3758/? I/art: at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
12-20 15:22:15.722 3758-3758/? I/art: at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:866)
12-20 15:22:15.722 3758-3758/? I/art: at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:756)
12-20 15:22:15.723 3758-3758/? I/art: Rejecting re-init on previously-failed class java.lang.Class<com.yourpackagename.v2.di.module.ApplicationModule_ProvideContextFactory>: java.lang.NoClassDefFoundError: Failed resolution of: Ldagger/internal/Factory;
12-20 15:22:15.723 3758-3758/? I/art: at com.yourpackagename.v2.di.components.DaggerApplicationComponent$Builder com.yourpackagename.v2.di.components.DaggerApplicationComponent.builder() (DaggerApplicationComponent.java:67)
here is what I have found so far:
Configuration:
- APK project that depends on an library aar that both have a dependency on Dagger 2.14.1
- Library aar project depends on Dagger to allow the project to have the following annotations on several classes: @singleton
@Inject
- Android Studio 3.1 alpha 8
- Gradle 4.4.1
== 1 ==
On the apk project, if I use D8 to dex (using gradle plugin 'com.android.tools.build:gradle:3.1.0-alpha08'), then I get a warning during the build:
Warning: The rule -keep public class *extends java.lang.annotation.Annotation { <all>; } uses extends but actually matches implements.
With 'gradle:3.1.0-alpha06' and ''gradle:3.1.0-alpha07':
Then the gradle output shows a lot of classes that seem to get stripped out (possibly the reason for the runtime ClassNotFound issues). (I did make sure that Proguard IS NOT turned on)
With 'gradle:3.1.0-alpha08' listing of the classes is no longer shown
== 2 ==
On the apk project, if I switch the plugin to 'com.android.tools.build:gradle:3.0.1', then the issue goes away
== 3 ==
using gradle plugin 'com.android.tools.build:gradle:3.1.0-alpha08'....
If I remove Dagger dependency in the aar project (and remove the @Singleton and @Inject annotations), and then add @Provider functions, for the classes in the library, in the apk project's @module class.... then the issue goes away
NOTES:
- The aar project has been built with both versions of the gradle plugin an there is no difference
- The main issues seems to be if the aar library has a Dagger dependency and the apk project is building with gradle plugin 'com.android.tools.build:gradle:3.1.0-alpha08'