我有一個Android應用程序,我剛完成了它的工作,並準備在PlayStore上發佈它。但是,爲了避免別人直接反編譯它,我想添加proguard安全層。Android:如何使用minifyEnabled生成簽名APK
我試圖在將minifyEnabled
設置爲'true'後生成已簽名的apk。然而,android studio開始顯示出幾個錯誤,一次計數超過了800個錯誤。我試着在網上搜索一個解決方案,並且知道這個問題的主要原因可能是我添加到我的應用程序中的所有第三方庫。
克服此類問題的最常見解決方案之一是在proguard-rules.txt
文件中添加-dontwarn
或-keep
屬性。但是,即使我嘗試瞭解所有可用的在線解決方案後,問題仍然存在,我試圖在YouTube上找到某些東西,但沒有任何用處。有人可以幫幫我嗎。這裏是應用級格拉德爾文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.example.android.jsontutorial"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
//compile 'com.google.firebase:firebase-core:10.2.4'
compile 'com.google.firebase:firebase-ads:10.0.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.gms.google-services'
這裏是proguard-rules.txt
文件:
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\Priyansh\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class tvName to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-dontwarn com.squareup.picasso.**
-dontwarn com.android.support.**
-dontwarn com.android.support.**
-dontwarn com.android.support.**
-dontwarn com.android.volley.**
-dontwarn com.android.support.**
-dontwarn com.android.support.**
-dontwarn com.google.firebase.**
這裏是看似有用的信息我在gradle這個控制檯發現:
Warning: there were 1341 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 83 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Warning: Exception while processing task java.io.IOException: Please correct the above warnings first.
:app:transformClassesAndResourcesWithProguardForRelease FAILED
如果您想看看詳細的警告,然後here。
有人可以幫助我解決這個問題,我知道像總是解決方案將太簡單,如簡單的ReBuild,但請幫助!
P.S.我已經嘗試了一個完整的清理構建和重建。
謝謝你的解決方案,它的工作。我還必須添加以下幾行:'--ignorewarnings -keep class * { public private *; }' –