Proguard 与 AAR 库问题
Proguard with AAR library issue
我有一个 android 库和一个 class,我想把它变成一个 .aar 库。当我设置 minifyEnabled
为 true 时,另一个 android 项目无法使用该库(如果 minifyEnabled
设置为 false 就可以了)。我想问一下proguard和AAR库的正确配置是什么
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 *;}
任何APK都可以反编译。 Proguard只是让反编译后的代码更难理解
尝试将 proguard-rules 中的最后一行更改为
-keep class com.example.hello.** {public *;}
至于AndroidStudio可以反编译,你无法阻止。如果你想保护你的代码,我想你能做的最好的事情就是混淆大部分代码,然后通过添加相关的 proguard 规则不混淆的接口扩展所需的功能。
我有一个 android 库和一个 class,我想把它变成一个 .aar 库。当我设置 minifyEnabled
为 true 时,另一个 android 项目无法使用该库(如果 minifyEnabled
设置为 false 就可以了)。我想问一下proguard和AAR库的正确配置是什么
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 *;}
任何APK都可以反编译。 Proguard只是让反编译后的代码更难理解
尝试将 proguard-rules 中的最后一行更改为
-keep class com.example.hello.** {public *;}
至于AndroidStudio可以反编译,你无法阻止。如果你想保护你的代码,我想你能做的最好的事情就是混淆大部分代码,然后通过添加相关的 proguard 规则不混淆的接口扩展所需的功能。