Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception trying to execute Android App from Eclipse To Android Studio

I have tried to migrate an Eclipse Android project to Android Studio, I have tried both ways, open directly from Android Studio and migrating to Gradle in Eclipse first and then open it in Android Studio.

Then I have tried to remove the Google Play library folder and added it in my Gradle file, and then the project do this:

  • Make Project OK
  • Clean Project OK
  • Rebuild Project OK
  • Gradle sync and download a lot of DLL OK
  • Play or Debug KO and gives me this errors:

Error:Execution failed for task ':goSmart.guestperience.MoncloaDeSanLazaro:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

OR

Error:Execution failed for task ':goSmart.guestperience.MoncloaDeSanLazaro:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

OR

Error:Execution failed for task ':goSmart.guestperience.MoncloaDeSanLazaro:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

I have started with JDK 1.6, then updated to 1.7 and then to 1.8 to see if that was the problem.

If I don't delete the Google Play Dervices folders the project works just fine.

I'm using a MAC if that is important.

And if that matter to solve this problem, I'm having this other problem in my project posted in stack overflow.

This is how it looks my project structure:

enter image description here

And this are the build.grade files of all the projects

Main warper project (guestperience 1.0.1 Moncloa De San Lazaro):

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.0'
    }
}

goSmart.guestperience.MoncloaDeSanLazaro (this is where I code):

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':librarySmartHotel')
    compile 'com.google.android.gms:play-services:7.3.0'
}

android {
    compileSdkVersion 16
    buildToolsVersion "22.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

librarySmartHotel:

apply plugin: 'com.android.library'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':main')
}

android {
    compileSdkVersion 16
    buildToolsVersion '22.0.1'

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

main:

apply plugin: 'com.android.library'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 16
    buildToolsVersion '22.0.1'

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

I'm thinking that some configuration is missing (maybe), the true is that I'm super lost.

I'm an iOS programmer and this are my first steps in Android, the project has been done by another guy, and now I'm supposed to continue, so let's say I'm having a good fight with Android Studio and it looks that I'm loosing ;-P

Thanks for the help.

UPDATE:

I have found this in the log:

AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"} AGPBI: {"kind":"SIMPLE","text":"com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/analytics/internal/Command$1;","position":{},"original":"com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/analytics/internal/Command$1;"} AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)","position":{},"original":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)"} AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)","position":{},"original":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)"} AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)"} AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)"} AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)","position":{},"original":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)"} AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)","position":{},"original":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)"} AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)","position":{},"original":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)"} AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:246)","position":{},"original":"\tat com.android.dx.command.dexer.Main.run(Main.java:246)"} AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:215)","position":{},"original":"\tat com.android.dx.command.dexer.Main.main(Main.java:215)"} AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.Main.main(Main.java:106)","position":{},"original":"\tat com.android.dx.command.Main.main(Main.java:106)"}

like image 590
Stornu2 Avatar asked May 04 '15 07:05

Stornu2


People also ask

How to migrate project to Gradle Android Studio?

Launch Android Studio, and click File > New > Import Project. Locate your project directory, click the build. gradle file you created above to select it, and then click OK to import your project.

How to import zip project in Android Studio?

Open Android Studio and select Open an Existing Android Studio Project or File, Open. Locate the folder you downloaded from Dropsource and unzipped, choosing the “build. gradle” file in the root directory. Android Studio will import the project.

Can I use Eclipse instead of Android studio?

Android Studio is faster than Eclipse. There is no need to add a plugin to Android Studio but if we use Eclipse then we do need to. Eclipse needs many resources to start but Android Studio does not. Android Studio is based on IntelliJ's Idea Java IDE and Eclipse uses the ADT Plugin to develop Android applications.


4 Answers

The problem come from Android Play Services 7.3.0.

Try :

dependencies {
    compile 'com.google.android.gms:play-services:6.5.87'
}

or enable multiDex:

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 19
    versionCode 1
    versionName versionNameVar
    multiDexEnabled true
}

(multiDex solution compile, but might crash at app launch)

like image 191
Livio Avatar answered Nov 15 '22 07:11

Livio


After hours with the same problem i found the answer.

The REAL problem is that you have multiple libs with the same classes inside, so the solution would be to either remove the repeating files from one of the libs.

You have to either remove the libs with repeating files or:

  1. Open the lib libGoogleAnalyticsServices.jar with WinRAR, 7Zip or whatever.
  2. Go to com/google/android/gms/analytics/internal and delete the files Command$1.class and Command.class.

In your case you may have to remove other repeating files, not sure because you have many files. Either way, you can also force it to ignore some of those files IF the method above didn't work. Put the following code inside the Android block on your build.gradle file:

defaultConfig {
    multiDexEnabled true
}

dexOptions {
    preDexLibraries = false
}
like image 32
George Avatar answered Nov 15 '22 07:11

George


In my case I just had to delete the old library.

like image 30
DoruChidean Avatar answered Nov 15 '22 08:11

DoruChidean


Try always compile with latest version of google play

try this : compile 'com.google.android.gms:play-services:8.1.0'

from : Setting up google play services

like image 32
AITAALI_ABDERRAHMANE Avatar answered Nov 15 '22 06:11

AITAALI_ABDERRAHMANE