Reputation: 93
I'm working with the koush/ion library that I use it for get a JSON from a url, the problem is that when I'm trying to run my app it throws this
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/android-4.4W/dx --dex --num-threads=4 --output
/Users/Ger/Desktop/Slide/app/build/intermediates/dex/debug
/Users/Ger/Desktop/Slide/app/build/intermediates/classes/debug
/Users/Ger/Desktop/Slide/app/build/intermediates/dependency-cache/debug
/Users/Ger/Desktop/Slide/app/build/intermediates/pre-dexed/debug/androidasync-1.3.8-a258b3b9f5350460cf9a1a47d3844ac30e9c5eba.jar
/Users/Ger/Desktop/Slide/app/build/intermediates/pre-dexed/debug/gson-2.2-3174cdb2bcc21df781020dd287f6d8f9b30fbcf4.jar
/Users/Ger/Desktop/Slide/app/build/intermediates/pre-dexed/debug/gson-2.3-2c927fa37b669aaa0ff9991dd7c990e2d88a7487.jar
/Users/Ger/Desktop/Slide/app/build/intermediates/pre-dexed/debug/ion-1.3.8-df2772cd07adc55daba28b3d0ce1374cf5a4edd5.jar
/Users/Ger/Desktop/Slide/app/build/intermediates/pre-dexed/debug/support-v4-18.0.0-2484d88715cbcdaf306e7f8449d6546e84c1520d.jar
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/gson/JsonSerializer;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
And this is my code:
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;
public class NuevosEpisodios extends Activity {
String resultado = "A";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.temporada);
TextView tv = (TextView) findViewById(R.id.descripcion_temp);
Ion.with(NuevosEpisodios.this)
.load("http://example.com/thing.json")
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
// do stuff with the result or error
Gson gson = new Gson();
resultado = gson.toJson(result);
}
});
tv.setText(resultado);
}
}
I've seen many answers to this problem but no one worked for me, please give me a hand I have the gson-2.2 and the koush/ion jar in my lib folder, both of them are compiled in my build gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:18.0.+'
compile 'com.koushikdutta.ion:ion:1.+'
compile files('libs/gson-2.2.jar')
}
Thanks in advanced!
Upvotes: 0
Views: 1821
Reputation: 80020
When I duplicate your dependencies
block inside a test project, I don't get your error. I think you have an extra jar file inside your libs directory that's causing the problem. This statement in your build file:
compile fileTree(dir: 'libs', include: ['*.jar'])
makes it automatically pick up any .jar files you put in that directory, so see if you have something in there you don't need. At any rate, with that wildcard include, this statement is redundant:
compile files('libs/gson-2.2.jar')
Also, instead of downloading GSON's jar and putting it manually into your libs directory, you can have it automatically download and manage it the same as you do for the com.koushikdutta.ion:ion
dependency:
compile 'com.google.code.gson:gson:2.2'
There are newer versions of this library than 2.2; you might want to consider upgrading. http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.google.code.gson%22%20AND%20a%3A%22gson%22
Upvotes: 2