首页 文章

在Gradle中加载材料 - 下载失败'android-P'

提问于
浏览
1

我是Android Studio的新手 .

我想将 Material 依赖项添加到我的项目中但是 sync 我的gradle文件时收到错误消息 .

这个帖子(link)告诉我使用 compileSdkVersion 'android-P' ,但这导致android工作室告诉我下载 android-P 它没有做,当我点击下载(... android-P无法下载...) .

所以我回去尝试它,如材料主页get started所述 .

您可以在下面找到我的相应代码和错误消息:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.chris.doghelper"
        minSdkVersion 22
        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'
        }
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.android.material:material:1.0.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'
}

和错误消息:

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-24:19 to override.

你有解决我的问题的方法吗?

1 回答

  • 1

    这是因为您将新材料库与旧版支持库一起使用 . 您必须将 android.support 迁移到 androidx 才能使用 com.google.android.material .

    如果您还不想切换到新的 androidxcom.google.android.material 包,则可以通过 com.android.support:design:28.0.0 依赖项使用Material Components .

    关注Link1Link2 .

    要切换androidX,请按照此Link3进行操作 .

    我走得更深,我找到了你 .

    它一定会帮到你 .

    快乐的编码!

相关问题