Configuration ProGuard pour la goyave avec obfuscation et optimisation
cherche une configuration ProGuard pour Guava qui obfusera et optimisera, comme celle fournie par défaut sur le site web ne le fait pas.
non seulement que je ne peux pas l'obtenir pour exporter mon apk, je continue à obtenir:
Warning: com.google.common.collect.MinMaxPriorityQueue:
can't find referenced field 'int UNSET_EXPECTED_SIZE' in class
com.google.common.collect.MinMaxPriorityQueue$Builder
You should check if you need to specify additional program jars.
10 réponses
à partir de Guava 17.0 , c'est ce dont j'avais besoin dans la config ProGuard:
-dontwarn javax.annotation.**
-dontwarn javax.inject.**
-dontwarn sun.misc.Unsafe
sinon build échoue avec des avertissements comme:
Warning: com.google.common.base.Absent:
can't find referenced class javax.annotation.Nullable
(C'est parce que Guava utilise des annotations qui ne font pas partie de L'exécution Android (android.pot.) Dans ce cas, c'est bien de couper les Avertissements.)
si vous utilisez Gradle comme outil de construction , le ci-dessus proguard-project.txt
et le suivant dans build.gradle
produit une APK optimisée et obscurcie tout en utilisant la goyave.
buildTypes {
release {
minifyEnabled true
proguardFile file('proguard-project.txt')
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
}
}
alternativement vous pouvez inclure la dépendance à jsr305.jar dans build.gradle
dépendances:
compile 'com.google.code.findbugs:jsr305:2.0.2'
...avec seulement -dontwarn sun.misc.Unsafe
dans la config ProGuard, mais j'ai préféré utiliser -dontwarn
aussi pour le javax
stuff.
j'ai dû ajouter les lignes suivantes à mon fichier de règles proguard lors de la mise à niveau de 23.4-android à 23.5-android:
-dontwarn afu.org.checkerframework.**
-dontwarn org.checkerframework.**
les Avertissements proguard que j'ai vu de la mise à jour (avant d'ajouter de nouvelles règles) sont énumérés ci-dessous pour référence:
Warning: afu.org.checkerframework.checker.experimental.tainting_qual.qual.Untainted: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.experimental.tainting_qual.qual.Untainted: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.experimental.tainting_qual.qual.Untainted: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.experimental.tainting_qual.qual.Untainted: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.fenum.qual.FenumBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.fenum.qual.FenumBottom: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.fenum.qual.FenumBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.formatter.qual.FormatBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.formatter.qual.FormatBottom: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.formatter.qual.FormatBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.guieffect.qual.AlwaysSafe: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.guieffect.qual.AlwaysSafe: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.guieffect.qual.AlwaysSafe: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.i18n.qual.Localized: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.i18n.qual.Localized: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.i18n.qual.Localized: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.i18n.qual.Localized: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.i18n.qual.Localized: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.i18n.qual.Localized: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.i18n.qual.Localized: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.i18n.qual.Localized: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.i18nformatter.qual.I18nFormatBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.i18nformatter.qual.I18nFormatBottom: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.i18nformatter.qual.I18nFormatBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.initialization.qual.FBCBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.initialization.qual.FBCBottom: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.initialization.qual.FBCBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.interning.qual.Interned: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedPrimitiveType
Warning: afu.org.checkerframework.checker.interning.qual.Interned: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror
Warning: afu.org.checkerframework.checker.interning.qual.Interned: can't find referenced class afu.com.sun.source.tree.LiteralTree
Warning: afu.org.checkerframework.checker.interning.qual.Interned: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedPrimitiveType
Warning: afu.org.checkerframework.checker.nullness.qual.KeyForBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.KeyForBottom: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.nullness.qual.KeyForBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedPrimitiveType
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedNoType
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class javax.lang.model.type.TypeKind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedPrimitiveType
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedNoType
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.Nullable: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.nullness.qual.Nullable: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.nullness.qual.Nullable: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.oigj.qual.Mutable: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.oigj.qual.Mutable: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.oigj.qual.Mutable: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.oigj.qual.Mutable: can't find referenced class javax.lang.model.type.TypeKind
Warning: afu.org.checkerframework.checker.oigj.qual.OIGJMutabilityBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.oigj.qual.OIGJMutabilityBottom: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.oigj.qual.OIGJMutabilityBottom: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedPrimitiveType
Warning: afu.org.checkerframework.checker.oigj.qual.OIGJMutabilityBottom: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror
Warning: afu.org.checkerframework.checker.oigj.qual.OIGJMutabilityBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.oigj.qual.OIGJMutabilityBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.oigj.qual.OIGJMutabilityBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.oigj.qual.OIGJMutabilityBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.oigj.qual.OIGJMutabilityBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.oigj.qual.OIGJMutabilityBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.oigj.qual.OIGJMutabilityBottom: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror$AnnotatedPrimitiveType
Warning: afu.org.checkerframework.checker.regex.classic.qual.RegexBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.regex.classic.qual.RegexBottom: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.regex.classic.qual.RegexBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.signature.qual.SignatureBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.signature.qual.SignatureBottom: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.signature.qual.SignatureBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.tainting.classic.qual.Untainted: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.tainting.classic.qual.Untainted: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.checker.tainting.classic.qual.Untainted: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.tainting.classic.qual.Untainted: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.checker.units.qual.UnitsRelations: can't find referenced class afu.org.checkerframework.checker.units.UnitsRelations
Warning: afu.org.checkerframework.common.aliasing.qual.MaybeAliased: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.common.aliasing.qual.MaybeAliased: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.common.aliasing.qual.MaybeAliased: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.common.reflection.qual.ClassValBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.common.reflection.qual.ClassValBottom: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.common.reflection.qual.ClassValBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.common.reflection.qual.MethodValBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.common.reflection.qual.MethodValBottom: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.common.reflection.qual.MethodValBottom: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.common.value.qual.BottomVal: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.common.value.qual.BottomVal: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.common.value.qual.BottomVal: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.framework.qual.ImplicitFor: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.framework.qual.ImplicitFor: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.framework.qual.ImplicitFor: can't find referenced class afu.com.sun.source.tree.Tree$Kind
Warning: afu.org.checkerframework.framework.qual.ImplicitFor: can't find referenced class afu.com.sun.source.tree.Tree
Warning: afu.org.checkerframework.framework.qual.ImplicitFor: can't find referenced class javax.lang.model.type.TypeKind
Warning: afu.org.checkerframework.framework.qual.ImplicitFor: can't find referenced class afu.org.checkerframework.framework.type.AnnotatedTypeMirror
Warning: org.checkerframework.checker.interning.qual.Interned: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.interning.qual.Interned: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.interning.qual.Interned: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.interning.qual.Interned: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.interning.qual.Interned: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.interning.qual.Interned: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.interning.qual.Interned: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.interning.qual.Interned: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.lock.qual.GuardedBy: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.lock.qual.GuardedBy: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.lock.qual.GuardedBy: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.lock.qual.GuardedBy: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.lock.qual.GuardedBy: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.lock.qual.GuardedBy: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.lock.qual.GuardedBy: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.lock.qual.GuardedBy: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.nullness.qual.NonNull: can't find referenced class javax.lang.model.type.TypeKind
Warning: org.checkerframework.checker.units.qual.UnitsRelations: can't find referenced class org.checkerframework.checker.units.UnitsRelations
Warning: org.checkerframework.framework.qual.ImplicitFor: can't find referenced class javax.lang.model.type.TypeKind
pour les intéressés, le règlement complet que j'ai actuellement pour guava est:
# Guava (official)
## Not yet defined: follow https://github.com/google/guava/issues/2117
# Guava (unofficial)
## https://github.com/google/guava/issues/2926#issuecomment-325455128
## https://stackoverflow.com/questions/9120338/proguard-configuration-for-guava-with-obfuscation-and-optimization
-dontwarn com.google.common.base.**
-dontwarn com.google.errorprone.annotations.**
-dontwarn com.google.j2objc.annotations.**
-dontwarn java.lang.ClassValue
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# Added for guava 23.5-android
-dontwarn afu.org.checkerframework.**
-dontwarn org.checkerframework.**
maintenant que Guava 19.0 est libéré , j'ai trouvé que je devais ajouter ces règles.
-keep class com.google.j2objc.annotations.** { *; }
-dontwarn com.google.j2objc.annotations.**
-keep class java.lang.ClassValue { *; }
-dontwarn java.lang.ClassValue
-keep class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement { *; }
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
L'un des ingénieurs qui a construit R8 (Stephan Herhut) a énuméré les règles suivantes pour la dernière Goyave ( 25.0-android
) dans cette session de Google I / O 2018 :
-dontwarn afu.org.checkerframework.**
-dontwarn org.checkerframework.**
-dontwarn com.google.errorprone.**
-dontwarn sun.misc.Unsafe
-dontwarn java.lang.ClassValue
la vidéo comprend également une brève explication des règles (les 3 premières sont des cadres d'annotation d'analyse statique, les 2 dernières sont des classes non disponibles sur Android qui sont protégés par des contrôles d'exécution en Goyave).
J'ai parlé avec Stephan après le il a déclaré que ces derniers seront, espérons-le, inclus dans la documentation de la goyave à l'avenir ou, mieux encore, dans les consumerProguardFiles
des futures publications de la goyave. Ici en espérant!
pour la goyave 20.0 vous devez ajouter aussi :
# Guava 20.0
-dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue
-dontwarn com.google.errorprone.annotations.concurrent.LazyInit
-dontwarn com.google.errorprone.annotations.ForOverride
ce message suggère la solution suivante:
-dontwarn com.google.common.collect.MinMaxPriorityQueue
j'aimerais penser que Proguard pourrait être changé pour rendre cela inutile, mais nous n'avons pas vérifié avec ses propriétaires.
Total proguard règle de goyave 20.0. Pour l'instant, le dernier guava 21 ne supporte pas android.
-dontwarn com.google.common.base.**
-keep class com.google.common.base.** {*;}
-dontwarn com.google.errorprone.annotations.**
-keep class com.google.errorprone.annotations.** {*;}
-dontwarn com.google.j2objc.annotations.**
-keep class com.google.j2objc.annotations.** { *; }
-dontwarn java.lang.ClassValue
-keep class java.lang.ClassValue { *; }
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-keep class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement { *; }
les fichiers jar de guava ont été produits par un compilateur java qui (contrairement à javac) gardait des références supplémentaires aux constantes inlined privées dans le pool constant de classes de référencement dans le même fichier source, ce qui échoue seulement avec proguard 4.7, qui semble optimiser les définitions des constantes privées, sans optimiser les références. Les futurs fichiers Gava jar n'auront pas de telles références de pool constantes, mais il y a probablement un bug dans proguard 4.7 qui ne se manifeste pas avec les fichiers jar produit par standard javac.
je veux juste partager ce qui fonctionne actuellement pour mon application avec ce qui suit dans build.gradle:
compiler", com.Google.goyave:goyave: 23.5-android '
La suite est dans proguard-projet.txt pour s'occuper de la goyave. Il s'agit essentiellement de la combinaison de la réponse de TimTron et du Conseil de develper_7:
-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue
-dontwarn com.google.common.util.concurrent.FuturesGetChecked**
-dontwarn javax.lang.model.element.Modifier
-dontwarn afu.org.checkerframework.**
-dontwarn org.checkerframework.**
ces règles proguard travaillé pour moi: guava 23.3-android
-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue
-dontwarn com.google.common.util.concurrent.FuturesGetChecked**
-dontwarn javax.lang.model.element.Modifier