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

时间:2016-04-21 11:51:48

标签: java android android-studio android-gradle build.gradle

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内找到img标记。

失败:构建因异常而失败。

其中: 构建文件' /home/alle/AndroidStudioProjects/NewsLetter/build.gradle'行:5

出了什么问题: 评估根项目' NewsLetter'。

时出现问题
  

无法在存储库容器上找到参数[]的方法jcenter()。

尝试: 使用--info或--debug选项运行以获得更多日志输出。

的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

2 个答案:

答案 0 :(得分:3)

我知道这已经有一个月了,但由于我遇到了同样的问题,我只是想发布我的解决方案。 Android Studio上的控制台使用的系统gradle可能是旧版本。检查一下 gradle --version

如果gradle版本低于2.0,那么你和我有同样的问题。

您应该使用

升级系统gradle
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle-ppa

安装最新的gradle

答案 1 :(得分:0)

我按照this previous answer克服了同样的问题。

基本上,只需转到文件/设置/构建,执行部署/ Gradle,然后编辑Gradle Home字段,将文件路径更改为最新版本,如:

  • /gradle/gradle-4.1