我正在尝试将Android Jetpack Room添加到Android项目中。
我在app gradle文件中添加了以下内容
def room_version = "2.1.0-alpha03"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
这是房间的最新版本。
但我得到以下构建错误,请帮忙!
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-19:19 to override.
我添加了生命周期,视图模型,导航,工作管理器,但没有任何问题。
添加后
'tools:replace="android:appComponentFactory"
得到以下错误
Manifest merger failed with multiple errors, see logs
我在用
如果您在app级build.gradle
文件的“依赖项”部分中使用不兼容的工件,则会发生这种情况。建议修复:Refactor
-> Migrate to AndroidX...
然后清理并重建项目。
或者,您可以在app级别的build.gradle
文件中替换它:
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-compat:28.0.0'
有了这个:
implementation 'androidx.core:core:1.0.1'
implementation 'androidx.appcompat:appcompat:1.0.2'
将这些行添加到gradle.properties
:
android.useAndroidX=true
android.enableJetifier=true
并在您的代码中手动修复未解析的引用。
然后同步项目 - >清理项目 - >重建项目。