Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未找到Gradle DSL方法:';实施()';_Android_Android Gradle Plugin - Fatal编程技术网

Android 未找到Gradle DSL方法:';实施()';

Android 未找到Gradle DSL方法:';实施()';,android,android-gradle-plugin,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

我犯了这个错误

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
模块应用程序

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'

要使用DSL
implementation()
,您必须使用:

buildscript {
    repositories {
        ...
        // You need to add the following repository to download the
        // new plugin.
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta1'
    }
}
  • Android 3.0.0的升级gradle插件
  • gradle版本3.4或更高版本
然后在
build.gradle
中,您必须使用:

buildscript {
    repositories {
        ...
        // You need to add the following repository to download the
        // new plugin.
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta1'
    }
}
在您的
gradle wrapper.properties中

distributionUrl=\
  https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip

更详细。

或者如果您不想更新到最新版本,请返回使用DSL方法
compile()
,而不是
implementation()

implementation()
替换了
compile()
配置,该配置将在2018年底被弃用

为了修复错误并使用它,您必须更新到Android Gradle Plugin 3.0.0(或更高版本)。作为此更新的结果,您还需要将Gradle更新为Gradle 4.1(或更高版本)。您还需要使用构建工具26.0.2(或更高版本),这意味着要在
Build.gradle
中更新您的
构建工具版本
,或者只是将其完全删除(因为,从3.0.0开始,默认情况下会使用所需的最低版本)。为了使用这些高级版本,您还需要更新到Android Studio 3(或更高版本)

您可以在这里阅读android gradle插件3.0.0的变更日志、改进的编译时间等内容:

那么如何更新Android Gradle插件和Gradle?

选项1:手动

在您的
build.gradle
中找到您的gradle类路径,并将版本更新到gradle 3.0。此外,还应添加google()maven的存储库:

buildscript {
    repositories {
        jcenter()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}
在gradle-wrapper.properties中找到您的distributionUrl并更新到:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
选项2:通过项目属性 (但请注意,手动配置将覆盖它)

归档→项目结构→计划

最后一件事,您还可以选择是用implementation()替换compile(),还是用api()替换compile()。默认情况下,我建议只使用implementation()。您可以在此处阅读有关差异的更多信息:
我有一个很简单的原因来解释这个问题,所以我必须发布我的答案,以防止其他人遇到这个问题

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

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
不管是谁把那张纸条放进去的,干得好。相反,将您的存储库和依赖项放在类似命名的模块文件
build.gradle(模块:app)

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

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

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

在我的情况下,这只是一个输入错误。这是一个额外的符号“/”在您使用土耳其工作区的一行之后, 下面的更改解决了问题

testImplementation -> testİmplementation,
androidTestImplementation -> androidTestİmplementation
androidTestImplementation -> androidTestİmplementation

我也遇到了类似的错误。当我试图用这样的代码包含may build.gradle(模块:app)中的recyclerview依赖项时

//other build.gradle(Module: App) code above
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    testCompile 'junit:junit:4.12'
    implementation 'com.android.support:recyclerview-v7:25.3.1'
}

因此,我解决这个问题的简单方法是将代码更改为这个,在保留其他代码及其版本号的同时,我将实现更改为编译

//other build.gradle(Module: App) code above
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:recyclerview-v7:25.3.1'
}
我希望这能帮助一些有类似问题的人。
PS:实际错误是由
实现'com.android.support:recyclerview-v7:25.3.1'
和将代码更改为
编译'com.android.support:recyclerview-v7:25.3.1'
修复的。

作为初学者,我发现有两个build.gradle文件

值得检查的是,您没有将该行添加到错误的文件中。 我在项目文件中添加了我的,而我应该在模块一中添加它


在我的例子中,我添加了这些行并解决了问题

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

@这是另一个问题。这与你的问题无关。您的build.gradle文件有问题。你可能会想问一个单独的问题,非常感谢,你的解决方案很快,而且工作很完美。(预计)在2018年底之前就不复存在了,所以我不会改变它,把重点放在纠正错误的愿望上,这阻止了我经历同样的事情——我今天花了大部分时间试图找出错误。包括重新安装Android Studio、修改我的设置、安装新SDK等等。我的问题是,你提到的注释在
buildscript
大括号内,所以我认为可以将依赖项放在大括号外。重申:确保你把东西放在你的应用程序或模块的
build.gradle
中,而不是放在项目中。这正是我所经历的。值得注意的是,SDK会建议您可能需要更新,即使这在我们的案例中不是问题所在。对。我是从VisualStudio来到Android Studio的,使用“项目”就像VS使用“解决方案”;就像VS使用“项目”一样使用“模块”…至少在我看来是这样。这救了我,忽略了注释行,直到我找到了你的答案。感谢you@TaslimOseni没关系,我认为这是一个模糊的答案,没有正确地阅读。对我来说,问题是我把实现放在了我的项目的build.gradle中,而不是模块app build.gradle中。一旦我换了它,效果很好。非常感谢。这就是我的答案。非常感谢。这对我很有效,节省了我很多时间。这是正确的答案。