Infeasible
Status Update
Comments
ar...@squareup.com <ar...@squareup.com> #2
I tried using file-based dependency and in worked!
implementation fileTree(dir: '../library/build/outputs/aar/', include: ['library-debug.aar'])
Will definitely go with this solution over adding a flag to gradle.properties.
implementation fileTree(dir: '../library/build/outputs/aar/', include: ['library-debug.aar'])
Will definitely go with this solution over adding a flag to gradle.properties.
ga...@google.com <ga...@google.com> #3
After chatting with Gradle, there is no good API to figure out if artifact is coming from a flatDir repo that contains no dependency information.
However, we should really discourage use of flatDir. Dependencies should be added as file-based dependencies or AARs/JARs can be published to a Maven repo (local, within project, or external) with the actual POM/Gradle metadata. I filledhttps://issuetracker.google.com/143862922 to track this, and I'll close this issue.
However, we should really discourage use of flatDir. Dependencies should be added as file-based dependencies or AARs/JARs can be published to a Maven repo (local, within project, or external) with the actual POM/Gradle metadata. I filled
Description
Alternatively, developers can add AAR dependency as a file based one, and not use the flatDir. In the example above dependency can be added as:
dependencies {
implementation fileTree(dir: '../library/build/outputs/aar/', include: ['library-debug*.aar'])
}
Artem, can you migrate to file-based dependencies instead of flatDir?
Original issue:
Orignal comment:
I was able to isolate the issue and make a demo project to reproduce it. Tested on Android Studio 3.6.0-beta01 with AGP 3.6.0-beta01 - issue is still reproducible.
Steps to reproduce:
1. Download and import attached project
2. There will be two modules: app and library
app depends on 'library' and on 'androidx.lifecycle:lifecycle-common-java8:2.1.0'
library depends on 'androidx.lifecycle:lifecycle-common-java8:2.1.0'
3. Initial sync will fail because app depends directly on generated AAR. This file would be generated by :library:assemble task inside the /library/build/outputs/aar/
Run ./gradlew :library:assemble to assemble the 'library' module
4. After library is assembled try Gradle Sync button again. Now it should sync just fine.
5. Create an emulator that runs pre-java8 API, I was testing on Nexus 5 API 21 (required to enable desugaring)
6. Run app on the emulator. Upon launch app will crash.
7. In app/build.gradle comment out this:
implementation(name: 'library-debug', ext: 'aar')
And uncomment this line:
implementation project(":library")
8. Try running app again. With this module dependency app will run fine and activity will be displayed.
9. Revert step #7 to make dependency to be 'aar' again
10. In gradle.properties uncomment following line
android.enableDexingArtifactTransform.desugaring=false
11. Try running app. With this workaround app will run fine.
Explanation of the bug cause:
- Lifecycler-common-java8 contains an interface DefaultLifecycleObserver with default implementation on 6 methods
- 'library' has a class 'MyCustomObserver : DefaultLifecycleObserver' which overrides only 2 methods from DefaultLifecycleObserver
- 'app' instantiates 'MyCustomObserver' in its Application onCreate() and attempts to call method on it which is NOT overridden in 'MyCustomObserver'
Checking the bytecode for the case when AAR is used I found that 'MyCustomObserver' would only have two methods in it.
In the bytecode for the module dependency (steps #7-8) 'MyCustomObserver' has 6 methods, where 4 of those are synthetic and pointing to static methods generated by D8 in the 'DefaultLifecycleObserver$-CC' class
To sum things up, it looks like D8 cannot figure out where to get 'DefaultLifecycleObserver' while processing 'MyCustomObserver' - because AAR doesn't have any dependencies - and therefore it doesn't generate any synthetic methods for it.