简体   繁体   English

Android Studio - 应用程序编译,但不会运行。 看错误

[英]Android Studio - App compiles, but won't run. See error

I ported my app from Eclipse to Android Studio, and now my app won't run. 我将我的应用程序从Eclipse移植到Android Studio,现在我的应用程序将无法运行。 Just to be clear, I did not export from Eclipse. 为了清楚起见,我没有从Eclipse导出。 I created a new project in Android Studio, and manually cut/pasted every class in my project. 我在Android Studio中创建了一个新项目,并手动剪切/粘贴了我项目中的每个类。

I am running Android Studio on a new Macbook Pro - Yosemite. 我在新的Macbook Pro - Yosemite上运行Android Studio。 I am having some issues running my app, even though it compiles. 我正在运行我的应用程序时遇到一些问题,即使它已编译。 From what I can see, my problem might be that I am using JDK 1.8. 从我所看到的,我的问题可能是我使用的是JDK 1.8。 Well, I cannot figure out how the heck to get JDK 6. 好吧,我无法弄清楚如何获得JDK 6。

Here is the error I get when I run the project in Android Studio 这是我在Android Studio中运行项目时遇到的错误

Error:Execution failed for task ':app:preDexDebug'. 错误:任务':app:preDexDebug'的执行失败。 com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1 com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令'/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/java''完成非零退出值1

When I scroll up in the Gradle Event Log, I see this error: 当我在Gradle Event Log中向上滚动时,我看到了这个错误:

com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000) com.android.dx.cf.iface.ParseException:错误的类文件魔术(cafebabe)或版本(0034.0000)

In addition to the app not running, Android Studio freezes a lot! 除了应用程序未运行外,Android Studio还会冻结很多! Again, is this because of the version of Java I have installed? 再次,这是因为我安装的Java版本?

Wait, why didn't you IMPORT the project using Android Studio? 等等,为什么不使用Android Studio导入项目? It will build the gradle files for you. 它将为您构建gradle文件。

在此输入图像描述

Choose New/Import Project... 选择新建/导入项目...

Then you will see it will let you just point to the root directory of your eclipse project: 然后你会看到它会让你只指向你的eclipse项目的根目录:

在此输入图像描述

Ok, installing JDK 7 fixed the issue. 好的,安装JDK 7修复了这个问题。 So, this Macbook is brand new, running Yosemite. 所以,这款Macbook是全新的,运行Yosemite。 It didn't have a JDK installed already. 它没有安装JDK。 When I ran Android Studio, it said no JVM found. 当我运行Android Studio时,它说没有找到JVM。 So, I went and got the latest from Oracle. 所以,我去了Oracle的最新版本。 So the only JDK I had was JDK 8. 所以我唯一拥有的JDK是JDK 8。

So, for whatever reason, installing JDK 7 has made it so my app will actually run... Whoo Hoo! 因此,无论出于何种原因,安装JDK 7使我的应用程序实际运行...哇喔! I'm back in business. 我回来了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM