I’m trying to use Cloudinary with my android application, I built a test class to try to upload one file, but I’m getting the error below:
Estou tentando usar Cloudinary uma aplicação android, eu criei uma classe de teste para tentar fazer upload de um arquivo, mas esta retornando a expeception abaixo:
java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpRequestBase
Minha classe java
import com.cloudinary.Cloudinary;
import com.cloudinary.Transformation;
import com.cloudinary.utils.ObjectUtils;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* Created by 16110066 on 21/07/2017.
*/
public class cloudUtil {
public static void main(String args[]) throws IOException {
try {
configCloud();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void configCloud() throws IOException {
Map config = new HashMap<>();
config.put("cloud_name","euqueropucrs");
config.put("api_key","219569379885948");
config.put("api_secret","My secret was here");
Cloudinary cloudinary = new Cloudinary(config);
Map imageResult = cloudinary.uploader().upload("C:\\git\\Trocas\\app\\src\\main\\res\\drawable\\ic_menu_gallery.xml",ObjectUtils.emptyMap());
System.out.println(imageResult.toString());
}
}
Meu Gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias '15109336'
keyPassword '15109336'
storeFile file('/home/ricardo/.android/debug.keystore')
storePassword '15109336'
}
}
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.cassiotrindade.trocas"
minSdkVersion 21
multiDexEnabled true
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support:support-v4:26.+'
compile 'com.android.support:design:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:recyclerview-v7:26.+'
compile 'com.google.code.findbugs:jsr305:2.0.1'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'
compile 'com.google.android.gms:play-services:11.0.2'
compile 'com.google.android.gms:play-services-auth:11.0.2'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.1'
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile (group: 'com.cloudinary', name: 'cloudinary-http44', version: '1.14.0')
compile group: 'com.cloudinary', name: 'cloudinary-core', version: '1.13.0'
//Imagepicker
compile 'com.github.bumptech.glide:glide:3.7.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
Exception inteira
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpRequestBase
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.cloudinary.strategies.StrategyLoader.load(StrategyLoader.java:11)
at com.cloudinary.strategies.StrategyLoader.find(StrategyLoader.java:20)
at com.cloudinary.Cloudinary.loadStrategies(Cloudinary.java:78)
at com.cloudinary.Cloudinary.<init>(Cloudinary.java:92)
at com.example.cassiotrindade.trocas.utility.cloudUtil.configCloud(cloudUtil.java:29)
at com.example.cassiotrindade.trocas.utility.cloudUtil.main(cloudUtil.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpRequestBase
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 13 more
Edit:
Adicionei mais uma linha ao gradle
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
E retorna este erro
Exception in thread "main" java.lang.UnknownError: Can't find Cloudinary platform adapter [com.cloudinary.android.UploaderStrategy,com.cloudinary.http42.UploaderStrategy,com.cloudinary.http43.UploaderStrategy,com.cloudinary.http44.UploaderStrategy]
at com.cloudinary.Cloudinary.loadStrategies(Cloudinary.java:81)
at com.cloudinary.Cloudinary.<init>(Cloudinary.java:92)
at com.example.cassiotrindade.trocas.utility.cloudUtil.configCloud(cloudUtil.java:29)
at com.example.cassiotrindade.trocas.utility.cloudUtil.main(cloudUtil.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Process finished with exit code 1