Webサイトで提供されるデフォルトの構成では不可能なため、難読化して最適化するGuavaのProGuard構成を探します。
私はそれを私のapkをエクスポートするために得ることができないだけでなく、私は得続けます:
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.
Guava 17.0以降、これはProGuard構成で必要なものです。
-dontwarn javax.annotation.**
-dontwarn javax.inject.**
-dontwarn Sun.misc.Unsafe
そうでない場合、ビルドは次のような警告で失敗します:
Warning: com.google.common.base.Absent:
can't find referenced class javax.annotation.Nullable
(Guavaが注釈を使用しているためです Android runtime (Android.jarの一部ではありません)。この場合、警告をミュートするだけで問題ありません。)
Gradle as the build tool を使用している場合、上記のproguard-project.txt
とbuild.gradle
の次のコードは、Guavaを使用しているときに最適化され難読化されたAPKを生成します。
buildTypes {
release {
minifyEnabled true
proguardFile file('proguard-project.txt')
proguardFile getDefaultProguardFile('proguard-Android-optimize.txt')
}
}
またはできます jsr305.jarへの依存関係を含めるbuild.gradle
依存関係:
compile 'com.google.code.findbugs:jsr305:2.0.2'
... ProGuard構成では-dontwarn Sun.misc.Unsafe
のみですが、javax
にも-dontwarn
を使用することを推奨しました。
23.4-Androidから23.5-Androidにアップグレードするときに、次の行をプロガードルールファイルに追加する必要がありました。
-dontwarn afu.org.checkerframework.**
-dontwarn org.checkerframework.**
(新しいルールを追加する前の)アップデートから見たProguardの警告を以下に示します。
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
興味のある人のために、グアバのために私が現在持っている完全なルールセットは次のとおりです:
# 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.**
R8(Stephan Herhut)を構築したエンジニアの1人は、最新のGuava(25.0-Android
) このセッションはGoogle I/O 2018から :
-dontwarn afu.org.checkerframework.**
-dontwarn org.checkerframework.**
-dontwarn com.google.errorprone.**
-dontwarn Sun.misc.Unsafe
-dontwarn Java.lang.ClassValue
ビデオにはルールの簡単な説明も含まれています(最初の3つは静的分析アノテーションフレームワーク、最後の2つはAndroidで利用できないクラスです。これらはGuavaのランタイムチェックによって保護されています)。
セッション後にステファンと話しましたが、彼はこれらが将来のGuavaのドキュメントに含まれるか、将来のGuavaリリースのconsumerProguardFiles
に含まれると期待しています。期待しています!
Guava 19.0がリリースされました になったので、これらのルールを追加する必要があることがわかりました。
-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
Guava 20.0の場合、またはを追加する必要があります。
# Guava 20.0
-dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue
-dontwarn com.google.errorprone.annotations.concurrent.LazyInit
-dontwarn com.google.errorprone.annotations.ForOverride
このメッセージ は、次の回避策を提案します。
-dontwarn com.google.common.collect.MinMaxPriorityQueue
Proguardを変更してこれを不要にすることができると思いますが、所有者に確認していません。
グアバ20.0のトータルプロガードルール。現時点では、最新の guava 21 は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 { *; }
私のアプリで現在実際に機能しているものを、次のbuild.gradleと共有したいだけです。
「com.google.guava:guava:23.5-Android」をコンパイルします
以下は、Guavaを処理するためのproguard-project.txtにあります。基本的には、TimTronの回答と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.**
guavaのjarファイルはJavaコンパイラによって生成されたものであり、javacとは異なり、同じソースファイル内の参照クラスの定数プール内のプライベートインライン定数への追加の参照を保持しました。これは、proguard 4.7でのみ失敗します。参照を最適化せずに、プライベート定数の定義を最適化しているように見えます。将来のguava jarファイルにはそのような定数プール参照はありませんが、proguard 4.7には、標準のjavacによって生成されたjarファイルでは表示されないバグがある可能性があります。
これらのプロガードルールは私のために働きました:グアバ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