Android的proguard相关的APK没有连接到服务器碧空 [英] Android proguard enabled apk not connecting to azure server

查看:215
本文介绍了Android的proguard相关的APK没有连接到服务器碧空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找,因为上周的解决方案。我有是有使用Windows Azure服务器的连接的应用程序。我需要给我的apk的客户,所以我想在部署之前,我的apk进行加密。现在我使用ProGuard,我能创造没有任何警告的APK。但在安装之后,设备未连接到服务器。如果没有的ProGuard它连接。这里是我的

在我MainActivity吐司与异常java.lang.IllegalArgumentException异常:类重presenting移动serviceTable必须定义一个id属性显示,而分配类

  mClient =新MobileServiceClient(
                https://uchek.azure-mobile.net/
                LslqFcIcUrlbLnYdDxTHUVrZBeQwPX81
            CON);    尝试{
    mToDoTable = mClient.getTable(Product.class); //分配表
    }赶上(例外五){Toast.makeText(getApplicationContext(),E +,Toast.LENGTH_LONG).show();}

Product.java

 公共类ProductInfo {
@ com.google.gson.annotations.SerializedName(ID)
私人诠释MID;@ com.google.gson.annotations.SerializedName(IMEI)
私人字符串mIMEI;
公共ProductInfo(INT ID,字符串IMEI)
    {
    this.setId(ID);
    this.setIMEI(IMEI);
    }
    公众最终无效setIMEI(IMEI串){
    mIMEI = IMEI;
}
公众诠释的getId(){
    返回MID;
}
公共字符串getIMEI(){
    返回mIMEI;
}公众最终无效SETID(INT ID){
    MID = ID;
}
    }

proguard的-project.txt

  -optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dont preverify
-dontshrink
-dontoptimize
-verbose-injars斌/班
-injars库
-outjars斌/班,processed.jar
-libraryjars库/ achartengine-1.1.0.jar
-libraryjars库/ droidText.0.5.jar
-libraryjars库/ GSON-2.2.2.jar
-libraryjars库/ HttpClient的-4.2.3.jar
-libraryjars库/乔达时间,2.2.jar
-libraryjars库/ mobileservices-0.2.1.jar
-libraryjars库/ mobileservices-0.2.1-javadoc.jar
-libraryjars库/ 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 /简化/算术!现场/ * ,!类/合并/ *    -keep公共类*扩展android.app.Activity
-keep公共类*扩展android.app.Application
-keep公共类*扩展android.app.Service
-keep公共类*扩展android.content.BroadcastReceiver
-keep公共类*扩展android.content.ContentProvider
-keep公共类*扩展android.app.backup.BackupAgentHelper
-keep公共类*扩展Android系统。preference。preference
-keep公共类com.android.vending.licensing.ILicensingService
-keep公共类com.google。code.linkedinapi。**
-keep公共类*实现java.io.Serializable
-keep公共类*扩展android.support.v4.app.Fragment
-keep公共类*扩展android.support.v4.app.ListFragment-keep类的javax ** {*。 }
-keep类组织** {*。 }
-keep类twitter4j ** {*。 }
-keep类java.lang.management ** {*。 }
-keep类com.google code ** {*。; }
-keep类oauth.signpost ** {*。 }
-keep类com.microsoft.windowsazure.mobileservices ** {*。 }-keepclassmembers公共类com.google。$ C $ {c.linkedinapi.client.impl.LinkedInApiXppClient
 公众和LT; INIT>(java.lang.String中,java.lang.String中);
}-keepclasseswithmembernames类* {
天然的所述;方法&gt ;;
}-keepclasseswithmembernames类* {
公众和LT; INIT>(android.content.Context,android.util.AttributeSet);
}-keepclasseswithmembernames类* {
公众和LT; INIT>(android.content.Context,android.util.AttributeSet,INT);
}-keepclassmembers枚举* {
公共静态** []值();
公共静态**的valueOf(java.lang.String中);
}
-keepclassmembers类*宽com.actionbarsherlock.ActionBarSherlock {
<&初始化GT;(android.app.Activity,INT);
}
-keep类*实现android.os.Parcelable {
  公共静态最终android.os.Parcelable $造物主*;
}
-keepclassmembers类fqcn.of.javascript.interface.for.webview {
 上市 *;
}
-keepclassmembers类*实现java.io.Serializable {
静态最后的serialVersionUID长;
私有静态最终java.io.ObjectStreamField中的[] serialPersistentFields;
私人无效的writeObject(java.io.ObjectOutputStream中);
私人无效的readObject(java.io.ObjectInputStream中);
java.lang.Object继承writeReplace();
java.lang.Object中的readResolve();
}


解决方案

注解是通过反射访问。 ProGuard的不知道这件事,所以你需要preserve他们明确的:

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

请注意,如果您使用的是标准Ant / Eclipse中/摇篮构建脚本,他们已经自动指定所有必要的 -injars - outjars -libraryjars 选项和其他非项目特定的选项。

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

解决方案

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.

这篇关于Android的proguard相关的APK没有连接到服务器碧空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆