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



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

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

当我想使用它时,它说"无法访问com.neovisionaries.Adapter"。

1 - 为什么它无法访问,因为我认为我的异步类在后台调用该方法?

2-我应该将该依赖项添加到我的项目中吗?

我的模块类

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

我的演示器类

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无法访问我的 neseted 模块依赖项。

当 Gradlecompile关键字被弃用时,它被两个新关键字替换:implementationapiimplementation关键字将依赖项保留在内部,同时api像旧的compile关键字一样公开它们。因此,您应该使用api而不是implementation

请参阅文档中的更多详细信息。

最新更新