Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard with AAR library issue

I have a android library with one class and I want to make it an .aar library. When I set minifyEnabled to true, another android project cannot use the library (It is fine if minifyEnabled is set to false). I would like to ask what is the correct configuration of proguard with AAR library

HelloWorld.java

package com.example.hello;

import android.util.Log;

public class HelloWorld {
    public static void Hello(){
        Log.v("HelloWorld","Hello World!");
    }
}

build.grandle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 24
        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:24.0.0'
}

proguard-rules.pro

-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }

-keep class com.example.hello {public *;}
like image 384
Joshua Avatar asked Feb 06 '23 16:02

Joshua


1 Answers

Try changing the last line in proguard-rules to

-keep class com.example.hello.** {public *;}

As for Android Studio being able to decompile, you can't prevent that. If you want to protect your code, I suppose the best you can do is to obfuscate most of it, and then extend the desired functionality through interfaces that you do not obfuscate by adding the relevant proguard rules.

like image 185
Anuj Avatar answered Feb 16 '23 22:02

Anuj