错误:Gradle DSL找不到方法:'google()'

4

我试图将一个外部库添加到我的现有项目中。我创建了一个libs文件夹,并将我的MaterialDrawer库添加到根目录中。这是我的settings.gradle文件:

include ':app'
include 'libs:MaterialDrawer'

但是gradle同步失败,并出现以下错误:

错误:未找到Gradle DSL方法:“google()”

我在SO上找不到解决方案来解决我的问题。 有没有人愿意帮忙?

这是build.gradle(项目)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://maven.google.com" }
    }
}

以下是build.gradle (app)文件内容:

android { 编译目标版本号 25 构建工具版本号 '25.0.0'

defaultConfig {
    applicationId "com.myapp"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 38
    versionName "2.1.8"

    generatedDensities = []

}

dexOptions {
    javaMaxHeapSize "4g"
}

aaptOptions {
    additionalParameters "--no-version-vectors"
}

    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

tasks.whenTaskAdded { task ->
    if (task.name.equals("lint")) {
        task.enabled = false
    }
}

repositories {
    mavenCentral()
    maven { url "https://jitpack.io"}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(":libs:MaterialDrawer")
}

apply plugin: 'com.google.gms.google-services'

在项目的gradle中添加存储库{ maven { url 'https://maven.google.com' //备用URL为'https://dl.google.com/dl/android/maven2/' } } - Programming Pirate
仍然出现错误。:( - noob-Sci-Bot
@noob-Sci-Bot,你的libs目录中有任何jar库吗?发布MaterialDrawerbuild.gradle。还有为什么你在应用程序的build.gradle中使用了repositories部分? - DeKaNszn
@DeKaNszn 我的 libs 文件夹里没有任何 jar 库。我只是从 Github 下载了 zip 文件,解压并将文件夹粘贴到了 libs 中。 - noob-Sci-Bot
@noob-Sci-Bot,这是 https://github.com/mikepenz/MaterialDrawer 吗? - DeKaNszn
@DeKaNszn 是的,就是那个! - noob-Sci-Bot
1个回答

2

在Gradle 4.0中添加了google()方法
旧版本应使用maven { url 'https://maven.google.com' }

同时,从您的应用程序build.gradle中删除repositories部分(可以将其与根build.gradle合并)

在此处阅读有关如何将库添加到build.gradle的说明

compile('com.mikepenz:materialdrawer:5.9.5@aar') {
    transitive = true
}

很遗憾,不起作用了。 请告诉我为什么这与我新添加的外部库有关? 在添加它之前,一切都很好。 - noob-Sci-Bot
展示此库的 build.gradle 文件。 - DeKaNszn
谢谢您的回答。但是我的主要关注点是修改mikepenz库。如果我直接通过URL编译,我该如何修改它? - noob-Sci-Bot
我的回答是使用库(你没有提到修改)。如果你想要修改,那么你应该将其用作模块。 - DeKaNszn
这就是我想做的事情。我该如何将其添加为模块?你能帮我吗? - noob-Sci-Bot

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接