'Implementing latest version of JCIFS

Trying to update my app from jcifs-1.3.19 to the latest jcifs-2.1.29 I have changed the appropriate code, adding the "necessary" jars to build.gradle

<see answer below>

but keep getting the same error Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/bouncycastle/asn1/ASN1ObjectIdentifier;

Found a number of references, implemented their suggested solutions to no avail. What is missing??

java -version java version "18.0.1" 2022-04-19 Java(TM) SE Runtime Environment (build 18.0.1+10-24) Java HotSpot(TM) 64-Bit Server VM (build 18.0.1+10-24, mixed mode, sharing)

JAVA_HOME=C:\Program Files\Common Files\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;
}

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

Additional: https://www.baeldung.com/java-bouncy-castle



Solution 1:[1]

Now working with the following added into 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'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Theo