1

I have an old Android project made with Eclipse ADT and I'm trying to migrate it to Android Studio. I follow several guides and howtos and maybe I have almost migrated it.

When I try to build it I get the following error:

Error:Error converting bytecode to dex:Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

I have read a lot of solutions but none seems to suit to my problem. But maybe this answer is for my case...

Here is the Project status in Eclipse project explorer:

enter image description here

and here is the migrated Project in Android Studio project view:

enter image description here

Maybe the problem is the dependencies property of every gradle script:

app-app:

dependencies {
    compile project(':androidsupportv7appcompat')
    compile project(':library')
    compile files('libs/android-support-v4.jar')
}

androidsupportv7appcompat:

dependencies {
    compile files('libs/android-support-v4.jar')
    compile files('libs/android-support-v7-appcompat.jar')
}

googleplayservice_lib:

dependencies {
    compile files('libs/google-play-services.jar')
}

library: (a Google Maps library for markers clustering)

dependencies {
    compile project(':googleplayservices_lib')
    compile files('libs/android-support-v4.jar')
}

Do you know if something could be wrong in these dependencies configurations? Otherwise, what could be the cause?

Community
  • 1
  • 1
smartmouse
  • 13,912
  • 34
  • 100
  • 166

2 Answers2

1

First of all, you should remove the Support Library module from your Android Studio project. Instead add a dependency to your apps gradle build file. If your library uses components from the support library, its build file should have the proper dependencies also.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:support-v4:25.3.1'
}

Be sure to remove the Support Library JAR files from your lib's folder.

Similarly you should add a dependency for Google Play Services.

Dependency management with Gradle is one of the many advantages of moving to Android Studio. If the library module is not written by you, you should also find the correct take dependency to add to your build file instead of the module you have now.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • I have removed 3 modules under "Gradle scripts": `androidsupportv7appcompat`, `googleplayservices_lib` and `library`. I also removed `android-support-v4.jar` from `libs` folder. Then I edit `build.gradle` file in this way: https://pastebin.com/0Q54unGL. I'm still getting 211 errors, mostly like this **error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button'.**. How to fix it? PS: How do I remove the 3 folders unders "app-app" in project view of Android Studio? I can't see a remove button... – smartmouse Apr 17 '17 at 16:04
  • @smartmouse The folders with blue squares are also known as modules in Android Studio. The only modules you should have in your project is for code you have written yourself. You should also not download JAR files manually. You should remove all of them which you transferred from your Eclipse project. Instead, you should replace all third-party modules and JAR files with appropriate dependency declarations in your build.gradle file. – Code-Apprentice Apr 17 '17 at 16:24
  • @smartmouse What folders are in app-app? – Code-Apprentice Apr 17 '17 at 16:28
  • @smartmouse You should set `compileSdkVersion` to 25 instead of 19. Generally, you should compile with the most recent SDK. Also update the support library dependencies to the newest version as shown in answer. – Code-Apprentice Apr 17 '17 at 16:31
  • I think I have fixed all errors. But since I set an higher version of SDK a lot of class are deprecated, such as `NameValuePair`. Please stay tuned, I'm going to update you in few minutes... thank you – smartmouse Apr 17 '17 at 17:08
  • I solved all errors. Here is my `build.gradle` content: https://pastebin.com/udStRdAc. Please give me a feedback about this. As you can see I had to set some old versions because of too much deprecated code in my project (that I will gradually update). Thank you so much for your reply that make me open eyes on how Gradle works. – smartmouse Apr 17 '17 at 17:58
  • Ehm... ActionBar disappears... http://stackoverflow.com/questions/43457407/migrate-from-eclipse-to-android-studio-actionbar-disappears. Do you know why? – smartmouse Apr 17 '17 at 18:38
  • @smartmouse You can safely ignored deprecation warnings for now. Your app will still compile and run. You can figure out the correct alternatives after you get everything working. – Code-Apprentice Apr 17 '17 at 19:18
  • Unfortunately it wasn't so easy... since I had to turn min sdk to 25 some methods have been removed! Anyway it seems that I'm solving... thank you so much for your great support, I really appreciate it. – smartmouse Apr 17 '17 at 22:46
-1

in one of my old projects, I had to put this in the gradle file under app section

multiDexEnabled true in the default config and then add the dex options below... maybe this will help.

defaultConfig { 
    applicationId "xxx"
    minSdkVersion 14
    targetSdkVersion 24
    versionCode 4
    versionName "2.2"
    multiDexEnabled true   
}

dexOptions {
    javaMaxHeapSize "2g"
}