Android:如何使用minifyEnabled生成签名的APK [英] Android: How to generate signed APK with minifyEnabled

查看:80
本文介绍了Android:如何使用minifyEnabled生成签名的APK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个android应用程序,我刚完成它的工作,并准备在PlayStore上发布它.但是,为了避免其他人直接对其进行反编译,我想添加安全防护层.

I have an android app, I just finished working on it and am ready to publish it on PlayStore. However, to avoid someone else from directly decompiling it, I wanted to add the proguard layer of security.

minifyEnabled设置为"true"后,我试图生成带签名的apk.但是,android studio开始显示一些错误,在某个时刻,计数超过了800个错误.我尝试在线搜索解决方案,然后才知道这个问题的主要原因可能是我添加到应用程序中的所有第三方库.

I tried to generate signed apk after setting minifyEnabled to 'true'. However, android studio started showing several errors, at one point the count went beyond 800 errors. I tried searching for a solution online and got to know the main cause of this problem might be all the third party libraries I had added to my application.

克服此类问题的最流行解决方案之一是在proguard-rules.txt文件中添加-dontwarn-keep属性.但是,即使我尝试遵循在线提供的所有解决方案后,问题仍然存在,我去尝试在youtube上找到某些内容,但没有任何用处.有人可以帮帮我吗.这是应用程序等级Gradel文件:

One of the most popular solution to overcome this type of problem was to add the -dontwarn or -keep attribute in the proguard-rules.txt file. But, the problem persisted even after I tried following all the solutions available online, I went tried to find something on youtube but got nothing of use. Can someone please help me. Here is the app level gradel file:

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控制台中发现的看似有用的信息:

Here is the seemingly helpful information I found in the gradle console:

    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

如果您要查看详细的警告,请此处

If you want to take a look at the detailed warnings then here.

有人可以帮助我解决这个问题吗,我知道像往常一样,解决方案太愚蠢了,例如简单的ReBuild,但是,请帮忙!

Can someone please help me tackle this problem, I know like always the solution will be too stupidly simple such as a simple ReBuild, but, please help!!

P.S.我已经尝试过完整的构建和重建.

P.S. I have already tried a full clean build and rebuild.

推荐答案

将它们添加到您的proguard-rules.txt:

Add these to your 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语句,直到解决所有问题为止.

This should reduce the number of errors you have. Add more keep statements until you resolve all the problems.

这篇关于Android:如何使用minifyEnabled生成签名的APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆