gpt4 book ai didi

android - 无法访问我在 android 中的模块嵌套依赖项

转载 作者:行者123 更新时间:2023-12-05 00:09:45 25 4
gpt4 key购买 nike

我创建了一个具有如下类依赖项的 android 模块:

implementation 'com.squareup.moshi:moshi:1.5.0'
implementation 'com.neovisionaries:nv-websocket-client:2.3'

我将此模块添加到我的项目中。当我想使用它时,它说“无法访问 com.neovisionaries.Adapter”。

1 -Why it cannot access because I think that my Async class calls the method in the background?

2-Should I add that dependency to my project?

我的模块类

public class Async extends WebSocketAdapter {
....
public Async() {
}

public static Async getInstance(Context context) {
if (instance == null) {
sharedPrefs = context.getSharedPreferences(AsyncConstant.Constants.PREFERENCE, Context.MODE_PRIVATE);
moshi = new Moshi.Builder().build();
instance = new Async();
}
return instance;
}


public void webSocketConnect(String socketServerAddress, final String appId) {
WebSocketFactory webSocketFactory = new WebSocketFactory();
webSocketFactory.setVerifyHostname(false);
setAppId(appId);
setServerAddress(socketServerAddress);
try {
webSocket = webSocketFactory
.setConnectionTimeout(TIMEOUT)
.createSocket(socketServerAddress)
.addListener(this);
webSocket.connectAsynchronously();
} catch (IOException e) {
e.printStackTrace();
}
}}

MyPresenter 类

public class SocketPresenter implements SocketContract.presenter {

private Async async;
private SocketContract.view view;
@Override
public void connect(String socketServerAddress, String appId) {
async.webSocketConnect(socketServerAddress, appId);
}

此行有一个错误 async.webSocketConnect(socketServerAddress, appId); 表示 websocketConnect 无法访问我的嵌套模块依赖项。

最佳答案

当 Gradle compile 关键字被弃用时,它被两个新关键字取代:implementationapiimplementation 关键字将您的依赖关系保持在内部,而 api 像旧的 compile 关键字一样公开它们。因此,您应该使用 api 而不是 implementation

documentation 中查看更多详细信息.

关于android - 无法访问我在 android 中的模块嵌套依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50343241/

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