API 28 (P) 的 Android 设计支持库不起作用

标签 android android-studio android-design-library android-9.0-pie

我已经成功配置了android-P SDK环境。当我尝试使用 android 设计支持库时,我遇到了项目构建错误。项目配置为:

IDE:3.2 Canary 17 目标 API:28 编译 API:28

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.app.navigationpoc"
        minSdkVersion 21
        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'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'

    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
}

构建失败的错误是:

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

最佳答案

您可以使用以前的 API 包版本的 Artifact 或新的 Androidx,不能同时使用。

如果您想使用以前的版本,请将您的依赖项替换为

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.1'

    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'

    implementation 'com.android.support:design:28.0.0-alpha3'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
}

如果你想使用Androidx:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha3'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'

    implementation 'com.google.android.material:material:1.0.0-alpha3'
    implementation 'androidx.cardview:cardview:1.0.0-alpha3'
}

关于API 28 (P) 的 Android 设计支持库不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52716118/

相关文章:

java - RSS Feed 解析并在 ListView 中显示结果,然后在单击帖子时显示正文

java - Android Studio 3.0 金丝雀 8 : Advanced profiling is unavailable for the selected process

android - 从 Android Studio 在设备上安装 Android 应用

android - 在工具栏上 app :popupTheme ="@style/AppTheme.PopupOverlay" do? 是什么

android - 如何在 TextInputLayout 中禁用即时焦点?

android - 在 TextView 中居中文本

android - 检查 GPS 可访问性

android - 如何使用 Android Studio 重新安装应用程序

android - 编辑器左侧装订线中的符号 ("gutter icons")

android - 添加 Android 设计支持库后,Gradle 构建速度非常慢