更新
将这些行添加到 app 模块的 build.gradle 中:
splits {
abi {
enable true
reset()
include 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
universalApk true
}
}
packagingOptions {
exclude 'lib/getLibs.ps1'
exclude 'lib/getLibs.sh'
exclude 'lib/gson-2.2.2.jar'
}
旧答案
尝试以下步骤:
第一步:将此依赖项添加到您的 build.gradle:
implementation 'com.microsoft.signalr:signalr:1.0.0'
第二步:将这些行添加到您的活动中:
private final String serverUrl = "put your server url";
private HubConnection hubConnection;
hubConnection = HubConnectionBuilder.create(serverUrl).build();
if (hubConnection.getConnectionState() == HubConnectionState.DISCONNECTED)
hubConnection.start();
if (hubConnection.getConnectionState() == HubConnectionState.CONNECTED)
hubConnection.send("your method name at server", your arguments);
else if (hubConnection.getConnectionState() == HubConnectionState.DISCONNECTED)
hubConnection.start();
正如您在上面看到的,您不需要在项目中添加两个不推荐使用的 signalR jar 库。