Android: 如何使用 minifyEnabled 生成签名的 APK
Android: How to generate signed APK with minifyEnabled
我有一个 android 应用程序,我刚刚完成它的开发并准备在 PlayStore 上发布它。但是,为了避免别人直接反编译,我想加proguard安全层。
我试图在将 minifyEnabled
设置为 'true' 后生成签名的 apk。但是,android studio 开始显示多个错误,一度超过 800 个错误。我尝试在线搜索解决方案,并了解到导致此问题的主要原因可能是我添加到我的应用程序中的所有第三方库。
克服此类问题的最流行的解决方案之一是在 proguard-rules.txt
文件中添加 -dontwarn
或 -keep
属性。但是,即使在我尝试遵循所有可用的在线解决方案之后,问题仍然存在,我试图在 youtube 上找到一些东西,但没有任何用处。有人可以帮帮我吗。这是应用程序级别的 gradel 文件:
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。
有人能帮我解决这个问题吗,我知道解决方案总是太简单了,比如简单的重建,但是,请帮忙!!
P.S。我已经尝试过完全干净的构建和重建。
将这些添加到你的proguard-rules.txt:
-keep class java.awt.event.** { *; }
-keep class org.apache.** { *; }
-keep class org.gradle.** { *; }
-keep class groovy.lang.** { *; }
-keep class javax.swing.** { *; }
这应该可以减少您的错误数量。添加更多 keep 语句,直到您解决所有问题。
我有一个 android 应用程序,我刚刚完成它的开发并准备在 PlayStore 上发布它。但是,为了避免别人直接反编译,我想加proguard安全层。
我试图在将 minifyEnabled
设置为 'true' 后生成签名的 apk。但是,android studio 开始显示多个错误,一度超过 800 个错误。我尝试在线搜索解决方案,并了解到导致此问题的主要原因可能是我添加到我的应用程序中的所有第三方库。
克服此类问题的最流行的解决方案之一是在 proguard-rules.txt
文件中添加 -dontwarn
或 -keep
属性。但是,即使在我尝试遵循所有可用的在线解决方案之后,问题仍然存在,我试图在 youtube 上找到一些东西,但没有任何用处。有人可以帮帮我吗。这是应用程序级别的 gradel 文件:
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。
有人能帮我解决这个问题吗,我知道解决方案总是太简单了,比如简单的重建,但是,请帮忙!!
P.S。我已经尝试过完全干净的构建和重建。
将这些添加到你的proguard-rules.txt:
-keep class java.awt.event.** { *; }
-keep class org.apache.** { *; }
-keep class org.gradle.** { *; }
-keep class groovy.lang.** { *; }
-keep class javax.swing.** { *; }
这应该可以减少您的错误数量。添加更多 keep 语句,直到您解决所有问题。