Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Could not find method compile() for arguments

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.

like image 979
Ray Tayek Avatar asked Jan 23 '16 02:01

Ray Tayek


People also ask

Could not find method compile () for arguments react native?

You can fix this issue by replacing compile with implementation in node_modules/react-native-geocoder/android/build. gradle.

What is the difference between compile and implementation in gradle?

Fortunately, the implementation dependency configuration provides the same functionality as compile. You should always use implementation rather than compile for dependencies, as compile is now deprecated or removed in the case of Gradle 7+.

What is compileOnly in gradle?

compileOnly dependencies are available while compiling but not when running them. This is equivalent to the provided scope in maven. It means that everyone who wants to execute it needs to supply a library with all classes of the CompileOnly library.

Is compileOnly deprecated?

compileOnly is the replacement — the equivalent configuration that is being deprecated is provided .


Video Answer


1 Answers

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.

like image 111
RaGe Avatar answered Sep 23 '22 12:09

RaGe