I have a chat application using SignalR. Recently I have enabled PROGUARD. Gson proguard rules are OK. For debug apk, chat message sending to server OK. Server pushes the message to chat_Receiver but I can see the response only on below "SignalR LOG" for chat_Receiver.
Platform.loadPlatformComponent(new AndroidPlatformComponent());
String serverUrl = getString(R.string.BaseUrl) + "/signalr";
printLog = true;
mHubConnection = new HubConnection(serverUrl, "MobileNumber=" + sender_mobile_numberEn, false, new Logger() {
@Override
public void log(String s, LogLevel logLevel) {
if (printLog) {
Log.d(TAG, "SignalR LOG:" + s);
}
}
});
mHubProxy = mHubConnection.createHubProxy(SERVER_HUB_CHAT);
But I don,t get the response on below "ChatMessageResponse LOG" for release apk.
private void registerReceiver() {
Log.d(TAG, "registerReceiver called");
mHubProxy.on("PushMessageToClient", new SubscriptionHandler1<ChatMessageResponsePOCO[]>() {
@Override
public void run(final ChatMessageResponsePOCO[] msgs) {
Gson gsonForArray = new GsonBuilder().create();
JsonArray jsonArray = gsonForArray.toJsonTree(msgs).getAsJsonArray();
Log.d(TAG, "ChatMessageResponse LOG: " + jsonArray);
processChatMessaages(jsonArray);
}
}, ChatMessageResponsePOCO[].class);
}
proguard-rules.pro file is as below:
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in F:\AndroidStudio/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-dontwarn **
-target 1.7
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
#############################################
-injars libs
-outjars bin/classes-processed.jar
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-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.preference.Preference
-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 public class org.apache.** {
<fields>;
<methods>;
}
#Don't obfuscate the model classes.
-keep class aerotxt.model.** { *; }
##---------------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 ----------
#############################################
# ----------------------------------------
# Android Support Library
# ----------------------------------------
-dontwarn android.support.**
-keep class android.support.** { *; }
#Below 2 attributes are used for otto library
-keepattributes *Annotation*
-keepclassmembers class ** {
@com.squareup.otto.Subscribe public *;
@com.squareup.otto.Produce public *;
}
Everything works fine for debug apk even after enabling Proguard. Problem is for only release apk. What will be the solution or the proguard rules for this.?
Proguard
issue ? If yes there should be some error containingClassNotFoundException
. Check logs . Otherwise check the debug and release config . Maybe some Key is missing . – Rondi