1

because of a high priority security fix in cordova for android we need to update our cordova version (from 2.7.0 to 3.6.3) in our app. So we thought it would be better to create a new project.

I installed cordova and create a project with cordova cli api. Also I added the android platform added many cordova plugins. Then I copied our sencha touch stuff into the www folder.

Then I called cordova build android.

After that I imported this android project in Android Studio (0.8.11).

For our app I needed to copy the following things from our old project

  • AndroidManifest.xml
  • All the stuff out of the res/ directory
  • in the src/ directory I added some stuff we need in our app

In our own written java files (src/ directory) everything was red. So we found out that in src/org.apache.cordova/ that there were only directories of the installed cordova plugins. So I downloaded cordova 3.6.X (from https://github.com/apache/cordova-android/tree/3.6.x) and copied all java files to src/org/apache/cordava.

Then I recognized that the android-support android-support-v13.jar library was missing in the lib/ folder. So I copied it out of the sdk\extras\android\support\v13 directory. After that nearly all red stuff in the code disappeared, so I tried to run it.

But I'm getting this error:

Error:Execution failed for task ':dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Develop\Android SDK\sdk\build-tools\19.1.0\dx.bat --dex --output D:\www\xxx\native\cordova-project\platforms\android\build\intermediates\dex\debug D:\www\DiLocSyncMobile\native\cordova-project\platforms\android\build\intermediates\classes\debug D:\www\xxx\native\cordova-project\platforms\android\build\intermediates\dependency-cache\debug D:\www\xxx\native\cordova-project\platforms\android\build\intermediates\pre-dexed\debug\android-support-v13-ba93a882b9b887c9c56ff93adba54cb3616bd827.jar D:\www\xxx\native\cordova-project\platforms\android\build\intermediates\pre-dexed\debug\classes-0236632443c0351e54fca9912536c8c02b5ad2b2.jar
Error Code:
    2
Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/App$1;
        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)

My build.gradlefile is has got the following dependencies:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    for (subproject in getProjectList()) {
        compile project(subproject)
    }
}

In my lib/ directory is just the jar I added manually.

Please help me/ Thanks ahead!! :-)

mbo
  • 64
  • 2
  • 10
  • Check : http://stackoverflow.com/questions/22315834/android-unable-to-execute-dex-multiple-dex-files-define or http://stackoverflow.com/questions/7870265/unable-to-execute-dex-multiple-dex-files-define-lcom-myapp-rarray – Haresh Chhelana Oct 10 '14 at 12:55
  • Check thoroughly, this error because you are getting reference of same thing from more than one jars. – khurram Oct 10 '14 at 12:56
  • Thanks, I found out what my problem was: It was because I copied the cordova java files into src/com/apache/cordova/ ... They already exist in /CordovaLib/... No the app is getting compiled, but I'm getting all the time the error: "Cordova exec fail: Class not found" and in my java files I've got errors like "Cannot resolve symbol CordovaPlugin" – mbo Oct 14 '14 at 15:02

1 Answers1

1

That error occurs when you have more than one reference to the same class in the same package.

For example you might have a class:

com.android.foo.bar.GenericClass

And then you have two jars:

tools_library.jar

more_tools_library.jar

And they both need the "GenericClass" - but one uses a different version of the class from another. In pseudo code, you might think of it like:

tools_library.jar:com.android.foo.bar.GenericClass != more_tools_library.jar:com.android.foo.bar.GenericClass

and you need it to be:

tools_library.jar:com.android.foo.bar.GenericClass == more_tools_library.jar:com.android.foo.bar.GenericClass

A common cause of this problem is using two different versions of a package like android-support-v13.jar or android-support-v4.jar which has happened to me more than few times.

It can also happen if one of the jars includes an old version of android-support-v4.jar and you need a newer version or android-support-v13.jar

While this may not specifically answer your question (there isn't enough information to figure out which specific jar or class is causing the conflict), I thought it might at least be helpful to provide a more descriptive explanation of the error compared to "Unable to execute dex" - which took me a long time to decrypt when I first saw it.

Jim
  • 10,172
  • 1
  • 27
  • 36
  • Thanks, I found out what my problem was: It was because I copied the cordova java files into src/com/apache/cordova/ ... They already exist in /CordovaLib/... No the app is getting compiled, but I'm getting all the time the error: "Cordova exec fail: Class not found" and in my java files I've got errors like "Cannot resolve symbol CordovaPlugin" – mbo Oct 14 '14 at 13:34