Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
I have an application that i have not needed to update since moving to API v2 in 2017. Due to google enforcing a minimum targetSDK i have made modifications and the project now meets the target and is backward compatible to API 8 in eclipse.
I am trying now to migrate the eclipse project over to ADS. I have to admit that I have no prior experience until the last few days of ADS and gradle, so please be gentle!
when i build my app i am getting the following error
cannot access OkHttpClient class file for com.squareup.okhttp.OkHttpClient not found
C:\test\testproject\src\main\java\com\dropbox\core\examples\android\PicassoClient.java:19: error: cannot access OkHttpClient
.downloader(new OkHttpDownloader(context))
i have the .jar file for okhttp in libs folder (same files that build ok with eclipse).
i have tried adding dependency so gradle downloads but it fails to find it.
implementation 'com.squareup.okhttp3:3.8.1'
and
implementation 'com.squareup.okhttp3:3.0.1'
Any help would be appreciated.
my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "29.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.test.testproject"
minSdkVersion 14
targetSdkVersion 28
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
implementation files('libs/okio-1.13.0.jar')
implementation files('libs/okhttp-3.8.1.jar')
//implementation 'com.squareup.okhttp3:3.8.1'
implementation files('libs/picasso-2.5.2.jar')
implementation files('libs/dropbox-android-sdk.jar')
implementation files('libs/dropbox-core-sdk-3.0.3.jar')
implementation files('libs/httpmime-4.0.3.jar')
implementation files('libs/jackson-core-2.7.4.jar')
implementation files('libs/json_simple-1.1.jar')
implementation fileTree(dir: 'C:\\android\\support\\v7\\appcompat\\libs', include: ['*.aar', '*.jar'], exclude: [])
}
It looks like you're trying to load the Dropbox SDK and dependencies directly from jar files yourself. I recommend just letting Gradle handle all of this though, by listing Dropbox as a dependency as shown here, like this:
implementation 'com.dropbox.core:dropbox-core-sdk:3.1.3'
That should take care of downloading the Dropbox library and its dependencies for you. That way you don't have to include all of them yourself. (Either way, you shouldn't have 'dropbox-android-sdk', as that's an old and now retired SDK.)
changed dependencies
//implementation files('libs/okio-1.13.0.jar')
//implementation files('libs/okhttp-3.8.1.jar')
//implementation 'com.squareup.okhttp3:3.0.1'
//implementation files('libs/picasso-2.5.2.jar')
implementation 'com.dropbox.core:dropbox-core-sdk:3.1.3'
//implementation files('libs/dropbox-android-sdk.jar')
//implementation files('libs/dropbox-core-sdk-3.0.3.jar')
implementation files('libs/httpmime-4.0.3.jar')
implementation files('libs/jackson-core-2.7.4.jar')
implementation files('libs/json_simple-1.1.jar')
now i get
and
C:\test\testproject\src\main\java\com\dropbox\core\examples\android\DropboxClientFactory.java:18: error: cannot access OkHttpClient
.withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient()))
^
class file for okhttp3.OkHttpClient not found
C:\test\testproject\src\main\java\com\dropbox\core\examples\android\PicassoClient.java:19: error: cannot access OkHttpClient
.downloader(new OkHttpDownloader(context))
^
class file for com.squareup.okhttp.OkHttpClient not found
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
Not sure if relevant but, when i look at the PicassoClient.java source
it is telling me the following imports are unused. Has there been compiler change? It is not detecting the usage of OkHttpDownloader.
import com.squareup.picasso.OkHttpDownloader;
import com.squareup.picasso.Picasso;
package com.dropbox.core.examples.android;
import android.content.Context;
import com.dropbox.core.v2.DbxClientV2;
import com.squareup.picasso.OkHttpDownloader;
import com.squareup.picasso.Picasso;
/**
* Singleton instance of Picasso pre-configured
*/
public class PicassoClient {
private static Picasso sPicasso;
public static void init(Context context, DbxClientV2 dbxClient) {
// Configure picasso to know about special thumbnail requests
sPicasso = new Picasso.Builder(context)
.downloader(new OkHttpDownloader(context))
.addRequestHandler(new FileThumbnailRequestHandler(dbxClient))
.build();
}
public static Picasso getPicasso() {
return sPicasso;
}
}
Apologies, I should have pointed out OKHttp in particular is a bit of a special case here, since it's considered optional when using the SDK. I see you're trying to use the Android example app though, which does use OKHttp, so you'll want to include that dependency. There's a note about this here:
in my application i import the example and use DropboxClientFactory.getClient() etc....
import com.dropbox.core.examples.android.*;
I now have the following dependencies, I have tried it with or without { implementation 'com.squareup.okhttp3:okhttp:3.11.0' }
dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.dropbox.core:dropbox-core-sdk:3.1.3'
api 'com.squareup.okhttp3:okhttp:3.11.0'
still getting the error.
cannot access OkHttClient class file for com.squareup.okhttp.OkHttpClient not found
I'm not sure I understand your current setup. To clarify, are you trying to import the official Android example for the Dropbox Java SDK into your own third party application? That's just intended as a sample, and not something you would import into your own app. You can follow the instructions here to build and run that example app itself. I recommend trying to do so as a test of your development environment, unrelated to your own app.
Though note that when you do so, it's probably easier to just install a released version of the Dropbox SDK rather than compile it locally (as the example is configured to do by default), as long as you don't need to make changes to the Dropbox SDK. That is, in the sample's build.gradle, replace:
implementation group: 'com.dropbox.core', name: 'dropbox-core-sdk', version: '0-SNAPSHOT', changing: true
with:
implementation 'com.dropbox.core:dropbox-core-sdk:3.1.3'
It would likely be helpful to see if Android Studio can build and run that for you as a validation of your Android Studio environment.
I got my app to build in ADS, even though i did not actually resolve the problem.
The problem reported was with the PicssoClient.java as posted above, I was not actually using it, so removed and the App built ok
I think I will have to try to make a new project with the example files to see if I can build it.
So I created a new project with ADS, added the dropbox java files. added the dependencies to the build.gradle.
I get the same build error, that I get with my App.
Project contains empty activity and code from example dropbox project.
link to zip of project folder
It looks like you're actually using old code, from before this change in 2018 (and maybe are mixing old code with new dependencies, or vice versa?). In any case, please use the latest version of the Dropbox library, sample code, and dependencies for compatibility.
The latest release of the Dropbox Java library itself is currently v3.1.3, and you can find the example Android app and instructions here, including the build.gradle listing the dependencies for the latest version of the example app.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!