EvolvingMonkey
EvolvingMonkey

Reputation: 59

Error: Could not find method jcenter() for arguments [] on repository container

I have recently updated my android studio from 1.5 to 2.0 and Iam unable to compile the existing project. When i build the project from the terminal i get the following error.

gradle build --stacktrace

alle@alle-Inspiron-3537:~/AndroidStudioProjects/NewsLetter$ gradle build --stacktrace Note: in order to honour the org.gradle.jvmargs and/or org.gradle.java.home values specified for this build, it is necessary to fork a new JVM. To avoid the slowdown associated with this extra process, you might want to consider running Gradle with the daemon enabled. Please see the user guide chapter on the daemon at http://gradle.org/docs/1.4/userguide/gradle_daemon.html.

FAILURE: Build failed with an exception.

Where: Build file '/home/alle/AndroidStudioProjects/NewsLetter/build.gradle' line: 5

What went wrong: A problem occurred evaluating root project 'NewsLetter'.

Could not find method jcenter() for arguments [] on repository container.

Try: Run with --info or --debug option to get more log output.

build.gradle

 buildscript {
     repositories {
      jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.+'
    }
}
    allprojects {
     repositories {
       jcenter()
      }
     }
    task clean(type: Delete) {
     delete rootProject.buildDir
    }

build.gradle(app)

apply plugin: 'com.android.application'


android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "design.iith.newsletter"
    minSdkVersion 16
    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'])
testCompile 'junit:junit:4.12'
compile files('libs/volley.jar')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
}

Gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

Upvotes: 3

Views: 5742

Answers (2)

JorgeAmVF
JorgeAmVF

Reputation: 1720

I overcame the same problem by following this previous answer.

Basically, just go to File/Settings/Build, Execution Deployment/Gradle and then edit the Gradle Home field changing the file path to the newest version like:

  • /gradle/gradle-4.1

Upvotes: 0

Takeya
Takeya

Reputation: 123

I know this is a month old but since I had the same issue, I'd just like to post my solution. The console on Android Studio uses your system gradle which might be of an older version. Check it with gradle --version

If the gradle version is below 2.0 then you have the same problem as me.

You should upgrade your system gradle with

sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle-ppa

to get the newest gradle installed

Upvotes: 4

Related Questions