我已经成功配置了android-P SDK环境 . 当我尝试使用android设计支持库时,我面临项目构建错误 . 项目配置是:
IDE: 3.2 Canary 17 Target API: 28 Compile 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'
}
并且构建失败的错误是:
清单合并失败:来自[androidx.core:core:1.0.0-alpha3] AndroidManifest.xml:22:18-86的属性应用程序@ appComponentFactory值=(androidx.core.app.CoreComponentFactory)也出现在[com . android.support:support-compat:28.0.0-alpha3] AndroidManifest.xml:22:18-91 value =(android.support.v4.app.CoreComponentFactory) . 建议:在AndroidManifest.xml:6:5-40:19中添加'tools:replace =“android:appComponentFactory”'来覆盖 .
11 回答
下面的代码与我完美配合:
试试这个:
您既可以使用先前的API包版本的工件,也可以使用新的Androidx,而不是两者 .
如果您想使用以前的版本,请将依赖项替换为
如果你想使用Androidx:
重要更新
在
28.0.0
之后,Android不会更新支持库 .所以使用库AndroidX .
Don't use both support and androidx in app gradle.
Your library module or dependencies can still have support libraries. Androidx Jetifier will handle it.
使用稳定版本的
androidx
或任何库,因为alpha,beta,rc可能存在您不希望随应用程序提供的错误 .在你的情况下
添加这个:
到您的清单应用程序
希望它能够解决
1.将这些代码添加到app / build.gradle:
2.修改了sdk和工具版本到28:
2.在AndroidManifest.xml文件中,您应该添加两行:
谢谢你的答案@Carlos Santiago:Android design support library for API 28 (P) not working
我用过那个选项:
https://developer.android.com/jetpack/androidx/migrate
我通过将所有
androidx.*
替换为appropiate package name
来跨越这种情况 .改变你的路线
至
风陵渡
tools:replace="android:appComponentFactory"
在我的情况下,这是完美的工作..我在清单文件中添加了下面两行代码
Note: You should not use the com.android.support and com.google.android.material dependencies in your app at the same time.
添加Android的Material Components
}
如果您的应用目前依赖于原始设计支持库,则可以使用Android Studio提供的Refactor to AndroidX ...选项 . 这样做会更新您的应用程序的依赖项和代码,以使用新打包的androidx和com.google.android.material库 .
如果您还不想切换到新的androidx和com.google.android.material包,可以通过com.android.support:design:28.0.0-alpha3依赖项使用Material Components .
打开文件gradle.properties并将这两行添加到它:
清洁和建设