Billdesk Android SDK 的 Proguard 规则
Proguard rule for Billdesk Android SDK
我在将 ProGuard
应用到 Billdesk SDK 时遇到问题。
如果我在没有 ProGuard 的情况下构建 apk 那么工作正常,但是如果使用 ProGuard 构建然后得到错误,
SDK not initialised properly.
我的应用程序的当前 ProGuard 规则如下所示,
# code for optimazation
-dontnote org.json.**
-dontwarn org.apache.http.**
-dontnote org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient
-dontnote android.net.http.**
#OKHTTP
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
-dontwarn okio.**
# Retrofit 2.X
## https://square.github.io/retrofit/ ##
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
# Simple-Xml Proguard Config
# NOTE: You should also include the Android Proguard config found with the build tools:
# $ANDROID_HOME/tools/proguard/proguard-android.txt
# Keep public classes and methods.
-dontwarn com.bea.xml.stream.**
-dontwarn org.simpleframework.xml.stream.**
-dontwarn javax.xml.**
-keep public class org.simpleframework.**{ *; }
-keep class org.simpleframework.xml.**{ *; }
-keep class org.simpleframework.xml.core.**{ *; }
-keep class org.simpleframework.xml.util.**{ *; }
-keepattributes Signature
-keepattributes *Annotation*
# Ignore our XML Serialization classes
-keep public class packagename.model.ServerResponse{
public protected private *;
}
-keep public class packagename.model.ServerRequest{
public protected private *;
}
-keep public class packagename.activity.ProceedToPayActivity{
public protected private *;
}
-keep public class packagename.model.ServerResponseHeader{
public protected private *;
}
#
#-dontwarn com.bea.xml.stream.**
#
#-keep class org.simpleframework.xml.**{ *; }
#-keepclassmembers,allowobfuscation class * {
# @org.simpleframework.xml.* <fields>;
# @org.simpleframework.xml.* <init>(...);
#}
-keep class com.jamesmurty.** { *; }
-dontwarn com.jamesmurty.utils.**
##
##Billdesk rules
-keep public class com.billdesk.sdk.*
-keep public class com.billdesk.config.*
-keep public class com.billdesk.utils.URLUtilActivity
-keep public interface com.billdesk.sdk.LibraryPaymentStatusProtocol{
public void paymentStatus(java.lang.String,android.app.Activity);
}
-keep class com.billdesk.sdk.PaymentWebView$JavaScriptInterface{
public void gotMsg(java.lang.String);
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
-keepattributes JavascriptInterface
-keep public class com.billdesk.sdk.PaymentWebView$JavaScriptInterface
-keep public class * implements com.billdesk.sdk.PaymentWebView$JavaScriptInterface
-keepclassmembers class com.billdesk.sdk.PaymentWebView$JavaScriptInterface {
<methods>;
}
为Billdesk通话使用,
BilldeskPaymentCallback billdeskPaymentCallback = new BilldeskPaymentCallback();
Intent intent = new Intent(getApplicationContext(), PaymentOptions.class);
intent.putExtra(Constants.BILLDESK_MESSAGE, billdeskToken); //pg_msg
intent.putExtra(Constants.BILLDESK_CALLBACK, billdeskPaymentCallback);
startActivity(intent);
It will access your input and create JSON for it.
错误是我没有为 JSON,
写混淆规则
添加此代码后正常工作。
-keep public class org.json.*{ *; }
-keep class org.json.*{ *; }
-keepclassmembers,allowobfuscation class * {
@org.json.* <fields>;
@org.json.* <init>(...);
}
我在将 ProGuard
应用到 Billdesk SDK 时遇到问题。
如果我在没有 ProGuard 的情况下构建 apk 那么工作正常,但是如果使用 ProGuard 构建然后得到错误,
SDK not initialised properly.
我的应用程序的当前 ProGuard 规则如下所示,
# code for optimazation
-dontnote org.json.**
-dontwarn org.apache.http.**
-dontnote org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient
-dontnote android.net.http.**
#OKHTTP
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
-dontwarn okio.**
# Retrofit 2.X
## https://square.github.io/retrofit/ ##
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
# Simple-Xml Proguard Config
# NOTE: You should also include the Android Proguard config found with the build tools:
# $ANDROID_HOME/tools/proguard/proguard-android.txt
# Keep public classes and methods.
-dontwarn com.bea.xml.stream.**
-dontwarn org.simpleframework.xml.stream.**
-dontwarn javax.xml.**
-keep public class org.simpleframework.**{ *; }
-keep class org.simpleframework.xml.**{ *; }
-keep class org.simpleframework.xml.core.**{ *; }
-keep class org.simpleframework.xml.util.**{ *; }
-keepattributes Signature
-keepattributes *Annotation*
# Ignore our XML Serialization classes
-keep public class packagename.model.ServerResponse{
public protected private *;
}
-keep public class packagename.model.ServerRequest{
public protected private *;
}
-keep public class packagename.activity.ProceedToPayActivity{
public protected private *;
}
-keep public class packagename.model.ServerResponseHeader{
public protected private *;
}
#
#-dontwarn com.bea.xml.stream.**
#
#-keep class org.simpleframework.xml.**{ *; }
#-keepclassmembers,allowobfuscation class * {
# @org.simpleframework.xml.* <fields>;
# @org.simpleframework.xml.* <init>(...);
#}
-keep class com.jamesmurty.** { *; }
-dontwarn com.jamesmurty.utils.**
##
##Billdesk rules
-keep public class com.billdesk.sdk.*
-keep public class com.billdesk.config.*
-keep public class com.billdesk.utils.URLUtilActivity
-keep public interface com.billdesk.sdk.LibraryPaymentStatusProtocol{
public void paymentStatus(java.lang.String,android.app.Activity);
}
-keep class com.billdesk.sdk.PaymentWebView$JavaScriptInterface{
public void gotMsg(java.lang.String);
}
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
-keepattributes JavascriptInterface
-keep public class com.billdesk.sdk.PaymentWebView$JavaScriptInterface
-keep public class * implements com.billdesk.sdk.PaymentWebView$JavaScriptInterface
-keepclassmembers class com.billdesk.sdk.PaymentWebView$JavaScriptInterface {
<methods>;
}
为Billdesk通话使用,
BilldeskPaymentCallback billdeskPaymentCallback = new BilldeskPaymentCallback();
Intent intent = new Intent(getApplicationContext(), PaymentOptions.class);
intent.putExtra(Constants.BILLDESK_MESSAGE, billdeskToken); //pg_msg
intent.putExtra(Constants.BILLDESK_CALLBACK, billdeskPaymentCallback);
startActivity(intent);
It will access your input and create JSON for it.
错误是我没有为 JSON,
写混淆规则添加此代码后正常工作。
-keep public class org.json.*{ *; }
-keep class org.json.*{ *; }
-keepclassmembers,allowobfuscation class * {
@org.json.* <fields>;
@org.json.* <init>(...);
}