I am trying to make a File List from my SMB Shared Folder with Android Studio.
I want to press a Button in my Android App and then get the List stored as *.txt
in my root or SD Card Root.
I am using Android Studio API Version Level 30 and SMBJ Library.
But I'm failing in connection for my SMB Share.
When I press the button with the code its crashing without giving a Message on my Samsung Galaxy S20.
I found that the crash happens on following 2 lines:
AuthenticationContext ac = new AuthenticationContext("admin", "password123".toCharArray(),null);
Session session = connection.authenticate(ac);
I am not sure if I need the domain.
I have no domain installed and tried some different things.
SMBClient client = new SMBClient();
try {
Connection connection = client.connect("192.168.1.75");
AuthenticationContext ac = new AuthenticationContext("admin", "password123".toCharArray(),null);
Session session = connection.authenticate(ac);
//DiskShare share = (DiskShare) session.connectShare("Intel");
} catch (Exception e) {
txt.setText(e.toString());
}
The following is from the SMBJ Website on GIT: https://github.com/hierynomus/smbj
SMBClient client = new SMBClient();
try (Connection connection = client.connect("SERVERNAME")) {
AuthenticationContext ac = new AuthenticationContext("USERNAME", "PASSWORD".toCharArray(), "DOMAIN");
Session session = connection.authenticate(ac);
// Connect to Share
try (DiskShare share = (DiskShare) session.connectShare("SHARENAME")) {
for (FileIdBothDirectoryInformation f : share.list("FOLDER", "*.TXT")) {
System.out.println("File : " + f.getFileName());
}
}
}
This is the error log I get:
2022-04-25 11:45:27.475 22865-22865/com.example.filme E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.filme, PID: 22865
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/slf4j/LoggerFactory;
at com.hierynomus.smbj.SMBClient.<clinit>(SMBClient.java:119)
at com.example.filme.MainActivity$1.onClick(MainActivity.java:36)
at android.view.View.performClick(View.java:7792)
at android.widget.TextView.performClick(TextView.java:16112)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View.performClickInternal(View.java:7769)
at android.view.View.access$3800(View.java:910)
at android.view.View$PerformClick.run(View.java:30213)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.slf4j.LoggerFactory" on path: DexPathList[[dex file "/data/data/com.example.filme/code_cache/.overlay/base.apk/classes3.dex", dex file "/data/data/com.example.filme/code_cache/.overlay/base.apk/classes.dex", zip file "/data/app/~~SMMMBpkYv1Fu0fT2H1M_sA==/com.example.filme-ovE-fLeCY69AhQvQzyn1cA==/base.apk"],nativeLibraryDirectories=[/data/app/~~SMMMBpkYv1Fu0fT2H1M_sA==/com.example.filme-ovE-fLeCY69AhQvQzyn1cA==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:218)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.hierynomus.smbj.SMBClient.<clinit>(SMBClient.java:119)
at com.example.filme.MainActivity$1.onClick(MainActivity.java:36)
at android.view.View.performClick(View.java:7792)
at android.widget.TextView.performClick(TextView.java:16112)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1119)
at android.view.View.performClickInternal(View.java:7769)
at android.view.View.access$3800(View.java:910)
at android.view.View$PerformClick.run(View.java:30213)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8663)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
2022-04-25 11:45:27.518 22865-22865/com.example.filme I/Process: Sending signal. PID: 22865 SIG: 9
tried to install library slf4j-android-1.7.9.jar but dont works for now.
Edit 12:46 o clock:
I added now many libraries and now its going close to work but not fully.
No library is missing but the following error occurs:
android.os.NetworkOnMainThreadException error
I read that I must do asynchronous processing.
But I'm too stupid to write this asynchronous code.. can anyone help?
Now its working.
I needed following LIBRARIES:
asn-one-0.6.0.jar bcprov-jdk15on-1.70.jar mbassador-1.3.2.jar slf4j-api-1.7.9.jar slf4j-nop-1.7.9.jar smbj-0.11.5.jar