3

本周末我试图将一些项目迁移到 Android Studio,但遇到了一些障碍。我的最后一次尝试涉及使用带有插件版本 22.0.5v201307292155-757759 的 Eclipse ADT 创建一个简单的 Hello World Android 项目。我创建了这个项目,目标是 Android 版本 4.2 w/最低 SDK 2.3 并使用 4.3 构建。我对 AVD 进行了快速构建/运行测试,结果很好。然后,我按照迁移文档中的说明,将项目导出并为 Android Studio 生成了我的 Gradle 构建文件。当我尝试使用捆绑的 gradle 分发 (1.7) 导入 Android Studio 0.2.6 Build# AI-130.795381 时,我收到错误:“原因:未能找到目标 android-18”,并在 idea.log 中带有堆栈跟踪:

2013-08-31 16:04:31,465 [ 517146]   INFO - ject.ProjectImportErrorHandler - Failed to import Gradle project at '/Users/clifton/workspace/MyOtherLilAndroid' 
org.gradle.tooling.BuildException: Could not fetch model of type 'AndroidProject' using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
    at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:55)
    at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$2.run(DefaultAsyncConnection.java:71)

当我尝试使用 Gradle Wrapper(推荐)时,出现错误:无法使用 Gradle 分发版“ http://services.gradle.org/distributions/gradle-1.6-bin.zip ”执行构建。构建文件“/Users/clifton/workspace/MyOtherLilAndroid/build.gradle”行:9 评估根项目“MyOtherLilAndroid”时出现问题。评估根项目“MyOtherLilAndroid”时出现问题。未找到 SDK 位置。使用 local.properties 文件中的 sdk.dir 或使用 ANDROID_HOME 环境变量定义位置。

在 idea.log 中使用以下堆栈跟踪:

2013-08-31 16:05:24,414 [ 570095]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home 
2013-08-31 16:05:24,415 [ 570096]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home 
2013-08-31 16:05:27,840 [ 573521]   WARN - nal.AbstractExternalSystemTask - Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
Build file '/Users/clifton/workspace/MyOtherLilAndroid/build.gradle' line: 9
A problem occurred evaluating root project 'MyOtherLilAndroid'.
A problem occurred evaluating root project 'MyOtherLilAndroid'.
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable. 
com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
Build file '/Users/clifton/workspace/MyOtherLilAndroid/build.gradle' line: 9
A problem occurred evaluating root project 'MyOtherLilAndroid'.
A problem occurred evaluating root project 'MyOtherLilAndroid'.
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
    at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.ensureInstalledWrapper(GradleExecutionHelper.java:198)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:66)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:44)

我尝试下载 Gradle 1.7 并将其用于导入,但出现另一个错误:“原因:找不到目标 android-18

构建文件:'/Users/clifton/workspace/MyOtherLilAndroid/build.gradle'"

在 idea.log 中使用以下堆栈跟踪:

2013-08-31 16:08:01,214 [ 726895]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home 
2013-08-31 16:08:01,214 [ 726895]   INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home 
2013-08-31 16:08:09,075 [ 734756]   INFO - ject.ProjectImportErrorHandler - Failed to import Gradle project at '/Users/clifton/workspace/MyOtherLilAndroid' 
org.gradle.tooling.BuildException: Could not fetch model of type 'AndroidProject' using Gradle installation '/Users/clifton/java-apps/gradle-1.7'.
    at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:55)
    at org.gradle.tooling.internal.consumer.async.DefaultAsyncConnection$2.run(DefaultAsyncConnection.java:71)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:680)
    at org.gradle.tooling.internal.consumer.BlockingResultHandler.getResult(BlockingResultHandler.java:46)
    at org.gradle.tooling.internal.consumer.DefaultModelBuilder.get(DefaultModelBuilder.java:46)
    at com.android.tools.idea.gradle.project.ProjectResolver$1.fun(ProjectResolver.java:206)
    at com.android.tools.idea.gradle.project.ProjectResolver$1.fun(ProjectResolver.java:199)
    at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.execute(GradleExecutionHelper.java:148)
    at com.android.tools.idea.gradle.project.ProjectResolver.getAndroidProject(ProjectResolver.java:199)
    at com.android.tools.idea.gradle.project.ProjectResolver.resolveProjectInfo(ProjectResolver.java:136)
    at com.android.tools.idea.gradle.project.AndroidGradleProjectResolver$ProjectResolverFunctionFactory$1.fun(AndroidGradleProjectResolver.java:151)
    at com.android.tools.idea.gradle.project.AndroidGradleProjectResolver$ProjectResolverFunctionFactory$1.fun(AndroidGradleProjectResolver.java:145)
    at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.execute(GradleExecutionHelper.java:148)

我已经确认ANDROID_HOME是通过“~/.MacOSX/environment.plist”在我的Mac上设置的,并且在我的“~/.bash_profile”中设置的“~/.bashrc”中,最后我尝试设置sdk。项目的 local.properties 中的 dir 和 ndk.dir。使用捆绑的 gradle 我在 idea.log 中收到此错误:

2013-08-31 16:14:15,943 [1101624]   INFO - dle.util.AndroidGradleSettings - Found Android SDK home at '/Users/clifton/android-sdk-macosx' (from local.properties file) 
2013-08-31 16:14:18,207 [1103888]   INFO - ject.ProjectImportErrorHandler - Failed to import Gradle project at '/Users/clifton/workspace/MyOtherLilAndroid' 
org.gradle.tooling.BuildException: Could not fetch model of type 'AndroidProject' using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.

以及带有 gradle 包装器的堆栈跟踪:

2013-08-31 16:15:59,616 [1205297]   WARN - nal.AbstractExternalSystemTask - Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
Task 'wrapper' not found in root project 'MyOtherLilAndroid'. 
com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
Task 'wrapper' not found in root project 'MyOtherLilAndroid'.
    at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.ensureInstalledWrapper(GradleExecutionHelper.java:198)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:66)
    at 

是什么赋予了?有没有人成功地将项目迁移到 Android Studio?我在一个糟糕的时间尝试吗?我了解这些工具仍在大力开发中。请指教。

4

1 回答 1

3

我已经找到了上述问题的大部分答案。我的问题源于刚刚打开全新的 MACbook Pro 并全新安装了所有工具(ADT/IntelliJ/Android Studio)。一个复杂的问题是我安装了两个不同的 Android SDK,一个与 ADT 捆绑在一起,另一个与 Android Studio 捆绑在一起。我最初在我的家庭驱动器(~/android-sdk-macosx)中创建了一个指向 ADT 捆绑 SDK 的符号链接,因为我的所有命令行工具(在我的其他项目中)都配置为在那里查看。我开始注意到其中一个创建的 AVD 无法在另一个中正确启动,这促使我替换上面的符号链接并将其指向 AS SDK。

长话短说……我对 SDK 的混淆导致了一个从 ADT 导出的项目,该项目仍然在其捆绑的 SDK 中看到构建工具 18 在 Android Studio 中不可导入。其他错误只是掩盖和混淆了根本问题。(他们是徒劳地试图强制项目导入。)

于 2013-09-01T15:05:33.633 回答