2013-07-02 84 views
3

我想混淆我的.apk,并且在Proguard中遇到一些麻烦。使用Eclipse我已经启用这样的:Android Proguard ExceptionInInitializerError和RuntimeException

# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 

我用4个外部库:

  • Android的支持,v4.jar
  • 九老的Android lib.jar
  • GSON-2.2.2.jar
  • 公地IO-2.4.jar

我想我遇到的麻烦GSON:

private static Type MY_DATA_TYPE = new TypeToken<Pair<Map<Point, Void>, Integer>>() {}.getType(); 

我每次使用它:

FATAL EXCEPTION: main 
java.lang.ExceptionInInitializerError at com.myapp.MyActivity.onCreate(Unknown Source) 

... 

Caused by: java.lang.RuntimeException: Missing type parameter. 
at com.google.gson.reflect.TypeToken.getSuperclassTypeParameter(Unknown Source) 
at com.google.gson.reflect.TypeToken.<init>(Unknown Source) 

我使用这个选项,但我想这不会帮助:

-keepattributes Exceptions, InnerClasses, *Annotation*, EnclosingMethod 

-dontskipnonpubliclibraryclassmembers 
-libraryjars .../libs/android-support-v4.jar 
-libraryjars .../libs/nine-old-android-lib.jar 
-libraryjars .../libs/gson-2.2.2.jar 
-libraryjars .../libs/commons-io-2.4.jar 


-keep class java.** { *; } 
-keep class android.** { *; } 
-keep class org.** { *; } 
-keep class com.google.** { *; } 
-keep class com.facebook.** { *; } 
-keep class com.nineoldandroids.** { *; } 

我怎样才能解决这个和创建一个工作正常的混淆的.apk?
谢谢你的时间。

+0

我使用...类型类型=新TypeToken >>(){} .getType(); ..它确实给我这个列表,但我得到站对象null我应该怎么做 –

回答

7

想这是一个GSON “问题”,这里的溶液:

-keepattributes Signature 
-keep class sun.misc.Unsafe { *; } 
-keep class com.google.gson.examples.android.model.** { *; } 

由于https://groups.google.com/forum/#!topic/google-gson/6XuHfOoZIKo

+0

我正在使用... Type type = new TypeToken >>(){} .getType(); ..它给我这个列表,但我得到站对象null我应该怎么做 –

+0

创建一个新的话题与您的问题和一些代码示例和错误输出,所以我们可以给你一些质量帮助。 – GuilhE

+0

是的,我确实创建了一个http://stackoverflow.com/questions/35539960/how-to-get-release-build-apk-file-using-proguard,显然我无法得到有关错误的解释以及如何解决这个问题 –

1

Proguard的配置如由谷歌GSON proguard的示例所示。

google gson proguard configuration link

##---------------Begin: proguard configuration for Gson ---------- 
# Gson uses generic type information stored in a class file when working with fields. Proguard 
# removes such information by default, so configure it to keep all of it. 
-keepattributes Signature 

# For using GSON @Expose annotation 
-keepattributes *Annotation* 

# Gson specific classes 
-keep class sun.misc.Unsafe { *; } 
#-keep class com.google.gson.stream.** { *; } 

# Application classes that will be serialized/deserialized over Gson 
-keep class com.google.gson.examples.android.model.** { *; } 

# Prevent proguard from stripping interface information from TypeAdapterFactory, 
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter) 
-keep class * implements com.google.gson.TypeAdapterFactory 
-keep class * implements com.google.gson.JsonSerializer 
-keep class * implements com.google.gson.JsonDeserializer 

##---------------End: proguard configuration for Gson ----------