filestack-java icon indicating copy to clipboard operation
filestack-java copied to clipboard

NoClassDefFoundError in com.filestack.internal.Networking

Open jagged91 opened this issue 7 years ago • 7 comments

This is in an Android app running in debug (i.e. no proguard/obfuscation). The client is unable to initialize. Here's the stacktrace:

java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread. at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.NoClassDefFoundError: com.filestack.internal.Networking at com.filestack.internal.Networking.getCdnService(Networking.java:87) at com.filestack.Client.<init>(Client.java:48) at com.myapp.app.support.DatabaseArchiver$uploadArchive$1.call(DatabaseArchiver.kt:172) at com.myapp.app.support.DatabaseArchiver$uploadArchive$1.call(DatabaseArchiver.kt:47) at rx.internal.operators.OnSubscribeFromCallable.call(OnSubscribeFromCallable.java:48) at rx.internal.operators.OnSubscribeFromCallable.call(OnSubscribeFromCallable.java:33) at rx.Observable.unsafeSubscribe(Observable.java:10150) at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94) at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:228) at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.ExceptionInInitializerError at com.filestack.internal.Networking.getCdnService(Networking.java:87) at com.filestack.Client.<init>(Client.java:48) at com.myapp.api.sync.SyncService$SyncAdapter.onPerformSync(SyncService.java:153) at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:321) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.InputStream java.lang.ClassLoader.getResourceAsStream(java.lang.String)' on a null object reference at com.filestack.internal.Util.getVersion(Util.java:30) at com.filestack.internal.HeaderInterceptor.<init>(HeaderInterceptor.java:22) at com.filestack.internal.Networking.buildOkHtttpClient(Networking.java:33) at com.filestack.internal.Networking.<clinit>(Networking.java:29) at com.filestack.internal.Networking.getCdnService(Networking.java:87) at com.filestack.Client.<init>(Client.java:48) at com.myapp.api.sync.SyncService$SyncAdapter.onPerformSync(SyncService.java:153) at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:321)

I'm using OKHTTP 3.11.0 currently - could this be why?

jagged91 avatar Oct 15 '18 14:10 jagged91

Just tested with an older version of OKHTTP (3.9.0) and still have the same issue.

jagged91 avatar Oct 15 '18 14:10 jagged91

Hey @jgadsby, do you use Filestack SDK inside of a SyncAdapter? Is this 0.9.0 version? Would you mind trying 0.8.2?

Caused by: java.lang.NullPointerException: 
Attempt to invoke virtual method 'java.io.InputStream
java.lang.ClassLoader.getResourceAsStream(java.lang.String)' on a null object reference at
com.filestack.internal.Util.getVersion(Util.java:30) at 

I see that there is some issue with acquiring the SDK version from system resources. This is not really necessary for us to do and it might be the cause of the problem. I don't really think that the OkHttp version has anything to do with it (fortunately :))

scana avatar Oct 15 '18 15:10 scana

So, I tried 0.8.2 and the exception seems to disappear, but there's still something going wrong - when I place a log statement right after the client is created, the log statement is never called.

Log.d("FileStackHandler", "Creating client...")
    // Create a Filestack client
    val config = Config("<API KEY>")
    val client = Client(config)
    Log.d("FileStackHandler", "Created client")

jagged91 avatar Oct 15 '18 16:10 jagged91

Anyway, it doesn't matter right now as I'm unable to get the response via the library (see the other issue - https://github.com/filestack/filestack-java/issues/81). A slightly unrelated question: When I try to upload a file via the FileStack API and OKHTTP directly, I always get 'unexpected end of stream'. Any idea why?

Some more details:

Part of the code for the image + filestack endpoint:

          val fileName = "${image.id}_${System.currentTimeMillis()}"
          val URL = "https://www.filestackapi.com/api/store/S3?key=<key>&mimetype=image/jpeg&filename=$fileName"

          val bitmap = MediaStore.Images.Media.getBitmap(provider.context.contentResolver, image.bitmapUri)

          val contentLength = BitmapCompat.getAllocationByteCount(bitmap).toLong()

jagged91 avatar Oct 15 '18 16:10 jagged91

Never mind - I figured out the OKHTTP upload issue. I needed to provide the following to my OkHttpClient.Builder:

.pingInterval(1, TimeUnit.SECONDS) .writeTimeout(60L, TimeUnit.SECONDS)

jagged91 avatar Oct 15 '18 17:10 jagged91

So, I tried 0.8.2 and the exception seems to disappear, but there's still something going wrong - when I place a log statement right after the client is created, the log statement is never called.

Log.d("FileStackHandler", "Creating client...")
    // Create a Filestack client
    val config = Config("<API KEY>")
    val client = Client(config)
    Log.d("FileStackHandler", "Created client")

Does this issue still exists? Also - do you instantiate and use Client class inside of a SyncAdapter?

scana avatar Oct 15 '18 19:10 scana

Also - do you instantiate and use Client class inside of a SyncAdapter?

Yep!

jagged91 avatar Oct 17 '18 18:10 jagged91