我正在构建一个Android项目,其中包含一些使用Proguard的buildType。在建造期间,我看到了来自Proguard的大量警告。因为这些警告是为我正在使用的第三方类生成的,所以我试图在我的'proguard-rules.pro'文件中使用-dontwarn标志和-dontnote标志,这样我将来就不会看到错误输出。但是,我看到的问题是,即使我将这些标志添加到我的.pro文件并在build.gradle中指定.pro文件,我仍然会在构建项目时看到警告输出。
以下是build.gradle文件的相关部分:
buildTypes {
debug {
applicationIdSuffix ".debug"
}
unitTest {
applicationIdSuffix ".unittest"
minifyEnabled true
// proguardFiles getDefaultProguardFile("proguard-android.txt")
proguardFile('proguard-rules.pro')
}
automation {
applicationIdSuffix ".automation"
minifyEnabled true
// proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile('proguard-rules.pro')
}
internal {
applicationIdSuffix ".internal"
minifyEnabled true
// proguardFiles getDefaultProguardFile('proguard-android.txt')
proguardFile('proguard-rules.pro')
}
release {
minifyEnabled true
// proguardFiles getDefaultProguardFile("proguard-android.txt")
proguardFile("proguard-rules.pro")
}
}
这是我的proguard-rules.pro文件:
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/tools/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 *;
#}
# Disabling obfuscation is useful if you collect stack traces from production crashes
# (unless you are using a system that supports de-obfuscate the stack traces).
-dontobfuscate
# React Native
# Keep our interfaces so they can be used by other ProGuard rules.
# See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.proguard.annotations.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.proguard.annotations.DoNotStrip *;
}
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
void set*(***);
*** get*();
}
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }
-dontwarn com.facebook.react.**
# okhttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
# okio
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**
# stetho
-dontwarn com.facebook.stetho.**
##ADDED TO GET WARNINGS TO GO AWAY BUT NEEDS TO BE EVALED BEFORE RELEASE
-dontnote junit.runner.*
-dontnote junit.framework.*
-dontwarn org.hamcrest.**
-dontwarn android.support.test.**
请注意,proguard-rules.pro文件位于引用它的build.gradle文件旁边的project / app /目录中。
以下是gradle输出错误的片段:
Note: duplicate definition of library class [junit.runner.Version]
Note: duplicate definition of library class [junit.runner.BaseTestRunner]
Note: duplicate definition of library class [junit.framework.Protectable]
Note: duplicate definition of library class [junit.framework.Assert]
Note: duplicate definition of library class [junit.framework.TestSuite]
Note: duplicate definition of library class [junit.framework.Test]
Note: duplicate definition of library class [junit.framework.ComparisonFailure]
Note: duplicate definition of library class [junit.framework.TestFailure]
Note: duplicate definition of library class [junit.framework.TestCase]
Note: duplicate definition of library class [junit.framework.AssertionFailedError]
Note: duplicate definition of library class [junit.framework.TestListener]
Note: duplicate definition of library class [junit.framework.TestResult]
Reading library jar [/Users/dhodapp/Library/Android/sdk/platforms/android-23/optional/org.apache.http.legacy.jar]
Note: duplicate definition of library class [android.net.http.SslCertificate]
Note: duplicate definition of library class [android.net.http.SslError]
Note: duplicate definition of library class [android.net.http.SslCertificate$DName]
Note: duplicate definition of library class [org.apache.http.conn.scheme.SocketFactory]
Note: duplicate definition of library class [org.apache.http.conn.scheme.HostNameResolver]
Note: duplicate definition of library class [org.apache.http.conn.ConnectTimeoutException]
Note: duplicate definition of library class [org.apache.http.params.HttpParams]
Note: there were 19 duplicate class definitions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning: org.hamcrest.integration.EasyMock2Adapter: can't find superclass or interface org.easymock.IArgumentMatcher
Warning: org.hamcrest.integration.JMock1Adapter: can't find superclass or interface org.jmock.core.Constraint
Warning: library class android.test.AndroidTestCase extends or implements program class junit.framework.TestCase
Warning: library class android.test.AndroidTestRunner extends or implements program class junit.runner.BaseTestRunner
Warning: library class android.test.InstrumentationTestCase extends or implements program class junit.framework.TestCase
Warning: library class android.test.InstrumentationTestSuite extends or implements program class junit.framework.TestSuite
为什么在应用proguard-rules.pro文件时错误消息不会被压缩?