在Play商店发布后,Retrofit2无法在Android应用中获取数据

时间:2017-10-28 14:17:11

标签: android google-play retrofit2 release

我创建了一个Android应用程序,它使用retrofit2从服务器获取数据。它在调试模式下工作得非常好,但在App Store上发布后,它无法获取数据。

在android studio中创建release apk时出现错误,所以我将以下代码放在proguard-rules.pro文件中:

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

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

     ## Square Picasso specific rules ##
     ## https://square.github.io/picasso/ ##

     -dontwarn com.squareup.okhttp.**
     -dontwarn com.squareup.picasso.**

     # OkHttp
     -keepattributes Signature
     -keepattributes *Annotation*
     -keep class okhttp3.** { *; }
     -keep interface okhttp3.** { *; }
     -dontwarn okhttp3.**

     ## Google Play Services 4.3.23 specific rules ##
     ## https://developer.android.com/google/play-                                             
     #Proguard ##

     -keep class * extends java.util.ListResourceBundle {
     protected Object[][] getContents();
     }

     -keep public class                   
     com.google.android.gms.common.internal.safeparcel.SafeParcelable {
       public static final *** NULL;
     }

     -keepnames @com.google.android.gms.common.annotation.KeepName class *
     -keepclassmembernames class * {
     @com.google.android.gms.common.annotation.KeepName *;
     }

     -keepnames class * implements android.os.Parcelable {
         public static final ** CREATOR;
     }

     # Okio
     -keep class sun.misc.Unsafe { *; }
     -dontwarn java.nio.file.*
     -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
     -dontwarn okio.**



     ##---------------Begin: proguard configuration common for all Android          apps ---------
     -optimizationpasses 5
     -dontusemixedcaseclassnames
     -dontskipnonpubliclibraryclasses
     -dontskipnonpubliclibraryclassmembers
     -dontpreverify
     -verbose
     -dump class_files.txt
     -printseeds seeds.txt
     -printusage unused.txt
     -printmapping mapping.txt
     -optimizations          !code/simplification/arithmetic,!field/*,!class/merging/*

     -allowaccessmodification
     -keepattributes *Annotation*
     -renamesourcefileattribute SourceFile
     -keepattributes SourceFile,LineNumberTable
     -repackageclasses ''

     -keep public class * extends android.app.Activity
     -keep public class * extends android.app.Application
     -keep public class * extends android.app.Service
     -keep public class * extends android.content.BroadcastReceiver
     -keep public class * extends android.content.ContentProvider
     -keep public class * extends android.app.backup.BackupAgentHelper
     -keep public class * extends android.preference.Preference
     -keep public class com.android.vending.licensing.ILicensingService
     -dontnote com.android.vending.licensing.ILicensingService

     # Explicitly preserve all serialization members. The Serializable interface
     # is only a marker interface, so it wouldn't save them.
     -keepclassmembers class * implements java.io.Serializable {
     static final long serialVersionUID;
     private static final java.io.ObjectStreamField[]                   
     serialPersistentFields;
     private void writeObject(java.io.ObjectOutputStream);
     private void readObject(java.io.ObjectInputStream);
     java.lang.Object writeReplace();
     java.lang.Object readResolve();
     }

     # Preserve all native method names and the names of their classes.
     -keepclasseswithmembernames class * {
      native <methods>;
      }

     -keepclasseswithmembernames class * {
         public <init>(android.content.Context, android.util.AttributeSet);
     }

     -keepclasseswithmembernames class * {
         public <init>(android.content.Context, android.util.AttributeSet, 
      int);
     }

     # Preserve static fields of inner classes of R classes that might be 
     accessed
     # through introspection.
     -keepclassmembers class **.R$* {
       public static <fields>;
     }

     # Preserve the special static methods that are required in all 
     enumeration classes.
     -keepclassmembers enum * {
         public static **[] values();
         public static ** valueOf(java.lang.String);
     }

     -keep public class * {
         public protected *;
     }

     -keep class * implements android.os.Parcelable {
       public static final android.os.Parcelable$Creator *;
     }
     -keep class android.support.v4.app.** { *; }
     -keep interface android.support.v4.app.** { *; }
     -keep class com.actionbarsherlock.** { *; }
     -keep interface com.actionbarsherlock.** { *; }

     -dontwarn android.support.**
     -dontwarn com.google.ads.**
     -keepattributes Signature
     -keepattributes *Annotation*
     -keep class sun.misc.Unsafe { *; }
     -keep class com.example.model.** { *; }

我对android中使用的proguard规则一无所知,我只是把我在互联网上找到的任何内容放在一边,以避免所有错误。

0 个答案:

没有答案