Delete external library from obfuscated classes.jar (in Android Studio / Gradle)

I created an android library (using Android Studio) that imports an external .jar file (containing only interfaces) for proper assembly. But the final library file should not include this file, since the main application project will contain the .jar file, which already contains these interface classes contained in the external library. If I leave the file inside, the compiler will complain about "multiple dex files ...".

I can automatically remove the external .jar library from .aar using gradle as follows:

android.libraryVariants.all { variant ->
    variant.outputs.each { output ->
        def packageLib = output.getPackageLibrary()
        packageLib.exclude('libs/externalLibrary.jar')
    }
}

But if the library is messed up with ProGuard (minifyEnabled true), all class files from the external library are added to class.jar before it is packaged into a .aar file and therefore cannot be excluded in this way.

I can edit the classes.jar file and automatically delete the files using gradle as follows:

task makeRelease(type: Jar) {
    baseName='changedClasses'
    destinationDir=file('../../release/')

    from zipTree('build/intermediates/bundles/release/classes.jar')
    exclude "com/externallibrary/**"
}

which works when performing this task after the library build is complete. But I will need to complete this task after completing the proguard task, but before the files are packed into the final .aar, in order to automatically create and run the final application. And I have not yet found a way to do this so far ...

: .jar, .aar? , , , , , proguard, classes.jar?

+4
1

, , "" "", , , , , .

+1

All Articles