生成APK时,Android在改装方面的不同行为

问题描述

我遇到一个奇怪的错误。它是在我升级到新的Google计费库后开始的,但我认为这没有关系。

在测试和生成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);
    }
    });
}

运行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: {}

请注意,帖子中的正文内容为空(D / Retrofit:{})。

当我在android studio环境中运行它时,结果如下:

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)

请注意,后2条改装行中的内容包含正文内容

遵循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'

遵循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 ----------

解决方法

当我将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.** { <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  ----------