Nach dem Update Android Studio auf die Version 2.2 und Android Gradle Plugin 2.2.0, ich habe eine Menge Warnungen, wenn ich Release apk bauen, wie zum Beispiel:Android Gradle Plugin 2.2.0 ProGuard begann innere Klassen zu halten
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(android.support.graphics.drawable.b) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is not an inner class.
Darüber hinaus hat meine Release-apk-Größe zugenommen. Also habe ich es mit dex2jar in jar umgewandelt und mit der vorherigen Version verglichen (die mit com.android.tools.build:gradle:2.1.3
erstellt wurde). Das erste, was mir auffiel, ist, dass neue Releases immer noch einige innere Klassen haben, was in früheren Versionen nicht der Fall war.
Dann füge ich meiner proguard config -keepattributes EnclosingMethod
hinzu, um Warnungen zu vermeiden, aber es erhöhte die Dateigröße viel mehr, indem es jetzt alle inneren Klassen behielt.
Also, kann ich apk ohne unnötige innere Klassen und -keepattributes EnclosingMethod
wie es in Android Gradle Plugin 2.1.3 war bauen?
ProGuard config:
# Retrolambda
-dontwarn java.lang.invoke.*
# okhttp
-dontwarn okio.**
-dontwarn okhttp3.**
-keep class okio.**
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
# appcompat
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
public <init>(android.content.Context);
}
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}
-keep public class * implements com.myapppackage.InterfaceClass
-keepattributes EnclosingMethod # was added to avoid 2.2.0 warnings
# Soft obfuscation
-keep public class !com.myapppackage.subpackage.** {
public protected *;
}
Modul build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
}
configurations.classpath.exclude group: 'com.android.tools.external.lombok'
}
App build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
Es gibt bisher zwei offizielle Tickets: https://code.google.com/p/android/issues/detail?id=222989 und https://code.google.com/p/android/issues/Detail? id = 222775 – darken