android - 如何包含 Material 设计库

标签 android ant material-design

我想将 Android 的 Material 设计库包含到我的项目中,但我有点困惑在哪里可以找到它以及如何包含它。我从github下载了该库https://github.com/material-components/material-components-android .

我尝试使用 gradle 构建它,但出现以下错误,我似乎找不到解决方案:

> Configure project :catalog
Checking the license for package Android SDK Build-Tools 27.0.3 in /mnt/sda2/android/Sdk/licenses
Warning: License for package Android SDK Build-Tools 27.0.3 not accepted.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':catalog'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
     build-tools;27.0.3 Android SDK Build-Tools 27.0.3

我通过 SDK 管理器安装了“build-tools 27.0.3”。有关如何绕过此问题的任何提示吗?

据我了解,我需要首先编译该库,然后将其放入/lib 文件夹中,然后告诉“Ant”构建工具包含该库才能使用它。它是否正确?也许有一个地方我可以简单地下载已经预编译的库?我似乎无法在 SDK 管理器中找到它。谢谢!

我现在正在尝试使用 Gradle 构建项目,这是我的 build.gradle 文件:

buildscript {
  repositories {
    google()
    jcenter()
  }
  dependencies {
        implementation 'com.google.android.material:material:1.0.0-beta01'
  }
}

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

但我不断收到错误:

Could not find method implementation() for arguments [com.google.android.material:material:1.0.0-beta01] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

请问有什么提示吗?

更新

我下载了 android studio,按照说明进行操作,这是我的 build.gradle 的 fragment :

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.3'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    compile "com.android.support:design:27.1.1"
}

但现在我遇到了不同的错误:

Could not find method compile() for arguments [com.android.support:design:25.1.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager

我打开了 SDK 管理器,但 Android 支持存储库已安装 (rev47)。有什么提示吗?谢谢!

最佳答案

确保您的compiledSdkVersion是28

在 build.gradle 中,确保存储库部分包含 Google 的 Maven 存储库 google() 即,

添加这个

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

然后,添加依赖项。

dependencies {
  implementation 'com.google.android.material:material:1.0.0'
}

然后重构为 AndroidX。

单击“重构”,然后单击“迁移到 AndroidX”。

然后它将更新您应用的依赖项和代码以使用新打包的 androidx 和 com.google.android.material 库。

如果您不想切换到 androidx,可以使用 com.android.support:design:28.0.0 依赖项。

注意:您不能在应用中同时使用 com.android.support 和 com.google.android.material 依赖项。

关于android - 如何包含 Material 设计库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51504519/

相关文章:

android - Android 5.1 中的语音通话录音

android - 构建 Android LatinIME

java - 如何使用 build.xml 在 java 代码中设置属性

gradle - 通过Gradle运行时删除Ant日志前缀

android - JQuery .on() 方法未绑定(bind)到 Android 4.0 Phonegap 应用程序中的所有元素

android - 如何在 jetpack compose 中使用来自 URI 的 Coil 加载图像

eclipse - 为什么 Eclipse 可能无法在 Ant 构建文件的运行选项中显示 "Ant Build"?

android - ?attr/不在工具栏中设置正确的颜色

java - 如何在 MaterialCalendarView 中显示特定日期和时间的事件?

jquery - Material 设计精简版(MDL)中的水平和垂直中心卡