如何将proguad与库项目Android Studio一起使用

时间:2022-08-31 22:50:13

I got proguard to work correctly, but the problem is that I have a library project inside my project, so when proguard does its magic the library doesn't recognize the classes (vice-versa).

我得到了proguard正常工作,但问题是我的项目中有一个库项目,所以当proguard发挥其魔力时,库不能识别类(反之亦然)。

How to use proguard correctly when I have a library project? how to keep both projects link to each others' classes correctly? Any help is much appreiciated guys.

我有一个图书馆项目时如何正确使用proguard?如何让两个项目正确地链接到彼此的类?任何帮助都是很有帮助的人。

Here's my App's build file:

这是我的App的构建文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {



    applicationId "com.ex.test"
    minSdkVersion 14
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE-FIREBASE.txt'
    exclude 'META-INF/NOTICE'
}

}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.2'
    compile 'com.android.support:cardview-v7:21.0.2'
    compile 'com.android.support:recyclerview-v7:21.0.2'
    compile 'com.mcxiaoke.volley:library:1.0.+'
    compile 'com.android.support:support-annotations:21.0.2'
    compile 'com.android.support:support-v4:21.0.2'
    compile project(':chatinglibrary')
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.koushikdutta.ion:ion:2.+'
    compile 'com.github.amlcurran.showcaseview:library:5.0.0'
    compile 'com.afollestad:material-dialogs:0.7.6.0'
}

And here's my lib's build file:

这是我的lib的构建文件:

apply plugin: 'com.android.library'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.firebase:firebase-client-android:2.0.3+'
}

1 个解决方案

#1


0  

you must keep your each libs from proguard like this

你必须保持你的每个libs像proguard这样

   -keep class android.support.v4.app.** { *; }
   -keep interface android.support.v4.app.** { *; }

some libs have special ruls to keep from proguad

一些libs有特殊的ruls来保持proguad

see example

and see this answer

并看到这个答案

#1


0  

you must keep your each libs from proguard like this

你必须保持你的每个libs像proguard这样

   -keep class android.support.v4.app.** { *; }
   -keep interface android.support.v4.app.** { *; }

some libs have special ruls to keep from proguad

一些libs有特殊的ruls来保持proguad

see example

and see this answer

并看到这个答案