0

Trying to create a standard Android project using Gradle which I will import into Eclipse.

Am using the following tools (Eclipse IDE along with plug-ins):

  • Eclipse Kepler SR 2 (SE 64 bit)
  • Android Development Plug-in 22.6.3.v201404151837-1123206
  • Gradle IDE 3.5.1.201404300713-RELEASE
  • Groovy Compiler 1.8 - 2.1 Feature (along with dependencies)

Am able to create a standard Gradle project but when I tried to follow the tutorial (to setup an Android / Gradle project) located at:

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:

FAILURE: Build failed with an exception.

  • Where: Build file '/GradleProjects/hello/build.gradle' line: 1

  • What went wrong: A problem occurred evaluating root project 'hello'.

    Could not create plugin of type 'AppPlugin'.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

    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 (e.g. writing the build script and / or importing into Eclipse as a Gradle project)?

(2) I know I am using the latest versions (both Android and Gradle) but it doesn't work when I try to add

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

Would really appreciate it if someone can point me to a good reference...

4

1 回答 1

3

您不能使用 Eclipse 的 Gradle 支持将基于 Gradle 的 Android 项目导入 Eclipse。Android Gradle 项目在 Eclipse 的 Gradle 支持不理解的 Android 插件中使用了很多自定义基础架构。最重要的是,Android 不使用 Java 源集。

对此没有简单的答案。为了能够在 Eclipse 中使用基于 Gradle 的 Android 项目,必须有人为其编写一个 Eclipse 插件,这不是一件容易的事。

如果你想在 Android Studio 和 Eclipse 中使用同一个项目,你需要为其设置一个普通的 Eclipse 项目,并在 Eclipse 端完全绕过 Gradle。您必须将项目保留在 Eclipse 样式的目录结构中,根据您设置 sourceSets 的方式,这看起来您已经完成了。

至于您的第二个问题,您已经将 Gradle 版本与 Android-Gradle-plugin 版本交叉。Gradle 的最新版本是 1.12;该插件的最新版本是 0.10.2。

于 2014-05-21T16:28:12.743 回答