0

I want to hide real code from aar file. My library's Gradle file looks like this.

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:recyclerview-v7:25.3.1'
}

And I am getting following exception while running this app.

Warning:Exception while processing task java.io.FileNotFoundException: E:\MyProjects\TestApp\testLibrary\build\intermediates\proguard-rules\release\aapt_rules.txt (The system cannot find the path specified)
Error:Execution failed for task ':testLibrary:transformClassesAndResourcesWithProguardForRelease'.
> Job failed, see logs for details

If I changed the minifyEnabled true to minifyEnabled false then this app runs without fail but I can see the Java files from generated arr file.

So I want to hide Java code.

halfer
  • 19,824
  • 17
  • 99
  • 186
Gunaseelan
  • 14,415
  • 11
  • 80
  • 128

1 Answers1

0

for a library you should not supply proguard-rules.pro but some proguard-consumer-rules.pro... which contains the configuration rules, which are being applied, when the library is compiled into an APK package (contrary to the usual behavior, when the library is being build).

// These rules will be applied when a consumer of this library sets 'minifyEnabled true'.
consumerProguardFiles 'proguard-consumer-rules.pro'

the library is not directly being obfuscated like that, but only later on - without having every single consumer of the library having to define their own ProGuard rules configuration. see the question I've linked above, one of it's answers provides a basic configuration, in order to keep the public methods (so that one can still use the library, once it had been merely obfuscated). and also see the Android Testing template for: module-android-library.

I would assume, that this AAPT error stems from supplying an empty ProGuard configuration file.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216