Bug P2
Status Update
Comments
ga...@google.com <ga...@google.com> #2
Do you have a repro project that you could share with us?
There should be no need to excluding any dependencies: we automatically remove them from the test APK if they are in the main APK.
There should be no need to excluding any dependencies: we automatically remove them from the test APK if they are in the main APK.
pe...@layer.com.c-02odbdyf.appstempdomain.goog <pe...@layer.com.c-02odbdyf.appstempdomain.goog> #3
Here are the main dex lists (3.1.1's looks rather short). I’ve also attached the project I’m working on as it’s open source rather than wasting time trying to make a sample project. Let me know if that helps
ga...@google.com <ga...@google.com> #4
Thank you for sharing the project, I was able to reproduce.
The issue is that the main dex list for the test APK does not contain the test classes. AndroidJUnitRunner when looking for the test classes, does not uses the patched class loader that contains all dex files, but it only examines classes.dex. Therefore, it does not find any test classes to run. The workaround is to specify:
android.enableD8MainDexList=false
as this will make as keep all annotated classes in the main dex. Even though that is not the required for the legacy multidex to work, it will fix the issue for this particular case.
The issue is that the main dex list for the test APK does not contain the test classes. AndroidJUnitRunner when looking for the test classes, does not uses the patched class loader that contains all dex files, but it only examines classes.dex. Therefore, it does not find any test classes to run. The workaround is to specify:
android.enableD8MainDexList=false
as this will make as keep all annotated classes in the main dex. Even though that is not the required for the legacy multidex to work, it will fix the issue for this particular case.
ga...@google.com <ga...@google.com> #5
Stephan, it seems that the runner looks for the classes only in the dalvik.system.DexFile defined on the test APK. By default this will load classes only from the classes.dex. Code search link:
http://google3/third_party/android/android_test_support/runner/android_junit_runner/java/android/support/test/internal/runner/TestRequestBuilder.java?l=865&rcl=193292544
Can the runner look for classes also in the secondary dex files?
NB: If the "am instrument" command contains which test class to run, the test is run successfully.
Can the runner look for classes also in the secondary dex files?
NB: If the "am instrument" command contains which test class to run, the test is run successfully.
do...@gmail.com <do...@gmail.com> #6
Where should I put the "android.enableD8MainDexList=false" line?
Is it in Gradle file under "android" property?
If so, I was not able to add the line because it returned "Could not find method enableD8MainDexList() for arguments [false] on object of type com.android.build.gradle.AppExtension."
Is it in Gradle file under "android" property?
If so, I was not able to add the line because it returned "Could not find method enableD8MainDexList() for arguments [false] on object of type com.android.build.gradle.AppExtension."
ga...@google.com <ga...@google.com> #7
You should add it to gradle.properties file in project root directory.
do...@gmail.com <do...@gmail.com> #8
Thanks, but does not work.
I am in another post (https://issuetracker.google.com/issues/72758547#comment22 ) to continue looking for a fix. Thanks anyways.
I am in another post (
pe...@layer.com.c-02odbdyf.appstempdomain.goog <pe...@layer.com.c-02odbdyf.appstempdomain.goog> #9
Is there a planned fix for this in future tooling releases? I am getting a warning on 3.2.0-rc2 saying the "android.enableD8MainDexList" is deprecated:
The option 'android.enableD8MainDexList' is deprecated and should not be used anymore.
Use 'android.enableD8MainDexList=true' to remove this warning.
It will be removed in the future AGP versions. For more details, seehttps://d.android.com/r/studio-ui/d8-overview.html .
However, tests still do not work without that property. I've attached a simple sample project that was generated from the Android Studio template that exhibits this behavior.
The option 'android.enableD8MainDexList' is deprecated and should not be used anymore.
Use 'android.enableD8MainDexList=true' to remove this warning.
It will be removed in the future AGP versions. For more details, see
However, tests still do not work without that property. I've attached a simple sample project that was generated from the Android Studio template that exhibits this behavior.
[Deleted User] <[Deleted User]> #10
The workaround suggested in https://issuetracker.google.com/issues/78108767#comment4 fixed my projects as well. This should work as long as this issue is fixed before android.enableD8MainDexList is removed.
[Deleted User] <[Deleted User]> #11
This has become a critical blocking issue in Android Gradle Plugin 3.3 and is preventing us from upgrading. I can file a new issue if it is necessary to get this issue triaged and resolved.
In 3.3m, android.enableD8MainDexList=false no longer has any effect and many instrumentation tests no longer run on API 19 devices as a result of this build issue. Our test suite has many test cases but only a few are running. Android Studio's APK inspector reveals that the few tests that do run are all in classes.dex, the main dex file, and all of the missing tests are in classes[2,3,...].dex.
In 3.3m, android.enableD8MainDexList=false no longer has any effect and many instrumentation tests no longer run on API 19 devices as a result of this build issue. Our test suite has many test cases but only a few are running. Android Studio's APK inspector reveals that the few tests that do run are all in classes.dex, the main dex file, and all of the missing tests are in classes[2,3,...].dex.
[Deleted User] <[Deleted User]> #12
multiDexKeepProguard may be used to avoid this issue again. It would be better if D8 automatically packaged JUnit test classes into the main dex file, however, that would still limit us to a single dex file. Ideally, the test runner should support test cases in any dex file.
Fortunately all of our test source files are suffixed with the name "Test" so here's the workaround that we'll attempt to use for now:
build.gradle:
android {
defaultConfig {
multiDexKeepProguard file('multidex.pro ')
}
}
multidex.pro :
-keep class **Test { *; }
Fortunately all of our test source files are suffixed with the name "Test" so here's the workaround that we'll attempt to use for now:
build.gradle:
android {
defaultConfig {
multiDexKeepProguard file('
}
}
-keep class **Test { *; }
[Deleted User] <[Deleted User]> #13
Due to reflection used by AndroidJUnit4 you may also need to multiDexKeepProguard these classes:
androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
org.robolectric.RobolectricTestRunner
https://github.com/android/android-test/blob/master/ext/junit/java/androidx/test/ext/junit/runners/AndroidJUnit4.java#L57-L62
The tests occasionally fail without these additional rules whenever those classes end up in secondary dex files:
java.lang.RuntimeException: Delegate runner ‘androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner’ for AndroidJUnit4 could not be loaded.
androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
org.robolectric.RobolectricTestRunner
The tests occasionally fail without these additional rules whenever those classes end up in secondary dex files:
java.lang.RuntimeException: Delegate runner ‘androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner’ for AndroidJUnit4 could not be loaded.
sl...@google.com <sl...@google.com>
ae...@google.com <ae...@google.com> #14
This bug has not been updated in over a year. Please reopen if this is still an issue or requires addition inspection.
Description
Gradle version: 4.4
Android Plugin Version: 3.1.1
Module Compile Sdk Version: 27
Module Build Tools Version: 27.0.3
Android SDK Tools version: 26.1.1