2017-07-15 10 views
0

私はカスタムリストを持っています.Gsonを使ってjsonArrayに変換しています。Gsonはキーを変更します

問題は、私がデバッグバージョンapkを使用している場合、完全に動作していますが、リリースバージョンapkを使用している場合、キーが変更されます。

例:

Debug version -> "name", "Mary" 
Release version -> "a", "Mary" 

すべてのキーが、私は両方のバージョンでは、ProGuardを持っている "...、B、C" に

を変更します。

マイコード:

Gson gson = new Gson(); 
JsonArray jsonArray = gson.toJsonTree(myCustomList).getAsJsonArray(); 

のGradleコード:

buildTypes { 
    release { 
     debuggable true 
     minifyEnabled true 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 

    } 
    debug { 
     minifyEnabled true 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 

ProGuardのコード:

-dontwarn okhttp3.** 
-dontwarn okio.** 

##---------------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 

私は私のパッケージ名を-keep class yourPackageName.data.model.** { *; }を追加しましたが、私は同じ問題を抱えて。

答えて

1

私はあなたのデバッグビルドでは有効になっていないと思います。したがって、難読化が発生したときにモデルクラスを維持する必要があります。この例の意図は、指定されたパッケージ-keep class yourPackageName.data.model.** { *; }

+0

内のすべてのモデルクラスを維持するしかし、私は実際に奇妙な、私はそれをすることはできませんProGuardの設定 – Dahnark

+0

どちらもあまりにもデバッグバージョンでProGuardのを使用しています。あなたのデバッグビルドのフィールド名を変更する必要があるので – Dahnark

+0

を投稿するつもりですが、あまりにも – santalu

関連する問題