Carlos
Carlos

Reputation: 453

Android different behavior in retrofit when generate APK

I'm facing a weird error. It started when I upgraded to the new google billing library, but I think that is not related.

This part of the code behaves different when I test it and when I generate the APK.

private void insertPetDogWalker() {
    PetDogWalker mPetDogWalker = new PetDogWalker();
    mPetDogWalker.setIsActive(true);
    mPetDogWalker.setPetUid(mPet.getUid());
    mPetDogWalker.setDogWalkerUid(mGlobal.getUserUid());
    mPetDogWalker.setDateTimeInsert(mGlobal.getCurrentDateAndTime());
    mPetDogWalker.setDateTimeLastUpdate(mGlobal.getCurrentDateAndTime());

Log.e("insertPetDogWalker", "mGlobal.getUserUid()= "+ mGlobal.getUserUid()) ;
Log.e("insertPetDogWalker", "mPet.getUid()= "+ mPet.getUid()) ;

mPetDAO.insertPetDogWalker(mPetDogWalker, new Callback<Integer>() {
    @Override
    public void success(Integer petDogWalkerUid, Response response) {
        if (!LifecycleHandler.isActivityRunning() || !isAdded()) {
            if (progressDialog !=null) progressDialog.dismiss();
            return;
        }
        progressDialog.dismiss();
    }

    @Override
    public void failure(RetrofitError error) {
        if (!LifecycleHandler.isActivityRunning() || !isAdded()) {
            progressDialog.dismiss();
            return;
        }
        mGlobal.showErrorDialog(error.getLocalizedMessage(), mActivity);
    }
    });
}

Here the results when I run the APK:

2020-11-07 21:54:30.474 7600-7929/? D/Retrofit: ---> HTTP POST https://ssl.websiteseguro.com/cfbinformatica/dogwalkprd/************.svc/InsertPetDogWalker 
2020-11-07 21:54:30.474 7600-7929/? D/Retrofit: Accept: application/json 
2020-11-07 21:54:30.474 7600-7929/? D/Retrofit: AuthUserUid: ********** 
2020-11-07 21:54:30.474 7600-7929/? D/Retrofit: AuthUserValidationUid: VgKtbltimzJRB5YjeUaIH1BC4BvKJSskXhZXNxe4mEZlXuk+90INC91Nu31****** 
2020-11-07 21:54:30.474 7600-7929/? D/Retrofit: DeviceLanguage: português 
2020-11-07 21:54:30.474 7600-7929/? D/Retrofit: AuthUserProfile: user 
2020-11-07 21:54:30.474 7600-7929/? D/Retrofit: Content-Type: application/json;charset=utf-8 
2020-11-07 21:54:30.474 7600-7929/? D/Retrofit: Content-Length: 2 
2020-11-07 21:54:30.475 7600-7929/? D/Retrofit: {}

Notice that the body content in the post is empty (D/Retrofit: {}).

Here the results when I run it in a android studio environment:

2020-11-07 22:21:44.357 9633-10144/? D/Retrofit: ---> HTTP POST https://ssl.websiteseguro.com/cfbinformatica/dogwalkprd/*********.svc/InsertPetDogWalker
2020-11-07 22:21:44.357 9633-10144/? D/Retrofit: Accept: application/json
2020-11-07 22:21:44.357 9633-10144/? D/Retrofit: AuthUserUid: *******
2020-11-07 22:21:44.357 9633-10144/? D/Retrofit: AuthUserValidationUid: VgKtbltimzJRB5YjeUaIH1BC4BvKJSskXhZXNxe4mEZlXuk+90INC91Nu31****
2020-11-07 22:21:44.357 9633-10144/? D/Retrofit: DeviceLanguage: português
2020-11-07 22:21:44.357 9633-10144/? D/Retrofit: AuthUserProfile: user
2020-11-07 22:21:44.358 9633-10144/? D/Retrofit: Content-Type: application/json;charset=utf-8
2020-11-07 22:21:44.358 9633-10144/? D/Retrofit: Content-Length: 233
2020-11-07 22:21:44.359 9633-10144/? D/Retrofit: {"companyUid":0,"dateTimeInsert":20201107222144,"dateTimeLastUpdate":20201107222144,"dogWalkerDateTimeLastUpdate":0,"dogWalkerUid":4358,"isActive":true,"petUid":1610,"phoneNumber":0,"phoneNumberCity":0,"phoneNumberCountry":0,"uid":0}
2020-11-07 22:21:44.360 9633-10144/? D/Retrofit: ---> END HTTP (233-byte body)

Notice that the contend in the post last 2 retrofit line has the body content

Follows build.grade:

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

implementation 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
implementation 'com.squareup.okhttp:okhttp:2.2.0'
implementation 'com.squareup.retrofit:retrofit:1.9.0'
implementation 'com.google.code.gson:gson:2.8.5'

Follows proguard-rules.pro

# Add any project specific keep options here:

# Direct HTTP call
-keep class br.com.cfb.dogwalktrackershared.json.DirectionsJSONParser

# Parcel library
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
-keep class org.parceler.Parceler$$Parcels

# Remove warnings for Release the application
-dontwarn javax_.**
-dontwarn okio.**
-dontwarn org.parceler.**
-dontwarn com.google.android.gms.internal.zz**

# Squareup
-dontwarn com.squareup.**
-keepclassmembers class ** {
    @com.squareup.otto.Subscribe public *;
    @com.squareup.otto.Produce public *;
}
-keep class com.squareup.okhttp.** { *; }

# Retrofit
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
    @retrofit.http.* <methods>;
}

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

# ---- Crashlytics
-keepattributes SourceFile,LineNumberTable
##---- End: proguard configuration for Crashlytics ----------

Upvotes: 1

Views: 55

Answers (1)

Carlos
Carlos

Reputation: 453

It worked once I updated the proguard to:

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

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

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

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

Upvotes: 1

Related Questions