簡體   English   中英

在 Android Studio 中出現錯誤“找不到方法實現()”

[英]Getting an error “could not find method implementation()” in Android Studio

我收到此錯誤消息。

無法在 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 類型的對象上找到參數 [project ':app'] 的方法 implementation()。

這是我的項目級別的 gradle 文件:

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

    repositories {
        jcenter()
        maven { url "https://maven.google.com" }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:3.2.0'
        // 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
}

dependencies {
    implementation project(':app')
}

這是我的應用程序的 gradle 文件:

apply plugin: 'com.android.application'
apply plugin: 'java-library'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.therationalbloke.myapplication"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation project(':app')
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

注意:我已經知道以下內容。

  • 在 Gradle 3.0 或更高版本中,“compile”已被“implementation”取代。

  • 是的,我使用的是 Android Studio 的最新版本,根據 Rob 的說法,我應該更喜歡舊版本。 但問題是那個版本中的許多技術問題困擾着我(其中很多包括現在已經過時的東西)。

  • 我已經在 Stack Overflow 和 Github 上閱讀了幾乎所有解決此問題的方法。 他們要么要求使用 implementation() 而不是 compile(我已經在使用),要么要求檢查 Gradle 版本是否為 3.0+。

  • 我已經嘗試根據 Stackoverflow 上一位用戶的建議將所有“實現”更改為“編譯”。

  • 我嘗試過按照不同社區的很多人的建議導入很多庫。

關於我的 Android Studio 的一些信息

  • 安卓工作室 - 3.1.3

  • Android 插件版本 - 3.1.3

  • Gradle 版本 - 4.4

情況截圖

我從未在 gradle 文件中看到過類似implementation project(':app')的東西。

這里有一個工作 gradle 文件的示例,嘗試刪除implementation project(':app')並重新同步。

apply plugin: 'com.android.application'
android {
  compileSdkVersion 27
  defaultConfig {
    applicationId "com.example.amvt_notebook4.codigoqrtest"
    minSdkVersion 19
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }
  buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies
{
  implementation fileTree(include: ['*.jar'], dir: 'libs')
  implementation 'com.android.support:appcompat-v7:27.1.1'
  implementation 'com.android.support:design:27.1.1'
  implementation 'com.android.support.constraint:constraint-layout:1.1.0'
  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'com.android.support.test:runner:1.0.2'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
  implementation 'com.google.android.gms:play-services:10.0.1'
  implementation 'com.android.support:recyclerview-v7:27.1.1'
  implementation 'com.android.support:cardview-v7:27.1.1'
  implementation files('build/libs/mail.jar')
  implementation files('build/libs/additionnal.jar')
  implementation files('build/libs/activation.jar')
  implementation files('build/libs/jtds-1.3.1.jar')
  implementation 'com.android.support:multidex:1.0.3'
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM