Search code examples
androidexportaar

Create a hidden AAR library in Android


I created the aar library in Android studio. I see the code when I import it in another project. I don't want this. What should I do to prevent it from appearing? Do I need to edit it during compilation or in the code?


Solution

  • Follow the steps mentioned below

    1. Copy library.pro file to your library project from this location:
      ...\android-sdk\tools\proguard\examples
    2. Comment these lines when building from Android Studio, it should be probably kept/updated when building from the command line:
      -injars  in.jar
      -outjars out.jar
      -libraryjars  /lib/rt.jar
    3. Update your library project build.gradle file to use library.pro:

      release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'library.pro'
      }
    4. Sync and build the project and it should generate an obfuscated AAR file now.