I recently extracted some code from my Android application project into separate kotlin modules (the build.gradle files declare the "java-library"
and "kotlin"
plugins).
Now, the task ':app:minifyQaWithR8'
is failing with the message:
AGPBI: {"kind":"error","text":"Type com.myapp.ext.models.AckResponse is defined multiple times: E:\projects\myapp\ext\build\.transforms\35656f2face08400c6d53844207373f0\jetified-ext.jar:com/myapp/ext/models/AckResponse.class, E:\projects\myapp\app\build\tmp\kotlin-classes\qa\com\myapp\ext\models\AckResponse.class"}],"tool":"R8"}
I tried deleting each module's build
folder, then invaldate cache/restart, then assemble, and got a similar result with a different class. But both times, the locations were the same: one was in .transforms\35656f2face08400c6d53844207373f0\jetified-ext.jar
and one in app\build\tmp\kotlin-classes\qa
In a similar question
a member of the R8 team suggests that one of these locations represents a dependency, and one represents the app code, however, I cannot find any instance of the class in question in my application code, nor any indication that my module is being imported more than once.
It may be relevant that two of my modules do have a lot of the same classes, however I'm using the following statement to only include one of them in the build:
if(api_version == "ext2") {
implementation project(":ext2")
}else{
implementation project(":ext1")
}
The packages in these modules do not appear in the main application code.
What other steps can I take to track down the root of this issue?
As it turns out, there were in fact duplicate classes in my project. I was just unable to find them at first because the package name in the file did not correspond to the folder where the file was located.