Obfuscating AAR and its Dependencies

I am using gradle and Android Studio to create a library, let it call library A. Library module A in my project depends on another library module B. The reason why A and B are separate is that this project also has applications that depend on libraries A or B, but not both. To put it simply, I don't want these library modules to be separated in my codebase.

I want to deliver two AARs:

  • A.aar
  • B.aar

I want to confuse classes in A.aar and B.aar. Currently, if I enable obfuscation on build A releases, it works. But as soon as I enable obfuscation on B, the build process of A fails because the reference characters in B cannot be found.

Apparently the obfuscation of these two libraries is out of sync. I want it, I want it.

Or I would like to create a single obfuscated AAR that contains all the dependencies, but as I understand this is not possible with gradle / Andorid Studio.

EDIT: I am using proguard for obfuscation.

+3


source to share


1 answer


As per your question, it looks like library A has a dependency on library B. If the dependency is in a public API, you just need to make sure that the public B.aar APIs are not obfuscated.

If you have a dependency on the inner code, you can:

  • Make the class part of the public API OR
  • If its one class then duplicates in library A OR
  • If there are many classes, you can create a new module and make library A and B depend on the new module

If you want to push the A.aar library with B.aar as a dependency, you can publish it as a local or central maven repository. More information can be found here



If you choose to make this a local repository, you need to archive the repository and deliver it to your user. All dependencies will be handled accordingly

You can obfuscate classes in B.aar like this:

  • Build and publish library B
  • Publishing library A to the same repository and moving the resulting repository to find B.aar. Make a copy of the B.aar and Unzip aar copy, either by changing the .aar extension to .zip, or using the zip / unzip software, or use the 7-Zip software directly.
  • Copy classes.jar from package and paste it into libs / library folder A. Don't forget to rename jar file.
  • Include the following line in your build.gradle file

    dependencies {

    implementation filetree (the dir: 'libs', the include: [ '* .jar'])
    ...

    }

  • Remove classes.jar from original aar without unzipping it. 7-Zip software can do it

  • Obfuscate library. The ABaar classes will be obfuscated as well.

0


source







All Articles