gpt4 book ai didi

android - SignalR android 客户端的混淆规则是什么?

转载 作者:行者123 更新时间:2023-11-29 01:00:27 32 4
gpt4 key购买 nike

我有一个使用 SignalR 的聊天应用程序。最近我启用了 PROGUARD。 Gson proguard 规则没问题。对于调试 apk,聊天消息发送到服务器 OK。服务器将消息推送到 chat_Receiver 但是我只能在 chat_Receiver 的“SignalR LOG”下方看到响应。

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

但我没有在“ChatMessageResponse LOG”下方收到发布 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文件如下:

# 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 *;
}

即使在启用 Proguard 后,调试 apk 一切正常。问题是只发布 apk。这将是什么解决方案或proguard规则。?

最佳答案

在混淆器规则中添加以下行:

 -keep class com.microsoft.signalr.** { *; }
-keep interface com.microsoft.signalr.** { *; }

这对我有用!

关于android - SignalR android 客户端的混淆规则是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51610646/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com