Gradle无法找到参数的方法compile() [英] Gradle Could not find method compile() for arguments

查看:1353
本文介绍了Gradle无法找到参数的方法compile()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个hello world全屏Android Studio 1.5.1应用程序,我添加了一个gradle / eclipse-mars子项目。没有其他文件被修改,除了在settings.gradle中添加':javalib'。添加项目库依赖项

 项目(':app'){
依赖项{
编译项目(':javalib')//第23行


$ / code>

添加到root build构建文件并从命令行运行gradle ,获得:


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


  • 出错了:
    评估根项目'AndroidMain'时出现问题。


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





a dding the java plugin to the root build file does not help。



我不认为它在错误的地方

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



任何指针都会被赞赏。



谢谢

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

  //顶级构建文件,您可以在其中添加所有子构件公共的配置选项,项目/模块。 
buildscript {
repositories {
jcenter()
}
依赖关系{
classpath'com.android.tools.build:gradle:1.5.0'

//注意:不要在这里放置应用程序依赖关系;它们属于单个模块build.gradle文件中的
// b

$ b allprojects {
存储库{
jcenter()
}
任务hello<< {任务 - > println我是$ task.project.name}
}

项目(':app'){
依赖关系{
//编译项目(' :javalib')//导致问题
}
}

任务清理(类型:删除){
删除rootProject.buildDir
}

和应用程序构建文件是:

  apply plugin:'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion23.0.1

defaultConfig {
applicationIdacme.androidmain
minSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName1.0
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}

依赖关系{
编译fileTree(dir:'libs',include:[' * .jar'])
//编译项目(':javalib')//使用:javalib:jar?
// testCompile project(':javalib')
testCompile'junit:junit:4.12'
compile'c​​om.android.support:appcompat-v7:23.1.1'
compile'c​​om.android.support:support-v4:23.1.1'
}

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



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



将所有代码生存并进行构建会很好: (

编辑:根据 RaGe 的建议,此处是处女android工作室项目处女gradle / eclipse项目。对这些文件没有进行编辑。你应该选择接受它是让android应用程序轻松访问java项目类(即新库();在MainActivity.onCreate()将编译和运行)。我不关心Java项目的生活在哪里。理想情况下,两者源代码将在两个IDE中都是 live

试图这个也失败了。说:>找不到:virginjavaproject,但目录确实存在。



编辑:实际工作的是RaGe对 virgin android project

 编译项目(':javalib')

在你的:app 项目中,你不必从你的根build.gradle注入依赖。如果你仍然想从根目录 build.gradle 来完成,正确的方法是:

<$ p $(':':$'$')$ {
$ {$ b $}编译项目(':javalib')//导致问题 - 不是ANYMORE!


virgin android studio 头是什么工作。


i have a hello world full screen android studio 1.5.1 app that i added a gradle/eclipse-mars subproject to. no other files were modified except for adding include ':javalib' to settings.gradle. adding a project lib dependency:

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

to the root build build file and running gradle from the command line , gets:

  • Where: Build file 'D:\AndroidStudioProjects\AndroidMain\build.gradle' line: 23

  • What went wrong: A problem occurred evaluating root project '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 to the root build file did not help.

i don't think it's in the wrong place.

both the root project and the added subproject have the gradle wrapper.

any pointers will be appreciated.

thanks

edit: for clarification, the root build file is:

// 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
}

and the app build file is:

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'
}

edit: the whole purpose of this exercise is to get core java code into an android project. currently the core code is a standalone gradle/eclispe project. i have a batch in the android project that does a gradle -p standaloneprojectdir/ jar and copied the jar into libs/.

i just though there would be an easier way other than to publish the jar and get it from a repository since this all done on my pc.

it would be nice to have all the code live and just do a build :(

edit: as per RaGe's suggestion, here is a virgin android studio project and a virgin gradle/eclipse project. no editing has been done to these files. you mission should you choose to accept it is to get the android app to easily access the java project classes (i.e. new Library(); in MainActivity.onCreate() will compile and run). i don't care where the java project lives. ideally, both sources would be live in both ide's.

atempting this fails also. says: > Could not find :virginjavaproject, but directory does exist.

edit: what actually worked was RaGe's pull request to the virgin android project.

解决方案

You already have

compile project(':javalib') 

in your :app project, you don't have to also inject the dependency from your root build.gradle. If you still want to do it from the root build.gradle, the correct way to do it is:

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

the virgin android studio head is what worked.

这篇关于Gradle无法找到参数的方法compile()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆