【问题标题】:Use gradle for Android/Eclipse project为 Android/Eclipse 项目使用 gradle
【发布时间】:2015-03-04 19:13:38
【问题描述】:

我想在我的 Android/Eclipse 项目中使用 gradle,因为我希望能够在发布版本旁边安装我的应用程序的开发版本(如下所示:What is a practical way to install stable and development app versions simultaneously?

使用命令行这样做对我来说是可以的。

所以我将我的项目的 src 文件夹移动到 src/main/java 并创建了一个build.gradle 文件(如此处所述:http://www.nodeclipse.org/projects/gradle/android/Make-Android-Eclipse-project-ready-for-Android-Studio):

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}
apply plugin: 'android'
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}
android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

    androidTest.setRoot('tests')
    }
}

但是当我运行gradle build 时,我得到了这个错误:

FAILURE: Build failed with an exception.
...
> Could not create plugin of type 'AppPlugin'.

我已经在 stackoverflow 上发现了这个错误。有人说是因为使用了错误的gradle版本。 (Gradle is issuing an error "Could not create plugin of type 'AppPlugin'")

我的问题:

  • 据我了解,build.gradle (0.12.+) 中的这个版本号是 gradle 插件的版本,而不是 gradle 本身的版本。如何找出我正在使用的 gradle 插件版本?
  • 这个插件是从哪里来的?它是 gradle 安装的一部分吗?还是 Eclipse 的一部分?还是 ADT?
  • 我将 Gradle IDE 安装为 Eclipse 插件。它会干扰常规的 gradle 安装吗?

【问题讨论】:

    标签: android eclipse gradle


    【解决方案1】:

    经过一番研究,我终于成功地用 gradle 编译了我的应用程序。

    以防万一其他人有同样的问题,这就是我所做的:

    • 在 Eclipse 中右键单击您的 Android 项目 -> 导出 -> Android -> 生成 Gradle 构建文件。
    • 这会创建build.gradlegradlewgradlew.batsettings.gradle(在我的情况下,在我的项目之上的某些级别)。不要将这些文件移动到您的项目文件夹中。
    • 然后运行./gradlew build。这将自动下载 gradle 插件 (afaik) 并在 [PROJECT FOLDER]/build/outputs/apk 中创建三个 apk。

    【讨论】:

    • 我建议您简单地转移到 Android Studio 并使用 Gradle。最新的 Android Gradle 插件是com.android.tools.build:gradle:1.1.2 并使用apply plugin: 'com.android.application'
    猜你喜欢
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-20
    • 2013-06-01
    • 2014-03-18
    • 2021-10-27
    相关资源
    最近更新 更多