17

Error:(36, 0) Could not find method api() for arguments [project ':model'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler

Please help me.

This is my build.gradle file.

apply plugin: 'com.android.application'
//apply plugin: 'io.fabric'

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
 applicationId "com.manafzar.mytaxi.driver"
 minSdkVersion 16
 targetSdkVersion 26
 versionCode 23
 versionName "2.0.3"
 multiDexEnabled true
 vectorDrawables.useSupportLibrary = true
 javaCompileOptions {
    annotationProcessorOptions {
    arguments = [eventBusIndex: 
   'com.manafzar.mytaxi.driver.DriverEventBusIndex']
  }
 }
}
buildTypes {
 release {
   minifyEnabled false
   proguardFiles getDefaultProguardFile('proguard-android.txt'), 
      'proguard-rules.pro'
  }
}
dataBinding {
  enabled = true
  }
}

dependencies {
   annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.0.1'
   api project(':model')
   api 'com.google.maps.android:android-maps-utils:0.5'
   api 'com.diogobernardino:williamchart:2.5.0'
}
apply plugin: 'com.google.gms.google-services'
Community
  • 1
  • 1
Waqas Khan
  • 171
  • 1
  • 1
  • 5
  • 6
    I got the same issue for my plain Java project (no Android). I fixed it by adding the line: `apply plugin: 'java-library'` to my `build.gradle` file. – Shadow Man Jan 22 '19 at 21:13
  • @ShadowMan: Your comment should be an answer so it can get up-voted! – Evan Aug 28 '19 at 16:38

3 Answers3

32

I ran into the same issue when migrating from Gradle 5.0 to Gralde 6.0.x.

As @ShadowMan mentioned, the issue was missing the java-library plugin which introduces the api method.

In your build.gradle file you should include:

plugins {
    id 'java-library'
}

More info can be found here: https://docs.gradle.org/current/userguide/java_library_plugin.html

andre
  • 1,084
  • 11
  • 13
0

I added two project dependency to build.gradle of project:

buildscript {
    
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'

        **api project(':StickyListHeaders')**
        **api project(':Farayan.Core')**
    }
}

After moving dependencies to build.gradle of module, problem resolved:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    **api project(':StickyListHeaders')**
    **api project(':Farayan.Core')**
}
Homayoun Behzadian
  • 1,053
  • 9
  • 26
-5

Please add "compile" instead of "api" in your dependencies tag. And please add below code in your main build.gradle file:

allprojects {
    repositories {
        jcenter()
        google()
        maven {
            url "https://maven.google.com"
        }
    }
}
Patrick R
  • 6,621
  • 1
  • 24
  • 27
  • The new way of handling dependencies in gradle is to use `implementation` for any runtime scoped dependencies (for things like jackson or bouncycastle that aren't actually exposed in your API but are required for things to run properly), and `api` for compile (default) scoped dependencies (things that are required to both compile and run). See: https://stackoverflow.com/a/44419574/2167531 – Shadow Man Jan 23 '19 at 01:17