1

When I sync my android studio project it get Error:(9, 0) Could not find method compile() for arguments [io.reactivex:rxandroid:1.2.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler

My build.gradle file is below

// 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:2.2.3'
        compile 'io.reactivex:rxandroid:1.2.1'
        compile 'io.reactivex:rxjava:1.1.9'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {

    repositories {
        jcenter()
    }
}

task clean(type: Delete) {

    delete rootProject.buildDir
}
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
Dipu
  • 45
  • 1
  • 2
  • 16

1 Answers1

2

You call this library in the wrong section. There are two kinds of build.gradle files. For more information build.gradle

In order to solve the problem, you should add required dependencies into build.gradle in the module level, to be exact app\build.gradle

Remove your dependencies from root '`build.gradle' and paste them in app\build.gradle.

android {
    compileSdkVersion // YOURS
    buildToolsVersion // YOURS
    ...........
        }
    dependencies {
            compile 'io.reactivex:rxandroid:1.2.1'
            compile 'io.reactivex:rxjava:1.1.9'
    }

FYI

It's better to use the latest version,

compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
Esmaeil MIRZAEE
  • 1,110
  • 11
  • 14
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198