Gradle无法为参数找到方法compile()

Ray*_*yek 11 android subproject gradle android-gradle-plugin

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

project(':app') {
    dependencies {
        compile project(':javalib') // line 23
    }
}
Run Code Online (Sandbox Code Playgroud)

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

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

  • 出了什么问题:评估根项目'AndroidMain'时出现问题.

    无法在org.grad le.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@46 3ca82f上为参数[project':javalib']找到方法compile().

将java插件添加到根构建文件没有帮助.

我不认为它在错误的地方.

根项目和添加的子项目都有gradle包装器.

任何指针将不胜感激.

谢谢

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

// 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
}
Run Code Online (Sandbox Code Playgroud)

和应用程序构建文件是:

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'
}
Run Code Online (Sandbox Code Playgroud)

编辑:本练习的全部目的是将核心java代码转换为android项目.目前核心代码是一个独立的gradle/eclispe项目.我在android项目中有一个批处理,它执行gradle -p standaloneprojectdir/jar并将jar复制到libs /中.

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

让所有代码都存在并且只是做一个构建会很好:(

编辑:根据RaGe的建议,这是一个处女android工作室项目处女gradle/eclipse项目.没有对这些文件进行编辑.你的任务应该选择接受它是为了让Android应用程序轻松访问java项目类(即新的Library();在MainActivity.onCreate()中将编译并运行).我不关心java项目的位置.理想情况下,两个来源都将存在于两个ide中.

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

编辑:实际工作的是RaGe对处理android项目的拉取请求.

RaG*_*aGe 4

你已经拥有了

compile project(':javalib') 
Run Code Online (Sandbox Code Playgroud)

在您的:app项目中,您不必从根 build.gradle 注入依赖项。如果您仍然想从根开始执行此操作build.gradle,正确的方法是:

configure(':app') {
    dependencies {
        compile project(':javalib') // causes problems - NOT ANYMORE!
    }
}
Run Code Online (Sandbox Code Playgroud)

virgin android studio head 是有效的。