Android proguard enabled apk not connecting to azu

2019-09-03 04:09发布

I have been looking a solution since last week. I have an application which is having a connection with windows azure server. I need to give my apk to clients so I am trying to encrypt my apk before the deployment. Right now I am using proguard and I can create the apk without any warning. But after installation,The device is not connecting to the server. Without proguard it is connecting. here is my

on my MainActivity The Toast is displaying with an exception "java.lang.IllegalArgumentException:The class representing the mobile serviceTable must have a single id property defined" while assigning the class

         mClient = new MobileServiceClient(
                "https://uchek.azure-mobile.net/",
                "LslqFcIcUrlbLnYdDxTHUVrZBeQwPX81",
            con);

    try{
    mToDoTable = mClient.getTable(Product.class); //Assigning table
    }catch(Exception e){Toast.makeText(getApplicationContext(),    e+"",Toast.LENGTH_LONG).show();}

Product.java

 public class ProductInfo {


@com.google.gson.annotations.SerializedName("id")
private int mId;

@com.google.gson.annotations.SerializedName("imei")
private String mIMEI;
public ProductInfo(int id, String imei)
    { 
    this.setId(id);
    this.setIMEI(imei);
    }
    public final void setIMEI(String imei) {
    mIMEI = imei;
}
public int getId() {
    return mId;
}
public String getIMEI() {
    return mIMEI;
}

public final void setId(int id) {
    mId = id;
}
    }

proguard-project.txt

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-dontshrink
-dontoptimize
-verbose

-injars bin/classes
-injars libs
-outjars bin/classes-processed.jar
-libraryjars libs/achartengine-1.1.0.jar 
-libraryjars libs/droidText.0.5.jar
-libraryjars libs/gson-2.2.2.jar
-libraryjars libs/httpclient-4.2.3.jar
-libraryjars libs/joda-time-2.2.jar
-libraryjars libs/mobileservices-0.2.1.jar
-libraryjars libs/mobileservices-0.2.1-javadoc.jar
-libraryjars libs/mobileservices-0.2.1-sources.jar
-dontwarn org.apache.**
-dontwarn org.joda.**
-dontwarn org.slf4j.**
-dontwarn org.json.*
-dontwarn org.mortbay.**
-dontwarn org.apache.log4j.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.apache.commons.logging.**
-dontwarn org.apache.commons.codec.binary.**
-dontwarn javax.xml.**
-dontwarn javax.management.**
-dontwarn java.lang.management.**
-dontwarn android.support.**
-dontwarn com.google.code.**
-dontwarn oauth.signpost.**
-dontwarn twitter4j.**

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

    -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
-keep public class com.google.code.linkedinapi.**
-keep public class * implements java.io.Serializable
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.support.v4.app.ListFragment

-keep class javax.**  { *; }
-keep class org.**  { *; }
-keep class twitter4j.**  { *; }
-keep class java.lang.management.**  { *; }
-keep class com.google.code.**  { *; }
-keep class oauth.signpost.**  { *; }
-keep class com.microsoft.windowsazure.mobileservices.**  { *; }

-keepclassmembers public class                 com.google.code.linkedinapi.client.impl.LinkedInApiXppClient {
 public <init>(java.lang.String, java.lang.String);
}

-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);
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * extends com.actionbarsherlock.ActionBarSherlock {
<init>(android.app.Activity, int);
}
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
 public *;
}
-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();
}

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-03 04:39

The annotations are accessed through reflection. ProGuard doesn't know about it, so you need to preserve them explicitly:

-keepattributes *Annotation*
-keep @interface com.google.gson.annotations.SerializedName

Note that if you're using the standard Ant/Eclipse/Gradle build scripts, they already automatically specify all the necessary -injars, -outjars, and -libraryjars options, and other non-project-specific options.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-09-03 04:52

I've hit the same problem myself, and after looking a little through the code, I found the solution: just rename 'mId' to 'id' and you are all good. MobileServiceClient.getTable() calls the validateClass() method which looks for a field named 'id' or if it's marked with the @SerializedName annotation, then the value of the annotation. Since it didn't find it by annotation value, just rename it in your code and it will pick it up by field name. It says that it must have only one id field, but the thing is, it doesn't find any, ergo the error.

查看更多
登录 后发表回答