未找到Android Studio Gradle DSL方法:'mavencentral()'

时间:2016-02-28 04:55:58

标签: android maven android-studio gradle android-gradle

我想在我的Android应用程序中使用facebook SDK,我开始将maven中央存储库添加到我的build.gardle。虽然,我发现2 build.gardle属于项目和应用程序。他们在这里;

  • Android Studio: 1.5.1
  • Gradle版本: 2.8
  • Android插件版本: 1.5.0

Build.gardle(项目)

buildscript {
    repositories {
        jcenter()
        mavencentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    }
}

allprojects {
    repositories {
        jcenter()
        mavencentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Build.gardle(APP)

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 15
        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 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:design:23.2.0'
}

但是我在构建期间遇到以下错误;

  

未找到Gradle DSL方法:mavencentral()

我试过了;

并且,我没有尝试update my gardle or android studio,但我只是想知道它是否真的需要,或者我对build.gardle做错了。

任何建议表示赞赏。谢谢。

1 个答案:

答案 0 :(得分:1)

Facebook SDK page很清楚。添加到项目/ build.gradle

repositories {
    mavenCentral() //note the uppercase C
}

并进入您的项目/ app / build.gradle

dependencies { 
  compile 'com.facebook.android:facebook-android-sdk:4.+'
}