android - Gradle 找不到参数的方法 compile()

标签 android gradle android-gradle-plugin subproject

我有一个 hello world 全屏 android studio 1.5.1 应用程序,我添加了一个 gradle/eclipse-mars 子项目。除了将 include ':javalib' 添加到 settings.gradle 之外,没有修改其他文件。添加 project lib dependency :

project(':app') {
    dependencies {
        compile project(':javalib') // line 23
    }
}

到根构建构建文件并从命令行运行gradle,得到:

  • 地点: 构建文件 'D:\AndroidStudioProjects\AndroidMain\build.gradle' 行:23

  • 出了什么问题: 评估根项目“AndroidMain”时出现问题。

    Could not find method compile() for arguments [project ':javalib'] on org.grad le.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@46 3ca82f.

adding the java plugin到根构建文件没有帮助。

我认为它不在 wrong place 中.

根项目和添加的子项目都有gradle wrapper。

任何指针将不胜感激。

谢谢

编辑:为澄清起见,根构建文件是:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
    }
    task hello << { task -> println "I'm $task.project.name" }
}

project(':app') {
    dependencies {
        //compile project(':javalib') // causes problems
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用构建文件是:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "acme.androidmain"
        minSdkVersion 22
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    //compile project(':javalib') // use :javalib:jar?
    //testCompile project(':javalib')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
}

编辑:本练习的全部目的是将核心 Java 代码放入 Android 项目中。目前核心代码是一个独立的 gradle/eclispe 项目。我在 android 项目中有一批执行 gradle -p standaloneprojectdir/jar 并将 jar 复制到 libs/。

我只是认为除了发布 jar 并从存储库获取它之外还有更简单的方法,因为这一切都在我的电脑上完成。

如果所有的代码都是在线的并且只做一个构建就好了:(

编辑:根据RaGe的建议,这里是virgin android studio project和一个 virgin gradle/eclipse project .没有对这些文件进行任何编辑。如果您选择接受它,您的任务是让 android 应用程序轻松访问 java 项目类(即 new Library();在 MainActivity.onCreate() 中将编译并运行)。我不在乎 java 项目在哪里。理想情况下,两个来源都将实时在两个 ide 中。

尝试 this失败也。说:> 找不到 :virginjavaproject,但目录确实存在。

编辑:实际起作用的是 RaGe 对 virgin android project 的拉取请求.

最佳答案

你已经拥有了

compile project(':javalib') 

在您的 :app 项目中,您不必从根 build.gradle 中注入(inject)依赖项。如果你仍然想从根 build.gradle 开始,正确的做法是:

configure(':app') {
    dependencies {
        compile project(':javalib') // causes problems - NOT ANYMORE!
    }
}

virgin android studio head 是有效的。

关于android - Gradle 找不到参数的方法 compile(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34958886/

相关文章:

android - 如何使约束布局抵抗扩展以覆盖其他 View

android - 在 Cygwin 中使用 repo 下载 Android 源码

intellij-idea - Intellij:定义要用于所有新Java项目的默认任务

android - Gradle Android,从另一个模块中排除依赖

android - 如何在 Android Studio 中编辑使用 Gradle 导入的库的代码?

java - 如何让PagerAdapter加载所有页面

java - ListView 中的搜索栏 JSON 解析数据错误 NullPointerException

android - Android Studio中缺少org.mozilla.javascript.Scriptable

ant - 为 Gradle Javadoc 任务指定所需的包

android - 具有多种口味的 Crashlytics 发行版