Неправильные ключи в json при вызове дооснащения после включения proguard - PullRequest
0 голосов
/ 05 мая 2020

когда я вызываю модификацию без proguard я получил json как показано ниже: D/OkHttp: {"UserPin":"123456","password":"123456"} и после добавления proguard он дает следующее json: D/OkHttp: {"a":"123456","b":"123456"}

Proguard меняет ключи в json

Это мой код: -

private void doLogin(String userPin, String password) {
        startProgress();
        LoginUser loginUser = new LoginUser(userPin, password);
        Call<Login> call = MyApplication.apiInterface.doLogin(loginUser);
        call.enqueue(new Callback<Login>() {
            @Override
            public void onResponse(Call<Login> call, Response<Login> response) {
                finishProgress();
                try {
                    setLoginResponse(response.body());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Call<Login> call, Throwable t) {
                finishProgress();
                try {
                    setLoginResponse(null);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        });

    }

Помогите, пожалуйста

Ответы [ 2 ]

0 голосов
/ 05 мая 2020

Убедитесь, что proguard также настроен для gson. Вам необходимо убедиться, что POJO, используемые с gson, не запутываются и аннотации не удаляются.

Примечание: В приведенном ниже примере вам следует заменить com.google.gson.examples.android.model.** { *; } на классы вашей модели.

Из примера конфигурации proguard gson -

##---------------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.** { *; }

##---------------End: proguard configuration for Gson  ----------
0 голосов
/ 05 мая 2020

Вы должны добавить proguard правило.

-ignorewarnings
-dontwarn okio.**

-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

-keepattributes *Annotation*

-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}

И класс входа

-keep class package_name.Login** { *; }
-keepclassmembers class package_name.Login** { *; }

Для GSON Proguard, попробуй вот так

##---------------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
-dontwarn sun.misc.**
#-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  ----------
...