我们将一个工件编译为AAR并存储在Maven存储库中。 我们的工件可以添加为依赖
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
...
consumerProguardFiles 'proguard-rules.pro'
}
}
我们在 build.gradle 脚本中有以下设置。
# Common
-dontoptimize
-dontobfuscate
-dontpreverify
-optimizations !code/allocation/variable
-keep public class * {
public protected *;
}
# attributes
-keepattributes InnerClasses, Signature, *Annotation*, Exceptions
# java
-dontwarn javax.naming.**
-dontwarn java.lang.invoke**
-dontwarn java.nio.file.Files
-dontwarn java.nio.file.Path
-dontwarn java.nio.file.OpenOption
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# retrofit
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn rx.**
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
@retrofit.http.* <methods>;
}
# gson
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
# otto
-keepclassmembers class ** {
@com.squareup.otto.Subscribe public *;
@com.squareup.otto.Produce public *;
}
# google play services
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
# support
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
文件 proguard-rules.pro 包含以下规则
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
...
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
我们正在尝试将库作为依赖项添加到包含 build.gradle 以下设置的应用
buildTypes {
release {
minifyEnabled true
}
debug {
minifyEnabled true
}
}
和
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile ('com.ourcompany:sdk:2.1.16@aar') {
transitive = true
}
compile 'com.google.android.gms:play-services-location:+'
compile 'com.google.android.gms:play-services-maps:+'
}
和
:app:proguardDebug
Warning:retrofit.RxSupport$1: can't find superclass or interface rx.Observable$OnSubscribe
Warning:retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find superclass or interface org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning:retrofit.client.ApacheClient$GenericHttpRequest: can't find superclass or interface org.apache.http.client.methods.HttpRequestBase
Warning:retrofit.client.ApacheClient$TypedOutputEntity: can't find superclass or interface org.apache.http.entity.AbstractHttpEntity
Warning:okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:okio.Okio: can't find referenced class java.nio.file.Files
Warning:okio.Okio: can't find referenced class java.nio.file.Path
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning:okio.Okio: can't find referenced class java.nio.file.Path
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning:okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:okio.Okio: can't find referenced class java.nio.file.Path
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning:okio.Okio: can't find referenced class java.nio.file.Path
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption
Warning:okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:retrofit.RestMethodInfo$RxSupport: can't find referenced class rx.Observable
Warning:retrofit.RxSupport: can't find referenced class rx.Observable
Warning:retrofit.RxSupport: can't find referenced class rx.Observable$OnSubscribe
Warning:retrofit.RxSupport: can't find referenced class rx.Observable
Warning:retrofit.RxSupport: can't find referenced class rx.Subscriber
Warning:retrofit.RxSupport$1: can't find referenced class rx.subscriptions.Subscriptions
Warning:retrofit.RxSupport$1: can't find referenced class rx.Subscriber
Warning:retrofit.RxSupport$1: can't find referenced class rx.Observable$OnSubscribe
Warning:retrofit.RxSupport$1: can't find referenced class rx.subscriptions.Subscriptions
Warning:retrofit.RxSupport$1: can't find referenced class rx.Observable
Warning:retrofit.RxSupport$1: can't find referenced class rx.Subscriber
Warning:retrofit.RxSupport$1: can't find referenced class rx.Observable$OnSubscribe
Warning:retrofit.RxSupport$2: can't find referenced class rx.Subscriber
Warning:retrofit.android.AndroidApacheClient: can't find referenced class android.net.http.AndroidHttpClient
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPMethod
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.URLFetchServiceFactory
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.URLFetchService
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPHeader
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPResponse
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPResponse
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPHeader
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPResponse
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPMethod
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPResponse
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPHeader
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPMethod
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.URLFetchServiceFactory
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.URLFetchService
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPResponse
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.URLFetchService
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPMethod
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.URLFetchService
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPResponse
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.URLFetchService
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPResponse
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.URLFetchService
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPMethod
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPResponse
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPHeader
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPResponse
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPRequest
Warning:retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPHeader
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.params.BasicHttpParams
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.impl.client.DefaultHttpClient
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.StatusLine
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.Header
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.util.EntityUtils
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.StatusLine
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.Header
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpEntity
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.StatusLine
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.Header
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.util.EntityUtils
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.HttpClient
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.client.methods.HttpUriRequest
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.Header
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpResponse
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.StatusLine
Warning:retrofit.client.ApacheClient: can't find referenced class org.apache.http.HttpEntity
Warning:retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning:retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced method 'void setURI(java.net.URI)' in program class retrofit.client.ApacheClient$GenericEntityHttpRequest
Warning:retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced class org.apache.http.message.BasicHeader
Warning:retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced method 'void addHeader(org.apache.http.Header)' in program class retrofit.client.ApacheClient$GenericEntityHttpRequest
Warning:retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced method 'void setEntity(org.apache.http.HttpEntity)' in program class retrofit.client.ApacheClient$GenericEntityHttpRequest
Warning:retrofit.client.ApacheClient$GenericEntityHttpRequest: can't find referenced class org.apache.http.client.methods.HttpEntityEnclosingRequestBase
Warning:retrofit.client.ApacheClient$GenericHttpRequest: can't find referenced class org.apache.http.client.methods.HttpRequestBase
Warning:retrofit.client.ApacheClient$GenericHttpRequest: can't find referenced method 'void setURI(java.net.URI)' in program class retrofit.client.ApacheClient$GenericHttpRequest
Warning:retrofit.client.ApacheClient$GenericHttpRequest: can't find referenced class org.apache.http.message.BasicHeader
Warning:retrofit.client.ApacheClient$GenericHttpRequest: can't find referenced method 'void addHeader(org.apache.http.Header)' in program class retrofit.client.ApacheClient$GenericHttpRequest
Warning:retrofit.client.ApacheClient$GenericHttpRequest: can't find referenced class org.apache.http.client.methods.HttpRequestBase
Warning:retrofit.client.ApacheClient$TypedOutputEntity: can't find referenced class org.apache.http.entity.AbstractHttpEntity
Warning:retrofit.client.ApacheClient$TypedOutputEntity: can't find referenced method 'void setContentType(java.lang.String)' in program class retrofit.client.ApacheClient$TypedOutputEntity
Warning:retrofit.client.ApacheClient$TypedOutputEntity: can't find referenced class org.apache.http.entity.AbstractHttpEntity
Warning:there were 148 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning:there were 6 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Exception while processing task
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:473)
at proguard.ProGuard.initialize(ProGuard.java:233)
at proguard.ProGuard.execute(ProGuard.java:98)
at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074)
at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:139)
at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:115)
at com.android.builder.tasks.Job.runTask(Job.java:48)
at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227)
at java.lang.Thread.run(Thread.java:745)
:app:dexDebug
:app:validateDebugSigning
:app:packageDebug FAILED
Error:Execution failed for task ':app:packageDebug'.
> Unable to compute hash of D:\Workspace\AppAndroid\TestApp\app\build\intermediates\classes-proguard\debug\classes.jar
我们已经检查过我们的AAR工件中存在 proguard.txt 。 我们在两种环境中测试了这种集成:
Android Studio 1.5.1结束构建过程,结果如下: 第一次构建:
:app:packageDebug FAILED
Error:Execution failed for task ':app:packageDebug'.
> Unable to compute hash of D:\Workspace\AppAndroid\TestApp\app\build\intermediates\classes-proguard\debug\classes.jar
第二次构建,只是:
':app:proguardDebug', task ':app:dexDebug', task ':app:validateDebugSigning', task ':app:packageDebug', task ':app:zipalignDebug', task ':app:assembleDebug']
22:15:56.077 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :app:clean (Thread[main,5,main]) started.
22:15:56.077 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :app:clean
22:15:56.097 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Starting to execute task ':app:clean'
22:15:56.097 [DEBUG] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Determining if task ':app:clean' is up-to-date
22:15:56.098 [INFO] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Executing task ':app:clean' (up-to-date check took 0.001 secs) due to:
Task has not declared any outputs.
22:15:56.098 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':app:clean'.
22:15:56.099 [DEBUG] [org.gradle.api.internal.file.copy.DeleteActionImpl] Deleting D:\Workspace\AppAndroid\TestApp\app\build
22:15:56.933 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':app:clean'
22:15:56.934 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :app:clean FAILED
22:15:56.957 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :app:clean (Thread[main,5,main]) completed. Took 0.88 secs.
22:15:56.957 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 0.88 secs, idle: 0.001 secs
22:15:56.977 [LIFECYCLE] [org.gradle.BuildResultLogger]
22:15:56.977 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
22:15:56.977 [LIFECYCLE] [org.gradle.BuildResultLogger]
22:15:56.977 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 7.678 secs
22:15:57.003 [DEBUG] [org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonManager] Stopping 0 compiler daemon(s).
22:15:57.003 [INFO] [org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonManager] Stopped 0 compiler daemon(s).
22:15:57.005 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on buildscript class cache for settings file 'D:\Workspace\AppAndroid\TestApp\settings.gradle'
Android Studio 1.4.2
成功构建完成但在运行时我们遇到了由代码混淆引起的NullPointerException。
我们还尝试通过 gradlew构建项目:app:clean:app:assembleDebug 最后以
结束Int16Array
非常感谢您的帮助!提前谢谢!
答案 0 :(得分:0)
我们清除了所有缓存,从头开始重新创建项目,现在它工作正常。