2017-01-17 1 views
3

После применения proguard к моему коду это все еще довольно читаемо. Классы и пакеты не переименовываются. Переменные класса, то есть все, что было переименовано. Android Studio 2.2.3. сборки: Gradle: 2.2.3ProGuard в Android Studio обеспечивает очень слабую обфускацию.

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

+0

@Aenadon Да. Я пробовал proguard-android-optimize.txt. Мой apk стал на 30 килобайт меньше, но никакой видимой разницы. – despecher

ответ

2

Я вижу, что вы используете библиотеку AppIntro. Эта библиотека имеет проблему, в которой правила proguard библиотеки сохраняют все классы в проекте. Правила proguard библиотеки объединены с локальными, поэтому в финальной сборке все классы сохраняются и не будут запутываться.

Эта проблема исправлена ​​в 4.2, но эта версия не была выпущена на Maven Central. Между тем, вы должны клонировать библиотеку локально и импортировать ее вручную в gradle.

Шаги:

  1. Скачать или клонировать библиотеку локально через Github (есть зеленая Clone or Download кнопка)
  2. Создать новую папку libs в корневом каталоге вашего проекта
  3. Создать новый папка AppIntro в папке libs
  4. Поместите содержимое library -файла клонированного проекта в AppIntro папку мы создали на шаге 3
  5. Добавить include ':libs:AppIntro' в свой settings.gradle
  6. Заменить compile 'com.github.paolorotolo:appintro:4.1.0' с compile project(':libs:AppIntro') в вашем build.gradle

Теперь ProGuard должен нормально работать!

+0

Благодарим вас за ответ. Да, действительно, после удаления AppIntro библиотека proguard начала работать исправно. – despecher

+0

У меня такая же проблема сейчас, и у меня нет этой библиотеки AppIntro в моем проекте. Как правильно диагностировать и находить плохое яблоко, которое заставляет ProGuard исключать все классы? – Segabond

Смежные вопросы