Android设计支持库适用于API 28(P)不起作用。
Android设计支持库适用于API 28(P)不起作用。
我已成功配置了android-P SDK环境。但是在尝试使用android design support库时,我遇到了项目构建错误。项目配置如下:
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合并失败:属性application@appComponentFactory的值
(androidx.core.app.CoreComponentFactory) 来自
[androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86 同样存在于 [com.android.support:support-compat:28.0.0-alpha3]
AndroidManifest.xml:22:18-91
的值是 (android.support.v4.app.CoreComponentFactory)。建议:在 AndroidManifest.xml:6:5-40:19 的元素中添加 'tools:replace="android:appComponentFactory"' 来进行覆盖。
Android design support library for API 28 (P) not working这个问题的出现原因是因为Android在28.0.0版本之后将不再更新support libraries,而是推荐开发者迁移到AndroidX 1.0.0。所以解决方法是使用AndroidX库,不要在项目中同时使用support libraries和AndroidX。但是你的库模块或依赖项仍然可以使用support libraries,Androidx Jetifier会处理这个问题。另外,为了保证应用程序的稳定性,建议使用稳定版本的androidx或任何库,因为alpha、beta和rc版本可能存在bug。如果遇到该问题,可以尝试在菜单中选择Build > Clear Project,然后选择Build > Make Project,如果这样还不行,可以选择Invalidate cache and restart。
Android design support library for API 28 (P) not working 这个问题的出现的原因是在使用Android设计支持库时,可能同时使用了之前的API包版本和新的Androidx版本。解决方法是要么使用之前的版本,要么使用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' }
这个回答应该被接受。更多信息请参考medium.com/mindorks/...
为什么在implementation中的material中的com没有被替换掉呢?