由于Amazon AWS SDK出现问题,启用ProGuard后,我的Android应用无法从Eclipse导出。
我正在使用适用于Android的AWS SDK 1.7.0版(核心版和s3版)。记录到控制台的错误如下所示。
我按照亚马逊提供的推荐ProGuard配置设置无效:https://mobile.awsblog.com/post/Tx2OC71PFCTC63E/Using-ProGuard-with-the-AWS-SDK-for-Android
这些是我项目中的罐子:
aws-android-sdk-1.7.0-core.jar
aws-android-sdk-1.7.0-s3.jar
Project.properties:
proguard.config=proguard-project.txt
# Project target.
target=android-19
android.library.reference.1=../../../../../opt/ADT/sdk/extras/google/google_play_services/libproject/google-play-services_lib
android.library.reference.2=../../../../../opt/ADT/sdk/extras/android/support/v7/appcompat
我的ProGuard配置如下:
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
# Otherwise return Warning: com.fasterxml.jackson.databind.ext.DOMSerializer: can't find referenced class org.w3c.dom.bootstrap.DOMImplementationRegistry
-dontwarn com.fasterxml.jackson.databind.**
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
# Preserve all fundamental application classes.
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.view.View
-keep public class * extends android.preference.Preference
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
# Preserve Android support libraries` classes and interfaces
-keep class android.support.** { *; }
-keep interface android.support.** { *; }
# Preserve all Jackson library classes
-keep class com.fasterxml.jackson.** { *; }
# Original
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
#To remove debug logs:
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
}
#AWS
-keep class org.apache.commons.logging.** { *; }
-keep class com.amazonaws.services.sqs.QueueUrlHandler { *; }
-keep class com.amazonaws.javax.xml.transform.sax.* { public *; }
-keep class com.amazonaws.javax.xml.stream.** { *; }
-keep class com.amazonaws.services.**.model.*Exception* { *; }
-keep class org.codehaus.** { *; }
-keepattributes Signature,*Annotation*
-dontwarn javax.xml.stream.events.**
-dontwarn org.codehaus.jackson.**
-dontwarn org.apache.commons.logging.impl.**
-dontwarn org.apache.http.conn.scheme.**
Proguard输出:
[2014-02-17 18:40:22 - Spream] Proguard returned with error code 1. See console
[2014-02-17 18:40:22 - Spream] Note: there were 1 duplicate class definitions.
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider: can't find referenced class com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider: can't find referenced class com.amazonaws.services.securitytoken.model.AssumeRoleRequest
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider: can't find referenced class com.amazonaws.services.securitytoken.AWSSecurityTokenService
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider: can't find referenced class com.amazonaws.services.securitytoken.model.AssumeRoleResult
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider: can't find referenced class com.amazonaws.services.securitytoken.model.Credentials
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider: can't find referenced class com.amazonaws.services.securitytoken.AWSSecurityTokenService
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSSessionCredentials: can't find referenced class com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSSessionCredentials: can't find referenced class com.amazonaws.services.securitytoken.model.Credentials
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSSessionCredentials: can't find referenced class com.amazonaws.services.securitytoken.model.GetSessionTokenRequest
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSSessionCredentials: can't find referenced class com.amazonaws.services.securitytoken.AWSSecurityTokenService
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSSessionCredentials: can't find referenced class com.amazonaws.services.securitytoken.model.GetSessionTokenResult
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSSessionCredentials: can't find referenced class com.amazonaws.services.securitytoken.model.Credentials
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSSessionCredentials: can't find referenced class com.amazonaws.services.securitytoken.AWSSecurityTokenService
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.auth.STSSessionCredentials: can't find referenced class com.amazonaws.services.securitytoken.AWSSecurityTokenService
[more com.amazonaws...]
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.HttpHost: can't find referenced class org.apache.http.annotation.Immutable
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.HttpVersion: can't find referenced class org.apache.http.annotation.Immutable
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.ProtocolVersion: can't find referenced class org.apache.http.annotation.Immutable
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.auth.AUTH: can't find referenced class org.apache.http.annotation.Immutable
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.auth.AuthOption: can't find referenced class org.apache.http.annotation.Immutable
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.auth.AuthSchemeRegistry: can't find referenced class org.apache.http.annotation.ThreadSafe
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.auth.AuthScope: can't find referenced class org.apache.http.annotation.Immutable
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.auth.AuthState: can't find referenced class org.apache.http.annotation.NotThreadSafe
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.auth.AuthenticationException: can't find referenced class org.apache.http.annotation.Immutable
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.auth.BasicUserPrincipal: can't find referenced class org.apache.http.annotation.Immutable
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.auth.InvalidCredentialsException: can't find referenced class org.apache.http.annotation.Immutable
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.conn.params.ConnManagerParams: can't find referenced class org.apache.http.annotation.Immutable
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.conn.params.ConnPerRouteBean: can't find referenced class org.apache.http.annotation.ThreadSafe
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.conn.params.ConnRouteParamBean: can't find referenced class org.apache.http.annotation.NotThreadSafe
[more com.amazonaws.org.apache.http... can not find referenced org.apache.http.annotation...]
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.impl.auth.GGSSchemeBase: can't find referenced class org.ietf.jgss.GSSManager
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.impl.auth.GGSSchemeBase: can't find referenced class org.ietf.jgss.GSSManager
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.impl.auth.GGSSchemeBase: can't find referenced class org.ietf.jgss.GSSException
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.message.AbstractHttpMessage: can't find referenced class org.apache.http.annotation.NotThreadSafe
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.message.BasicHeader: can't find referenced class org.apache.http.annotation.Immutable
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.message.BasicHeaderElement: can't find referenced class org.apache.http.annotation.NotThreadSafe
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.org.apache.http.message.BasicHeaderElementIterator: can't find referenced class org.apache.http.annotation.NotThreadSafe
[more com.amazonaws.org.apache.http...]
[2014-02-17 18:40:22 - Spream] Warning: com.amazonaws.util.TimingInfo: can't find referenced class org.apache.http.annotation.NotThreadSafe
[2014-02-17 18:40:22 - Spream] You should check if you need to specify additional program jars.
[2014-02-17 18:40:22 - Spream] Warning: there were 425 unresolved references to classes or interfaces.
[2014-02-17 18:40:22 - Spream] You may need to specify additional library jars (using '-libraryjars').
[2014-02-17 18:40:22 - Spream] java.io.IOException: Please correct the above warnings first.
[2014-02-17 18:40:22 - Spream] at proguard.Initializer.execute(Initializer.java:321)
[2014-02-17 18:40:22 - Spream] at proguard.ProGuard.initialize(ProGuard.java:211)
[2014-02-17 18:40:22 - Spream] at proguard.ProGuard.execute(ProGuard.java:86)
[2014-02-17 18:40:22 - Spream] at proguard.ProGuard.main(ProGuard.java:492)
如果我添加
-dontwarn com.amazonaws.**
ProGuard正常工作,但是当我运行应用程序时,它立即关闭此RuntimeException:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.RuntimeException: Failed to initialize the regions.
at com.amazonaws.g.c.b(Unknown Source)
at com.amazonaws.g.c.a(Unknown Source)
at com.amazonaws.g.c.a(Unknown Source)
at com.amazonaws.g.a.a(Unknown Source)
at com.gzanitti.spream.c.d(Unknown Source)
at com.gzanitti.spream.c.c(Unknown Source)
at com.gzanitti.spream.n.a(Unknown Source)
at com.gzanitti.spream.n.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 5 more
有什么想法吗?我几个小时都坚持这个问题。
答案 0 :(得分:0)
问题不在于Proguard,而是缺少区域配置文件。确保它在最终jar的类路径中可用。
https://github.com/aws/aws-sdk-android/blob/master/src/awssdk_config_default.json
-k