首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AAR依赖关系被混淆,尽管可用的proguard.txt禁止混淆。

AAR依赖关系被混淆,尽管可用的proguard.txt禁止混淆。
EN

Stack Overflow用户
提问于 2016-02-18 19:10:08
回答 1查看 768关注 0票数 2

我们将一个工件编译为AAR并存储在Maven存储库中。我们的工件可以作为依赖项添加。

代码语言:javascript
运行
复制
compile ('com.ourcompany:sdk:2.1.16@aar') {
    transitive = true
}

我们在build.gradle脚本中有以下设置。

代码语言:javascript
运行
复制
android {
   compileSdkVersion 23
   buildToolsVersion "23.0.2"

   defaultConfig {
       ...
       consumerProguardFiles 'proguard-rules.pro'
   }
}

File包含以下规则

代码语言:javascript
运行
复制
# 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.** { *; }

我们试图将库作为依赖项添加到包含在build.gradle中的应用程序中

代码语言:javascript
运行
复制
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
       ...
       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

代码语言:javascript
运行
复制
buildTypes {
    release {
        minifyEnabled true
    }

    debug {
        minifyEnabled true
    }
}

代码语言:javascript
运行
复制
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:+'
}

我们已经检查了proguard.txt是否存在于我们的AAR工件中。我们已经在两个环境中测试了这种集成:

Android 1.5.1以以下结果结束构建过程:第一个构建:

代码语言:javascript
运行
复制
    :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

第二次建造,只是:

代码语言:javascript
运行
复制
: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

Android Studio 1.4.2

构建成功,但在运行时,我们得到了NullPointerException,这是由代码混淆引起的。

我们还试图通过gradlew :app:clean :app:assembleDebug构建这个项目,最后以

代码语言:javascript
运行
复制
':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'

你的帮助真的很感激!提前谢谢你!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-20 04:07:26

我们清除了所有缓存,从无到有重新创建了项目,现在它可以正常工作了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35490346

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档