Android Studio中的ProGuard提供了非常弱的混淆。

时间:2017-01-17 06:28:52

标签: android proguard android-proguard

将proguard应用到我的代码之后,它仍然非常易读。不重命名类和包。类变量,即所有重命名的变量。 Android Studio 2.2.3。 建立:gradle这个:2.2.3

的build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "25.0.1"

defaultConfig {
    applicationId "com.mypackagename"
    minSdkVersion 19
    targetSdkVersion 24
    versionCode 3
    versionName "1.0"
    vectorDrawables.useSupportLibrary = true
}

 buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

dexOptions {
    dexInProcess = true
}

   lintOptions {
    abortOnError true
    checkReleaseBuilds true
}
}

ext {
supportLibVersion = '25.0.1'
playServisesVersion = '10.0.0'
}

repositories {
maven { url "https://jitpack.io" }
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.wdullaer:materialdatetimepicker:3.0.0'
compile 'com.aurelhubert:ahbottomnavigation:2.0.1'
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.google.android.gms:play-services-analytics:${playServisesVersion}"
compile "com.google.android.gms:play-services-drive:${playServisesVersion}"
compile "com.google.firebase:firebase-ads:${playServisesVersion}"
compile "com.google.firebase:firebase-core:${playServisesVersion}"
compile 'com.anjlab.android.iab.v3:library:1.0.34'
compile 'com.github.paolorotolo:appintro:4.1.0'
compile 'net.danlew:android.joda:2.9.5.1'
}
apply plugin: 'com.google.gms.google-services'

proguard-rules.pro

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:.....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 name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}
-dontwarn com.github.mikephil.charting.**
-keep class android.support.v7.** { *; }
-keep class android.support.graphics.drawable.** { *; }

查看我的发布apk enter image description here

1 个答案:

答案 0 :(得分:3)

我可以看到您正在使用库AppIntro。该库存在一个问题,即库的proguard规则保留了项目中的所有类。库的proguard规则与本地规则合并,因此在最终构建中,所有类都被保留,不会被混淆。

此问题已在4.2中修复,但此版本尚未在Maven Central上发布。同时,您必须在本地克隆库并在gradle中手动导入它。

<强>步骤:

  1. 通过Github在本地下载或克隆库(有一个绿色的Clone or Download按钮)
  2. 在项目的根目录中创建新文件夹libs
  3. AppIntro文件夹
  4. 中创建新文件夹libs
  5. 将克隆项目的library - 文件夹的内容放在我们在步骤3中创建的AppIntro文件夹中
  6. include ':libs:AppIntro'添加到您的settings.gradle
  7. compile 'com.github.paolorotolo:appintro:4.1.0'替换为compile project(':libs:AppIntro')
  8. 中的build.gradle

    现在,proguard应该正常工作!