I am using Apache Commons Net to download files through FTPClient. There is no problem when using version 3.8.0.
But after upgrading to 3.9.0 the app crashing on instantiating the FTPClient with the below stacktrace:
E FATAL EXCEPTION: main
Process: com.mozyn.android.example, PID: 14556
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/Duration;
at org.apache.commons.net.ftp.FTPClient.<init>(FTPClient.java:544)
at com.mozyn.android.example.services.DownloadService$startMyDownloadService$1$1$1$downloadResult$1.invokeSuspend(DownloadService.kt:188)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@aa100d1, Dispatchers.Main]
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.Duration" on path: DexPathList[[zip file "/data/app/com.mozyn.android.example-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mozyn.android.example-1/lib/x86_64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 10 more
Suppressed: java.lang.ClassNotFoundException: java.time.Duration
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 11 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
The DownloadService.kt:188 points to the constructor onf FTPClient(), while FTPClient.java:544 points to private Duration controlKeepAliveTimeout = Duration.ZERO;.
Also noticed that the constructor of the FTPClient in 3.9.0 version uses java.time API which is supported in API 26+.
Dependency used:
implementation("commons-net:commons-net:3.9.0")
Is there anyway to upgrade to 3.9.0 version or just stuck with the 3.8.0 version for supporting Android 7 and below?
Thanks!