Fixed
Status Update
Comments
he...@google.com <he...@google.com> #2
Adding "api 'com.android.support:multidex:1.0.2'" to the application module fixes the issue. But adding "implementation 'com.android.support:multidex:1.0.2'" doesn't.
ga...@google.com <ga...@google.com> #3
Can you please share your build.gradle files (for application and android library), as I am unable to reproduce?
From the screenshot, classes8.dex contains only references to the MultiDexApplication, it does not contain definitions of the class. If you execute `dexdump <path_to_apk>` are you able to see the definition of MultiDexApplication?
From the screenshot, classes8.dex contains only references to the MultiDexApplication, it does not contain definitions of the class. If you execute `dexdump <path_to_apk>` are you able to see the definition of MultiDexApplication?
je...@gmail.com <je...@gmail.com> #4
See attachments for more info.
he...@google.com <he...@google.com> #5
The difference when building from Studio is that we take into consideration the API of the device you are deploying to, so we might change legacy multidex build to a native multidex one. It looks like the device you are deploying to has API 25, so that is why APK differs when building from the command line and when building from the IDE. In legacy multidex we have requirements due to DalvikVM which classes are in the main dex, and that's why MultiDexApplication is in the classes.dex. However, for native multidex, ART is able to load classes from any classes<N>.dex file. So it is strange that the runtime is unable to find MultiDexApplication, when it's clearly in classes13.dex.
What is the device that you are trying to deploy the app to? From the screenshots it looks like it's a Chromebook?
What is the device that you are trying to deploy the app to? From the screenshots it looks like it's a Chromebook?
he...@google.com <he...@google.com> #6
I tested if the Chromebook was the issue by trying the same on the Nexus 6P running Oreo. And the Nexus 6P has the same issue.
The logcat says:
09-06 11:33:09.672 10942-10942/? E/dex2oat: Failed to open dex file from oat file. File: base.apk:classes8.dex Error: Failure to verify dex file 'base.apk:classes8.dex': Non-zero padding 65 before section start at ace
09-06 11:33:09.678 20659-10988/? I/CheckinUtil: Classify the device as Phone.
09-06 11:33:09.686 10942-10942/? I/dex2oat: dex2oat took 754.758ms (472.528ms cpu) (threads: 4)
09-06 11:33:09.693 581-23895/? E/installed: DexInv: --- END '/data/app/vmdl1021122682.tmp/base.apk' --- status=0x0100, process failed
09-06 11:33:09.694 581-23895/? E/installd: Failed to dexopt (256)
09-06 11:33:09.695 795-829/? W/PackageManager.DexOptimizer: Failed to dexopt
com.android.server.pm.Installer$InstallerException: android.os.ServiceSpecificException: Failed to dexopt (code 256)
at com.android.server.pm.Installer.dexopt(Installer.java:290)
at com.android.server.pm.PackageDexOptimizer.dexOptPath(PackageDexOptimizer.java:220)
at com.android.server.pm.PackageDexOptimizer.performDexOptLI(PackageDexOptimizer.java:175)
at com.android.server.pm.PackageDexOptimizer.performDexOpt(PackageDexOptimizer.java:123)
at com.android.server.pm.PackageManagerService.installPackageLI(PackageManagerService.java:18185)
at com.android.server.pm.PackageManagerService.installPackageTracedLI(PackageManagerService.java:17780)
at com.android.server.pm.PackageManagerService.-wrap33(Unknown Source:0)
at com.android.server.pm.PackageManagerService$6.run(PackageManagerService.java:15251)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
09-06 11:33:09.701 795-810/? I/ActivityManager: Force stopping com.visiolink.reader.wrapper appid=10264 user=-1: installPackageLI
See the attached file for the complete logcat.
I think it might be a 3. party library causing the issue. I will try to remove it and see what happens.
The logcat says:
09-06 11:33:09.672 10942-10942/? E/dex2oat: Failed to open dex file from oat file. File: base.apk:classes8.dex Error: Failure to verify dex file 'base.apk:classes8.dex': Non-zero padding 65 before section start at ace
09-06 11:33:09.678 20659-10988/? I/CheckinUtil: Classify the device as Phone.
09-06 11:33:09.686 10942-10942/? I/dex2oat: dex2oat took 754.758ms (472.528ms cpu) (threads: 4)
09-06 11:33:09.693 581-23895/? E/installed: DexInv: --- END '/data/app/vmdl1021122682.tmp/base.apk' --- status=0x0100, process failed
09-06 11:33:09.694 581-23895/? E/installd: Failed to dexopt (256)
09-06 11:33:09.695 795-829/? W/PackageManager.DexOptimizer: Failed to dexopt
com.android.server.pm.Installer$InstallerException: android.os.ServiceSpecificException: Failed to dexopt (code 256)
at com.android.server.pm.Installer.dexopt(Installer.java:290)
at com.android.server.pm.PackageDexOptimizer.dexOptPath(PackageDexOptimizer.java:220)
at com.android.server.pm.PackageDexOptimizer.performDexOptLI(PackageDexOptimizer.java:175)
at com.android.server.pm.PackageDexOptimizer.performDexOpt(PackageDexOptimizer.java:123)
at com.android.server.pm.PackageManagerService.installPackageLI(PackageManagerService.java:18185)
at com.android.server.pm.PackageManagerService.installPackageTracedLI(PackageManagerService.java:17780)
at com.android.server.pm.PackageManagerService.-wrap33(Unknown Source:0)
at com.android.server.pm.PackageManagerService$6.run(PackageManagerService.java:15251)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
09-06 11:33:09.701 795-810/? I/ActivityManager: Force stopping com.visiolink.reader.wrapper appid=10264 user=-1: installPackageLI
See the attached file for the complete logcat.
I think it might be a 3. party library causing the issue. I will try to remove it and see what happens.
je...@gmail.com <je...@gmail.com> #7
Logcat was missing in #6
ga...@google.com <ga...@google.com> #8
It is this library that causes the issue:
https://github.com/chartbeat-labs/android_sdk
The library is initialized in Application.onCreate.
From the multidex docs:
Caution: Do not execute MultiDex.install() or any other code through reflection or JNI before MultiDex.install() is complete. Multidex tracing will not follow those calls, causing ClassNotFoundException or verify errors due to a bad class partition between DEX files.
So this library must be loading through reflection. But when is attachBaseContext called in relation to onCreate? And why does having the multidex dependency in the application module fix the issue?
The library is initialized in Application.onCreate.
From the multidex docs:
Caution: Do not execute MultiDex.install() or any other code through reflection or JNI before MultiDex.install() is complete. Multidex tracing will not follow those calls, causing ClassNotFoundException or verify errors due to a bad class partition between DEX files.
So this library must be loading through reflection. But when is attachBaseContext called in relation to onCreate? And why does having the multidex dependency in the application module fix the issue?
ga...@google.com <ga...@google.com> #9
I don't even need to initialize it. It fails just be including it as a dependency in the application module:
implementation 'com.chartbeat:sdk:1.3.4'
implementation 'com.chartbeat:sdk:1.3.4'
je...@gmail.com <je...@gmail.com> #10
When running on Android N and above, MultiDex.install() is a no-op, so that is not where to problem is coming from.
However, your classes8.dex is corrupt, and all classes from classes8, 9, 10 etc will not be loaded. Considering that MultiDex is in classes13.dex, exception is thrown. When you add the multidex suppor library directly, we just end up packaging dex files in a way that does not break dex2oat.
This issue might be in the dex merger. Can you add android.useDexArchive=false to gradle.properties? After that, can you set android.useDexArchive=true and add android.enableD8=true?
However, your classes8.dex is corrupt, and all classes from classes8, 9, 10 etc will not be loaded. Considering that MultiDex is in classes13.dex, exception is thrown. When you add the multidex suppor library directly, we just end up packaging dex files in a way that does not break dex2oat.
This issue might be in the dex merger. Can you add android.useDexArchive=false to gradle.properties? After that, can you set android.useDexArchive=true and add android.enableD8=true?
ga...@google.com <ga...@google.com> #11
android.useDexArchive=false => Fixes the issue
android.useDexArchive=true, android.enableD8=true: => Also fixes the issue.
android.useDexArchive=true, android.enableD8=true: => Also fixes the issue.
he...@google.com <he...@google.com>
mt...@gmail.com <mt...@gmail.com> #12
Can you upload the dex file that breaks dex2oat i.e. classes8.dex from comment #7 ?
mt...@gmail.com <mt...@gmail.com> #13
Broken classes8.dex
je...@gmail.com <je...@gmail.com> #14
classes8.dex from #13, contains only Lorg/jetbrains/anko/IntentsKt.
Which version of Anko are you using? Do you maybe have your own fork of the anko library?
Which version of Anko are you using? Do you maybe have your own fork of the anko library?
ap...@google.com <ap...@google.com> #15
I am using the official version 0.10.1. I have been using that version since 3. of july.
mt...@gmail.com <mt...@gmail.com> #16
Can you run with android.useDexArchive=true and android.enableBuildCache=false? I am wondering if we have a broken cached version of the library.
yr...@google.com <yr...@google.com> #17
Thanks a ton to cmw@ for figuring this one out.
This is an actual bug in our dexing pipeline, because we reuse the array for writing out the result. Dx had an assumption that array will always be initialized with 0s, so whenever it had to add padding, it just didn't. This was a dx performance optimization, but it also breaks us, as some dex file might pick up remains of the previous one (and that was happening here).
I am working on a fix, should have something ready soon.
This is an actual bug in our dexing pipeline, because we reuse the array for writing out the result. Dx had an assumption that array will always be initialized with 0s, so whenever it had to add padding, it just didn't. This was a dx performance optimization, but it also breaks us, as some dex file might pick up remains of the previous one (and that was happening here).
I am working on a fix, should have something ready soon.
ma...@gmail.com <ma...@gmail.com> #18
Great! For the record android.useDexArchive=true and android.enableBuildCache=false also fixes the issue.
yr...@google.com <yr...@google.com> #19
Thanks for the bug report, the fix should land in the plugin 3.0.0-beta6.
ag/I5fbd7fad2fb70de709e03e71476222f967ad8a5a
ag/I5fbd7fad2fb70de709e03e71476222f967ad8a5a
az...@lyft.com <az...@lyft.com> #20
Project: platform/dalvik
Branch: master
commit d67961b03525d8b58cfa55d33c8ca669dc16f563
Author: Jerome Dochez <jedo@google.com>
Date: Fri Jun 16 18:28:03 2017
Provide APIs to allow reusing the passed buffer.
no functional changes.
Test: existing.
Change-Id: I30fbf02b92e804238807b4c98c3536c5c4c60ca4
Consider DEX size for signature and checksum
When calculating signature and checksum for a DEX
file, consider the size of the DEX file, instead of
the array. An array bigger than the file can be
allocated, and this would lead to wrong signature
and checksum calculation.
Test: manually verified, existing tests
Change-Id: I0b6ae946cca7c0e71bb5e1f0ecbe209b91347c9d
Write zeros to byte array output
Because we reuse the output array
between seprate dx invocations, we
must write zeros to array. Otherwise, we might
end up picking up the output from
previous invocation.
Dx had an assumption that a new output
array is always allocated, and it was
a performance optimization not to write
zeros out. That does not apply any more.
BUG=65363025
Test: ByteArrayAnnotatedOutputTest
Change-Id: I984076e8078f9ed977f10cacb9b1b135b1d6358e
A dx/junit-tests/com/android/dx/util/ByteArrayAnnotatedOutputTest.java
M dx/src/com/android/dx/dex/file/DexFile.java
M dx/src/com/android/dx/util/ByteArray.java
M dx/src/com/android/dx/util/ByteArrayAnnotatedOutput.java
https://android-review.googlesource.com/479697
https://goto.google.com/android-sha1/d67961b03525d8b58cfa55d33c8ca669dc16f563
Branch: master
commit d67961b03525d8b58cfa55d33c8ca669dc16f563
Author: Jerome Dochez <jedo@google.com>
Date: Fri Jun 16 18:28:03 2017
Provide APIs to allow reusing the passed buffer.
no functional changes.
Test: existing.
Change-Id: I30fbf02b92e804238807b4c98c3536c5c4c60ca4
Consider DEX size for signature and checksum
When calculating signature and checksum for a DEX
file, consider the size of the DEX file, instead of
the array. An array bigger than the file can be
allocated, and this would lead to wrong signature
and checksum calculation.
Test: manually verified, existing tests
Change-Id: I0b6ae946cca7c0e71bb5e1f0ecbe209b91347c9d
Write zeros to byte array output
Because we reuse the output array
between seprate dx invocations, we
must write zeros to array. Otherwise, we might
end up picking up the output from
previous invocation.
Dx had an assumption that a new output
array is always allocated, and it was
a performance optimization not to write
zeros out. That does not apply any more.
BUG=65363025
Test: ByteArrayAnnotatedOutputTest
Change-Id: I984076e8078f9ed977f10cacb9b1b135b1d6358e
A dx/junit-tests/com/android/dx/util/ByteArrayAnnotatedOutputTest.java
M dx/src/com/android/dx/dex/file/DexFile.java
M dx/src/com/android/dx/util/ByteArray.java
M dx/src/com/android/dx/util/ByteArrayAnnotatedOutput.java
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'