2016-06-28 80 views
1

我有一個類的Android庫,我想使它成爲一個.aar庫。當我將minifyEnabled設置爲true時,另一個android項目不能使用該庫(如果minifyEnabled設置爲false,那麼也可以)。我想問一下什麼是proguard的與AAR庫與AAR庫問題的Proguard

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 *;} 
+1

你可以嘗試將proguard-rules中的最後一行改爲「-keep class com.example.hello。** {public *;}' – basilisk

+0

@basilisk它似乎能夠工作,但它仍然可以反編譯通過android studio?另外,這是處理依賴庫的正確方法嗎? – Joshua

+0

@Joshua任何APK都可以反編譯。 Proguard不以任何方式保護APK或圖書館。它對不屬於API的類僅執行一點混淆處理。 – Robert

回答

4

嘗試改變proguard的規則最後一行

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

至於Android的工作室能反編譯,你不能阻止。如果你想保護你的代碼,我想你可以做的最好的辦法就是混淆大部分代碼,然後通過添加相關的proguard規則不會混淆的接口擴展所需的功能。

2

任何APK都可以反編譯。 Proguard的只是使反編譯代碼更難理解