迁移到Android Studio

时间:2013-08-31 23:19:38

标签: eclipse gradle android-studio

本周末我试图将一些项目迁移到Android Studio,我一直在遇到一些障碍。我的最后一次尝试涉及使用Eclipse ADT w / plugin版本22.0.5v201307292155-757759创建一个简单的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中使用stacktrace:

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位置。使用sdk.dir在local.properties文件中或使用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

构建文件:'/ Usrs / 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)

我已经确认通过“〜/ .MacOSX / environment.plist”和我的“〜/ .bashrc”在我的Mac上设置了ANDROID_HOME,这是我的“〜/ .bash_profile”的源代码我最后尝试过在项目的local.prooperties中设置sdk.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?我在困难时期尝试过吗?我知道这些工具仍处于重大发展阶段。请指教。

1 个答案:

答案 0 :(得分: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工作室中是不可导入的。其他错误只是掩盖并混淆了潜在的问题。 (他们徒劳无功地试图进口项目。)