在Gradle中加载素材-无法下载“ android-P”

时间:2018-12-09 11:44:08

标签: android android-studio gradle material-design

我真的是Android Studio的新手。

我想在项目中添加 Material 依赖,但是在sync我的gradle文件中,我收到一条错误消息。

此线程(link)告诉我使用compileSdkVersion 'android-P',但这导致android studio告诉我下载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 个答案:

答案 0 :(得分:1)

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

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

遵循Link1Link2

要切换androidX,请遵循此Link3

我走得更深,为你找到了它。

肯定会为您提供帮助。

编码愉快!