【问题标题】:Could not find method api() for arguments [directory 'libs']找不到参数 [目录'libs'] 的方法 api()
【发布时间】:2020-01-28 00:08:44
【问题描述】:

打开文件

这是我的 gradle 文件:

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 27
        buildToolsVersion "27.0.1"
        defaultConfig {
            applicationId "com.landdrops.cricketfantacy.androidbottom"
            minSdkVersion 21
            targetSdkVersion 27
            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(include: ['*.jar'], dir: 'libs')
        implementation 'com.android.support:appcompat-v7:27.0.1'
        implementation 'com.android.support:design:27.0.1'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test.runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2.2'
    }

我来了

错误:(23, 0) 无法在 org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler 类型的对象上找到参数 [directory 'libs'] 的方法 implementation()。 打开文件

【问题讨论】:

  • 你的gradle版本和android插件版本是多少?
  • 尝试用实现替换编译。
  • 我已经尝试过使用实现和 API 但不起作用。

标签: android android-studio android-gradle-3.0


【解决方案1】:

对于我的 Java 库项目,我需要使用 java-library 插件而不是 java

- apply plugin: 'java'
+ apply plugin: 'java-library'

【讨论】:

    【解决方案2】:

    我能够通过将大多数依赖项更新到当前版本来纠正此错误(不确定是否有必要,并且当最新版本与另一个组件的依赖项冲突时,我恢复了一个版本并清除了不匹配。在这一次,我将 27.1.0 用于 appCompat,设计。(我使用 27.0.3 作为构建工具)

    Gradle 包装器到 4.4 版(这实际上是在加载过时的项目和更新插件时提示我做的)

    调整项目 build.gradle 以使用: 类路径'com.android.tools.build:gradle:3.1.1'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-21
      • 1970-01-01
      • 1970-01-01
      • 2017-03-16
      • 1970-01-01
      • 1970-01-01
      • 2023-01-20
      • 2018-05-16
      相关资源
      最近更新 更多