【问题标题】:Could not find method implementation() for arguments [org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50]找不到参数的方法 implementation() [org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50]
【发布时间】:2020-08-29 21:51:45
【问题描述】:

我也是 Android 开发和 Flutter 的新手。在导出我的应用程序时,我遇到了很多当前卡在此错误上的错误。不知道如何解决这个问题。如果你们能帮助我,那将是非常有帮助的!

收到此错误:

FAILURE: Build failed with an exception.

* Where:
Build file 'F:\GAMES\quiz\android\app\build.gradle' line: 88

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method implementation() for arguments [org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDepen
dencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done                       4.3s
Gradle task assembleRelease failed with exit code 1

我认为 gradle 文件中一定有一些错误,因此包括下面的 gradle 文件:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    kapt { generateStubs = true }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.karat18.quiz"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            profile {
                matchingFallbacks = ['debug', 'release']
            }
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

apply plugin: 'kotlin-android'
buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.android.tools.build:gradle:3.6.3'
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        //testImplementation 'junit:junit:4.12'
        //androidTestImplementation 'androidx.test:runner:1.2.0'
        //androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
        //implementation 'com.google.firebase:firebase-analytics:17.4.1'

    }
    allprojects {
        // ...

        repositories {
            // Check that you have the following line (if not, add it):
            google()  // Google's Maven repository
            // ...
        }
    }
}

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

【问题讨论】:

    标签: java android flutter kotlin gradle


    【解决方案1】:

    您添加implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"dependencies 块位于buildscript 块内。 这意味着您正在尝试修改构建使用的依赖项,而不是项目使用的依赖项。

    • 仅使用classpath 配置构建依赖项,因此如果这是您的目标,请将implementation 替换为classpath
    • 项目依赖项必须在与android 块处于同一级别的dependencies 块中声明。有关详细信息,请参阅Android documentation。因此,如果这是您的目标,请将该行移至新的 dependencies

    【讨论】:

      【解决方案2】:

      在 build.gradle (Module:app) 中替换

      实施 “org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version”

      实施 “org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version”

      并在 build.gradle (Module:project) 中将版本更改为

      ext.kotlin_version = '1.3.0'

      【讨论】:

      • 不知道怎么回事,但是在复制代码并运行到一个新的项目文件后,它不再显示这样的错误了!
      猜你喜欢
      • 2019-07-05
      • 2020-02-26
      • 2018-05-24
      • 2017-08-08
      • 2020-11-15
      • 1970-01-01
      • 2021-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多