-
-
Notifications
You must be signed in to change notification settings - Fork 422
Android: exclude the main apk deps from the test apk #6073
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
Android: exclude the main apk deps from the test apk #6073
Conversation
|
Hi! I'm I would like to apply some automated changes to this pull request, but it looks like I don't have the necessary permissions to do so. To get this pull request into a mergeable state, please do one of the following two things:
|
Each |
thanks, I have it somewhat functional now. The problem is this as the steps in the packaging flow goes (just thinking out loud):
This extends beyond the jars, anything like android resources, native libs, meta info files. So it seems on a first glance that this transitiveCoursierProjects can be useful, if the androidTest compileClasspath has the base apk deps so that we can compile the test code , but not package it. Thanks for the tip, now that I have 2 complex examples working, I can make this less hacky! EDIT: Hm, I think after introducing the |
|
For the case of jet-chat I've even managed to exclude redundant things that are included in the gradle test apk Mill with this PR
Gradle
|
The problem is that I still have to compute the dependency exclusions, because the test deps might bring the same dependencies as in base module/apk and even worse , different versions. |
|
I've done some cleanup, avoiding duplication by overriding the resolvedRunMvnDeps. I've tried a few other methods but it starts to get a bit complicated to play with coursier + manage the kotlin friend paths, I ended up having even more duplication. I think with the latest commit, the implementation is fairly clean, but I'm open of course to further comments and suggestions to try . In terms of technical things and results, this PR allows mill to produce tiny test apks. Some result comparisons:
With the newest changes, there's a problem with androidtodo, so still not ready but will update accordingly EDIT: I've added a small workaround for now for androidtodo and also kept backwards compatibility if the new AndroidR8InstrumentedTests is not extended In addition to these size improvements, there's further improvement of setting up mill demonstrated here with a lot of duplicated dependencies not being needed in android test . Also the r8 error to warning mapping is no longer needed If one wishes to reproduce these results, this branch should be built locally and then start an emulator and run |
|
I need to figure out how to fix mima due to the added bom argument in a few methods, but apart from that , I'm open to review and comments |



This is related to #6064
Improvements
androidGeneratedMinifyKeepRulesis only available in R8 modulesFixes
Implementation details
Introduced a new
AndroidR8InstrumentedTestsModulewhich builds the test apk excluding the dependency tree of the base module (base apk) with 2 important tasks:androidR8CompileOnlyClasspathincorporates the whole base apk (but as a jar file)androidResolvedPackagableMvnDepsexcludes the dependencies of the base module viaandroidPackagableMvnDepsand is used in place ofresolvedRunMvnDeps.Extensions
To do the dependency resolution again by excluding the dependency tree, without breaking the examples, I needed a way to pass the bom to the
defaultResolver().classpath. Thus I extended the methods needed and fixed any MiMa issues with@unroll, although I haven't used it before, this is what I've found from looking around, so please let me know if this was a mistakeFurther work
Testing a few apps, there was a case where a test dependency was pulling
com.google.android.material:materialwhich in turn depends on appcompat android resources, so aapt2 linking was failing.I tried to see if
aapt2 link-Iargument would be of any help, but it seems I'm missing something, it appears only one artifact can be passed to it, tried several usage variations without luckGradle incorporates these resources without an issue, so it means we need to find a way to link the resources against the base module resources and at the same time avoid duplicate contents
I think it's a very niche use case, as typically runtime usage of these resources will be done in the base apk. For now, I added the appcompat explicitly in the androitTest mvnDeps so the linking goes through