尝试从Eclipse到Android Studio执行Android应用程序的异常

时间:2015-05-04 07:55:07

标签: java android eclipse android-studio gradle

我尝试将Eclipse Android项目迁移到Android Studio,我尝试过两种方式,直接从Android Studio打开并首先迁移到Eclipse中的Gradle,然后在Android Studio中打开它。

然后我尝试删除Google Play库文件夹并将其添加到我的Gradle文件中,然后项目执行此操作:

  • 让项目确定
  • 清洁项目确定
  • 重建项目确定
  • Gradle同步并下载了大量的DLL 确定
  • 播放或调试KO并给我这个错误:
  

错误:任务执行失败   ':goSmart.guestperience.MoncloaDeSanLazaro:dexDebug'

     
    

com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:Process'命令     ' /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java''     完成非零退出值2

  

OR

  

错误:任务执行失败   ':goSmart.guestperience.MoncloaDeSanLazaro:dexDebug'

     
    

com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:Process'命令     ' /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java''     完成非零退出值2

  

OR

  

错误:任务执行失败   ':goSmart.guestperience.MoncloaDeSanLazaro:dexDebug'

     
    

com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:Process'命令     ' /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java''     完成非零退出值2

  

我已经开始使用JDK 1.6,然后更新到1.7然后更新到1.8以查看是否存在问题。

如果我不删除Google Play Dervices文件夹,该项目就可以正常运行。

如果这很重要,我会使用MAC。

如果要解决这个问题,我的项目中出现了this其他问题已经在堆栈溢出中发布。

这就是我的项目结构:

enter image description here

这是所有项目的build.grade文件

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(这是我编码的地方):

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')
    }
}

主:

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')
    }
}

我认为某些配置缺失(可能),真的是我超级迷失了。

我是一名iOS程序员,这是我在Android上的第一步,该项目由另一个人完成,现在我应该继续,所以让我们说我&#39 ;我与Android Studio进行了很好的斗争,看起来我很失败;-P

感谢您的帮助。

更新

我在日志中找到了这个:

  

AGPBI:{&#34; kind&#34;:&#34; SIMPLE&#34;,&#34; text&#34;:&#34;意外的顶层   例外:&#34;,&#34;职位&#34;:{},&#34;原创&#34;:&#34;意想不到的顶级水平   例外:&#34;} AGPBI:   {&#34; kind&#34;:&#34; SIMPLE&#34;,&#34; text&#34;:&#34; com.android.dex.DexException:Multiple dex   文件定义   LCOM /谷歌/机器人/克/分析/内部/命令$ 1;&#34;&#34;位置&#34;:{},&#34;原&#34;:&#34; com.android.dex .DexException:   多个dex文件定义   Lcom / google / android / gms / analytics / internal / Command $ 1;&#34;} AGPBI:   {&#34;种类&#34;:&#34; SIMPLE&#34;&#34;文本&#34;:&#34; \ TAT   com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)&#34;&#34;位置&#34;:{},&#34;原&#34;:&#34; \ TAT   com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)&#34;}   AGPBI:{&#34; kind&#34;:&#34; SIMPLE&#34;,&#34; text&#34;:&#34; \ tat   com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)&#34;&#34;位置&#34;:{},&#34;原&#34;:&#34; \ TAT   com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)&#34;}   AGPBI:{&#34; kind&#34;:&#34; SIMPLE&#34;,&#34; text&#34;:&#34; \ tat   com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)&#34;&#34;位置&#34;:{},&#34;原&#34;:&#34; \ TAT   com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)&#34;}   AGPBI:{&#34; kind&#34;:&#34; SIMPLE&#34;,&#34; text&#34;:&#34; \ tat   com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)&#34;&#34;位置&#34;:{},&#34;原&#34;:&#34; \ TAT   com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)&#34;} AGPBI:   {&#34;种类&#34;:&#34; SIMPLE&#34;&#34;文本&#34;:&#34; \ TAT   com.android.dx.merge.DexMerger.merge(DexMerger.java:189)&#34;&#34;位置&#34;:{},&#34;原&#34;:&#34; \ TAT   com.android.dx.merge.DexMerger.merge(DexMerger.java:189)&#34;} AGPBI:   {&#34;种类&#34;:&#34; SIMPLE&#34;&#34;文本&#34;:&#34; \ TAT   com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)&#34;&#34;位置&#34;:{},&#34;原&#34;:&#34; \达   com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)&#34;}   AGPBI:{&#34; kind&#34;:&#34; SIMPLE&#34;,&#34; text&#34;:&#34; \ tat   com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)&#34;&#34;位置&#34;:{},&#34;原&#34;:&#34; \达   com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)&#34;} AGPBI:   {&#34;种类&#34;:&#34; SIMPLE&#34;&#34;文本&#34;:&#34; \ TAT   com.android.dx.command.dexer.Main.run(Main.java:246)&#34;&#34;位置&#34;:{},&#34;原&#34;:&#34; \达   com.android.dx.command.dexer.Main.run(Main.java:246)&#34;} AGPBI:   {&#34;种类&#34;:&#34; SIMPLE&#34;&#34;文本&#34;:&#34; \ TAT   com.android.dx.command.dexer.Main.main(Main.java:215)&#34;&#34;位置&#34;:{},&#34;原&#34;:&#34; \达   com.android.dx.command.dexer.Main.main(Main.java:215)&#34;} AGPBI:   {&#34;种类&#34;:&#34; SIMPLE&#34;&#34;文本&#34;:&#34; \ TAT   com.android.dx.command.Main.main(Main.java:106)&#34;&#34;位置&#34;:{},&#34;原&#34;:&#34; \ TAT   com.android.dx.command.Main.main(Main.java:106)&#34;}

4 个答案:

答案 0 :(得分:22)

问题来自Android Play Services 7.3.0。

尝试:

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

或启用multiDex:

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

(multiDex解决方案编译,但可能会在应用启动时崩溃)

答案 1 :(得分:3)

在遇到同样问题的几小时后,我找到了答案。

真正的问题是你有多个内部具有相同类的库,因此解决方案是从其中一个库中删除重复文件。

您必须删除带有重复文件的库或:

  1. 使用WinRAR,7Zip或其他任何内容打开lib libGoogleAnalyticsServices.jar
  2. 转到com/google/android/gms/analytics/internal并删除文件Command$1.classCommand.class
  3. 在您的情况下,您可能必须删除其他重复文件,不确定,因为您有许多文件。无论哪种方式,您还可以强制它忽略其中一些文件 IF 上述方法无效。将以下代码放在build.gradle文件的Android块中:

    defaultConfig {
        multiDexEnabled true
    }
    
    dexOptions {
        preDexLibraries = false
    }
    

答案 2 :(得分:2)

在我的情况下,我只需删除旧库。

答案 3 :(得分:0)

尝试使用最新版本的google play进行编译

试试这个:compile 'com.google.android.gms:play-services:8.1.0'

来自:Setting up google play services