简体   繁体   English

在Eclipse中使用Gradle设置标准Android项目

[英]Setup Standard Android Project using Gradle in Eclipse

Trying to create a standard Android project using Gradle which I will import into Eclipse. 尝试使用Gradle创建标准的Android项目,然后将其导入Eclipse。

Am using the following tools (Eclipse IDE along with plug-ins): 我正在使用以下工具(Eclipse IDE和插件):

  • Eclipse Kepler SR 2 (SE 64 bit) Eclipse Kepler SR 2(SE 64位)
  • Android Development Plug-in 22.6.3.v201404151837-1123206 Android开发插件22.6.3.v201404151837-1123206
  • Gradle IDE 3.5.1.201404300713-RELEASE Gradle IDE 3.5.1.201404300713-发布
  • Groovy Compiler 1.8 - 2.1 Feature (along with dependencies) Groovy编译器1.8-2.1功能(以及相关性)

Am able to create a standard Gradle project but when I tried to follow the tutorial (to setup an Android / Gradle project) located at: 能够创建一个标准的Gradle项目,但是当我尝试遵循位于以下位置的教程(设置Android / Gradle项目)时:

http://www.vogella.com/tutorials/AndroidBuild/article.html http://www.vogella.com/tutorials/AndroidBuild/article.html

apply plugin: 'android'
apply plugin: 'eclipse'

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.4+'
    }
}

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17

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

        instrumentTest.setRoot('tests')
    }
}

android {
    buildToolsVersion "17.0"
    compileSdkVersion 17

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

            instrumentTest.setRoot('tests')
        }
}

I got the following in my Eclipse's console: 我在Eclipse的控制台中得到以下内容:

FAILURE: Build failed with an exception. 失败:构建失败,发生异常。

  • Where: Build file '/GradleProjects/hello/build.gradle' line: 1 其中:构建文件'/GradleProjects/hello/build.gradle'行:1

  • What went wrong: A problem occurred evaluating root project 'hello'. 出了什么问题:评估根项目“ hello”时出现问题。

    Could not create plugin of type 'AppPlugin'. 无法创建“ AppPlugin”类型的插件。

  • Try: Run with --stacktrace option to get the stack trace. 尝试:使用--stacktrace选项运行以获取堆栈跟踪。 Run with --info or --debug option to get more log output. 使用--info或--debug选项运行以获取更多日志输出。

    BUILD FAILED 建立失败

Question(s): 问题:

(1) Is there a standard way to create an Android Gradle project (which one can add more to the build script later on) using Eclipse (eg writing the build script and / or importing into Eclipse as a Gradle project)? (1)是否存在使用Eclipse创建Android Gradle项目(以后可以向构建脚本添加更多内容)的标准方法(例如,编写构建脚本和/或作为Gradle项目导入到Eclipse)?

(2) I know I am using the latest versions (both Android and Gradle) but it doesn't work when I try to add (2)我知道我使用的是最新版本(包括Android和Gradle),但是当我尝试添加时却无法使用

classpath 'com.android.tools.build:gradle:1.10+'

Would really appreciate it if someone can point me to a good reference... 如果有人可以为我提供良好的参考,我将不胜感激。

You can't import Gradle-based Android projects into Eclipse using Eclipse's Gradle support. 您不能使用Eclipse的Gradle支持将基于Gradle的Android项目导入Eclipse。 Android Gradle projects use a lot of custom infrastructure in the Android plugin that Eclipse's Gradle support doesn't understand. Android Gradle项目在Eclipse的Gradle支持无法理解的Android插件中使用了许多自定义基础结构。 Most importantly, Android doesn't use Java sourceSets. 最重要的是,Android不使用Java sourceSets。

There's no simple answer for this. 没有简单的答案。 To be able to use Gradle-based Android projects in Eclipse, someone will have to write an Eclipse plugin for it, which won't be a trivial task. 为了能够在Eclipse中使用基于Gradle的Android项目,某人将不得不为其编写Eclipse插件,这并不是一件容易的事。

If you want to use the same project in both Android Studio and Eclipse, you'll need to set up a normal Eclipse project for it and bypass Gradle altogether on the Eclipse side. 如果要在Android Studio和Eclipse中使用同一项目,则需要为其设置一个普通的Eclipse项目,并在Eclipse端完全绕过Gradle。 You'll have to keep the project in Eclipse-style directory structure, which it looks like you've already done based on how you set up your sourceSets. 您必须将项目保持在Eclipse风格的目录结构中,根据您设置sourceSet的方式,它看起来已经完成了。

As for your second question, you've crossed Gradle versions with Android-Gradle-plugin versions. 至于第二个问题,您已经将Gradle版本与Android-Gradle-plugin版本进行了交叉。 The latest version of Gradle is 1.12; Gradle的最新版本是1.12; the latest version of the plugin is 0.10.2. 该插件的最新版本是0.10.2。

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

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