android - Gradle DSL 方法未找到 : 'implementation()'

标签 android android-gradle-plugin

我遇到了这个错误

Error:(45, 0) Gradle DSL method not found: 'implementation()'
Possible causes:<ul><li>The project 'LaTaxi2' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
<a href="fixGradleElements">Upgrade plugin to version 2.3.3 and sync project</a></li><li>The project 'LaTaxi2' may be using a version of Gradle that does not contain the method.
<a href="open.wrapper.file">Open Gradle wrapper file</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

build.gradle 内容

// Top-level build file where you can add configuration options common to all sub-projects/modules.


buildscript {
    repositories {
        maven {
            url 'https://maven.google.com'
        }
//        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        /* CHANGE to classpath 'com.android.tools.build:gradle:2.3.3'  for STABLE BUILD TOOL VERSION*/
//        classpath 'com.android.tools.build:gradle:3.0.0-alpha7'
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.1.0'
        // We recommend changing it to the latest version from our changelog:
        // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin

        classpath 'io.fabric.tools:gradle:1+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}


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

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

构建 .gradle 模块应用

apply plugin: 'com.android.application'

apply plugin: 'io.fabric'

repositories {
    maven {
        url 'https://maven.google.com'
    }
//    google()
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.0'
    defaultConfig {
        applicationId "in.techware.lataxi"
        minSdkVersion 17
        targetSdkVersion 25
        versionCode 5
        versionName "1.0.4"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    /* Remove This to remove Crashlytics and Fabric */

    compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
        transitive = true;
    }
/*    compile('com.digits.sdk.android:digits:2.0.6@aar') {
        transitive = true;
    }*/
    implementation 'com.android.support:appcompat-v7:25.4.0'
    implementation 'com.android.support:design:25.4.0'
    implementation 'com.android.support:recyclerview-v7:25.4.0'
    implementation 'com.squareup.okhttp3:okhttp:3.8.1'
    implementation 'com.android.support:cardview-v7:25.4.0'
    implementation 'com.github.bumptech.glide:glide:3.8.0'
    implementation 'com.google.android.gms:play-services-maps:11.0.2'
    implementation 'com.google.android.gms:play-services-location:11.0.2'
    implementation 'com.google.android.gms:play-services-places:11.0.2'
    implementation 'com.google.firebase:firebase-auth:11.0.2'
    implementation 'com.google.firebase:firebase-messaging:11.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
    implementation 'com.google.code.gson:gson:2.8.0'
    testCompile 'junit:junit:4.12'
}







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

最佳答案

我有一个很简单的原因导致这不起作用,我必须发布我的答案以防止其他人经历这个。

不要将存储库和依赖项放在名为 build.gradle (Project: YourProjectName) 的文件中!该文件中有一条注释说:

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

感谢把那张纸条放在那里的人。相反,将您的存储库和依赖项放在名称相似的模块文件 build.gradle (Module: app) 中。

应该已经有一个 dependencies 函数。您可能需要添加存储库功能。就我而言,它是:

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

这应该可以让您同步和识别实现

关于android - Gradle DSL 方法未找到 : 'implementation()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45838173/

相关文章:

java - 在 Android 中翻译短信正文

android - Android 中的加泰罗尼亚语和巴斯克语资源

android - RecyclerView 滚动到没有动画的所需位置

android - 为 Android 错误构建 FFMPEG

android - 构建 apk 时显示进程意外退出错误

android - Gradle 安卓插件 : Hook into post-compile task for all product flavors

android 组件启用 bool 值

android - 撇号前面没有\- values-fr.xml 文件在更改后未保存

android - Android 应用程序的测试版本和 proguarded 版本 - NoSuchMethodError

Android 实验级插件看不到我的库模块