尝试将我的应用程序从jcifs-1.3.19更新到最新的jcifs-2.1.29,我更改了适当的代码,将“必要的”jars添加到build.gradle中。
<see answer below>
但继续得到相同的错误,由: java.lang.NoClassDefFoundError:失败的决议:罗格/赏金城堡/asn1 1/asn1 1对象标识符;
找到了一些参考资料,实施了他们提出的解决方案,但没有效果。少了什么??
Java -version java版本"18.0.1“2022-04-19 Java(TM) SE运行时环境(build 18.0.1+10-24) java HotSpot(TM) 64位服务器VM (build 18.0.1+10-24,混合模式,共享)
JAVA_HOME=C:\Program文件\公共文件\Oracle\Java\javapath
Android Studio Gradle:
// implementation files('libs/jcifs-1.3.19.jar') moving from V1 to V2
implementation files('libs/jcifs-2.1.29.jar')
implementation files('libs/bcprov-jdk18on-171')
implementation files('libs/bcutil-jdk18on-171')
implementation files('libs/slf4j-api-1.7.30.jar')
public CIFSContext getcredentials(String user, String password){
NtlmPasswordAuthenticator sourceAuth = new NtlmPasswordAuthenticator("",
user, password);
Properties properties = new Properties();
properties.setProperty("jcifs.smb.client.responseTimeout", "5000");
PropertyConfiguration configuration = null;
try {
configuration = new PropertyConfiguration(properties);
} catch (CIFSException e) {
e.printStackTrace();
}
CIFSContext cifsContext = new BaseContext(configuration).withCredentials(sourceAuth);
return cifsContext;
}
连接到pc的代码:
String username = getusername();
String password= getpassword();
CIFSContext cifsContext = general.getcredentials(username,password );
String[] shares;
sharelist.clear();
try {
SmbFile server = new SmbFile("smb://" + ip, cifsContext); // value for server: "smb://192.168.0.38"
if( server.exists()) { // yes as it continues
try {
shares = server.list(); // this is where it crashes Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/bouncycastle/asn1/ASN1ObjectIdentifier;
for (String s : shares) {
if (!s.contains("$")) {
sharelist.add(s);
op.success = true;
}
// System.out.println(s);
}
} catch (SmbException e) {
e.printStackTrace();
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
op.an_error=e.getMessage().toString();
} catch (SmbException e) {
e.printStackTrace();
op.an_error=e.getMessage().toString();
}
发布于 2022-05-11 14:33:36
现在使用添加到build.gradle中的以下内容:
implementation files('libs/jcifs-2.1.29.jar')
implementation files('libs/slf4j-api-1.7.30.jar')
implementation 'org.bouncycastle:bcprov-jdk15on:1.68'
https://stackoverflow.com/questions/72068321
复制相似问题