如何制作安全签名的apk难以逆向工程?

时间:2017-03-09 06:46:13

标签: android gradle apk

我在我的项目中使用multidex enabled。当我使用 minifyEnabled true 时出现此错误

FAILURE: Build failed with an exception.
  • 出了什么问题: 任务执行失败':app:transformClassesAndResourcesWithProguardForRelease'。
      

    作业失败,请参阅日志了解详情

这是我的gradle文件:

        apply plugin: 'com.android.application'

    android {
        compileSdkVersion 25
        buildToolsVersion "25.0.2"
        useLibrary 'org.apache.http.legacy'
        defaultConfig {
            applicationId "com.app.example"
            minSdkVersion 15
            targetSdkVersion 25
            versionCode 9
            versionName "1.8"
            multiDexEnabled true


        }
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        dexOptions {
            preDexLibraries = false
        }
        productFlavors {
        }

        lintOptions {
            checkReleaseBuilds false
        }
    }


    repositories {

        maven {
            url 'https://dl.bintray.com/ayz4sci/maven/'
        }

    }

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:design:25.1.1'
        compile 'com.android.support:appcompat-v7:25.1.1'
        compile 'com.android.support:multidex:1.0.1'


    }
  

更新(按照 kevin 的建议查看日志后)

  • 我添加此行dontwarn

    -dontwarn com.squareup.picasso.**
    -dontwarn com.vungle.**
    -dontwarn twitter4j.**
    

及其工作,但我使用的是d-max / spots-dialog,并且在签名后没有显示apk

它也使用-keep class解决了。

1 个答案:

答案 0 :(得分:3)

如果使用minify,默认情况下启用代码混淆..

它还会删除未使用的方法。我有来自Google支持库的20k +方法,当我使用minify时,它被减少到大约... 5k左右..所以你必须修改你的应用程序的proguard-rules告诉代码混淆器不要删除你的类。

例如:

-keep class com.app.example.** {*;}
-dontwarn com.app.example.**

# Ensure annotations are kept for runtime use.
-keepattributes *Annotation*
# Don't remove any GreenRobot classes
-keepnames class org.greenrobot.** {*;}
# Don't remove any methods that have the @Subscribe annotation
-keepclassmembers class ** {
    @de.greenrobot.event.Subscribe <methods>;
}

您可以通过阅读错误日志找到所需的类,它通常会在“需要类x但未找到”的行中说出一些内容