【问题标题】:Can't import Android library无法导入 Android 库
【发布时间】:2018-11-11 20:07:15
【问题描述】:

我正在尝试使用 RecyclerView Helper,但无法使用它进行项目工作。 这是我正在尝试使用的库:https://github.com/nisrulz/recyclerviewhelper

但是得到这个错误:

   Could not find method implementation() for arguments [com.android.support:appcompat-v7:{latest version}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
    Please install the Android Support Repository from the Android SDK Manager.

这是我的 build.gradle:

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

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.0'

        def supportLibVersion="{latest version}"
// Required
        implementation "com.android.support:appcompat-v7:${supportLibVersion}"
        implementation "com.android.support:recyclerview-v7:${supportLibVersion}"

// RecyclerViewHelper
        implementation "com.github.nisrulz:recyclerviewhelper:${supportLibVersion}"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

【问题讨论】:

    标签: android jcenter


    【解决方案1】:

    我认为latest version 是占位符文本。 latest version 应替换为您需要的最新版本的 SDK。

    请用这个

    def supportLibVersion="27.1.1"
    

    而不是

    def supportLibVersion="{latest version}"
    

    你的库文档也有这一行

    其中{latest version} 对应于27.1.1 中的已发布版本。

    【讨论】:

      【解决方案2】:

      这是 project.gradle 文件,你在错误的 gradle 文件中导入库。请在 app.gradle 文件中导入这个库。

      在 app.gradle 上导入这个

      dependencies {
      
      
      
      implementation 'com.android.support:appcompat-v7:27.1.1'
      implementation 'com.android.support:recyclerview-v7:27.1.1'
      
      implementation 'com.github.nisrulz:recyclerviewhelper:27.1.1'
      
      }
      

      在 project.gradle 上导入这个

      allprojects {
        repositories {
          google()
          jcenter()
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2018-04-28
        • 2016-01-25
        • 1970-01-01
        • 2016-01-19
        • 2020-07-31
        • 1970-01-01
        • 2020-11-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多