无法在对象...android中找到实现()方法,其参数为[com.android.support:appcompat-v7:25.4.0]。

4

我需要编译一个在线购买的项目。将其导入到Android Studio中时,它会报Gradle版本的错误,所以我将distributionUrl更新为:distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

当我尝试清除和重建项目时,出现以下错误:

Error:(45, 1) A problem occurred evaluating project ':app'. Could not find method implementation() for arguments [com.android.support:appcompat-v7:25.4.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

下面是整个build gradle文件:

 apply plugin: 'com.android.application'

 apply plugin: 'io.fabric'

 android {
   compileSdkVersion 25
   buildToolsVersion '26.0.0'
   defaultConfig {
    applicationId "dumm.value"
    minSdkVersion 15
    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'

请问我该如何解决这个问题?

请将您遇到错误的代码张贴在此处。 - Nabin Bhandari
4个回答

10

要使用implementation(),您需要使用gradle v.4gradle插件v.3

使用:

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

buildscript {
    repositories {
        ...
        // You need to add the following repository to download the
        // new plugin.
        maven {
            url "https://maven.google.com"
        }            
        //google()  //only if you use Android Studio 3.x
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta7'
    }
}

更多信息请点击此处。


3
我在这样做后仍然遇到相同的问题。 - Samuel Elrod

3

1. 打开您的应用程序的 build.gradle 文件。 2. 确保存储库部分包括一个 Maven 部分,其中包含 "https://maven.google.com" 终端节点。例如:

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

仓库已经在build.gradle文件中了...我已经在上面更新了我的问题,附带了这些细节。 - ewom2468
它如何解决这个问题?Google Maven与问题无关。 - Gabriele Mariotti
build.gradle 文件在哪里? - SeanMC
@SeanMC,这不是一个文件夹,而是一个文件。这是项目级别的 build.gradle 文件。 - Tejas Pandya
@NullPointerException 当然,我是指包含它的文件夹。我的项目似乎只有在构建时被替换的build.gradle文件,因此更改它们没有任何影响。使用虚幻引擎。 - SeanMC

1
在我的情况下,我发现在app.gradle文件中

implementationSdkVersion 27

出现了,而不是

compileSdkVersion 27

所以请将其放置如下。
 compileSdkVersion 28
defaultConfig {
    applicationId "com.kotlinpractise"
    minSdkVersion 21
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

0
如果您仍然遇到错误,请尝试将node_modules中包的android/build.gradle从implementation更改为compile。这对我有用。 您可以在项目文件夹内使用以下命令。
sed -i -s "s#implementation#compile#" node_modules/your-react-native-package-name/android/build.gradle

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