安卓在改装时产生APK的不同行为

  • 本文关键字:APK android retrofit proguard
  • 更新时间 :
  • 英文 :


我面临一个奇怪的错误。它始于我升级到新的谷歌计费库,但我认为这与此无关。

这部分代码在测试时和生成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/改装:{}(。

以下是我在安卓工作室环境中运行它的结果:

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

相关内容

  • 没有找到相关文章

最新更新