在实现AndroidX依赖项后,清单合并失败
我正在尝试用MVVM架构构建一个应用程序,为此,我在我的在实现AndroidX依赖项后,清单合并失败,android,gradle,mvvm,Android,Gradle,Mvvm,我正在尝试用MVVM架构构建一个应用程序,为此,我在我的build.gradle中实现了以下内容: dependencies { def lifecycle_version = "2.0.0" def room_version = "2.1.0-alpha03" implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcomp
build.gradle
中实现了以下内容:
dependencies {
def lifecycle_version = "2.0.0"
def room_version = "2.1.0-alpha03"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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 "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
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.
清单合并失败:属性application@appComponentFactory值=(android.support.v4.app.CoreComponentFactory)来自[com.android.support:support compat:28.0.0]AndroidManifest.xml:22:18-91
在[androidx.core:core:1.0.0]AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory)中也存在。
建议:在AndroidManifest.xml:5:5-19:19处的元素中添加“tools:replace=“android:appComponentFactory””以覆盖。
堆栈建议我将tools:replace=“android:appComponentFactory”
放在清单中的
元素中,但这本身会导致更大的错误
谢谢。如果要使用AndroidX,所有支持依赖项都必须是AndroidX
这包括appcompat-v7
和约束布局
AndroidX有一个支持库,它为您提供了所有等价的支持库
这将需要一些手动迁移,因为某些导入(AppCompatActivity、ConstraintLayout等)现在将无效。如果您尝试构建,它将告诉您这些无效导入在构建错误日志中的位置
另外,请确保在XML中找到AppCompat视图的任何用途(如ConstraintLayout),并将其替换为AndroidX对应的视图(只需开始键入视图类名,Android Studio将建议正确的一个)。如果要使用AndroidX,则所有支持依赖项都必须是AndroidX
这包括appcompat-v7
和约束布局
AndroidX有一个支持库,它为您提供了所有等价的支持库
这将需要一些手动迁移,因为某些导入(AppCompatActivity、ConstraintLayout等)现在将无效。如果您尝试构建,它将告诉您这些无效导入在构建错误日志中的位置
另外,请确保在XML中找到AppCompat视图的任何用途(如ConstraintLayout),并将其替换为AndroidX对应视图(只需开始键入视图类名,Android Studio将建议正确的一个)。漫游者是对的。我必须把所有东西都换成AndroidX,我就是这么做的。这是我的新依赖项:
dependencies {
def lifecycle_version = "2.0.0"
def room_version = "2.1.0-alpha03"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
}
流浪者是对的。我必须把所有东西都换成AndroidX,我就是这么做的。这是我的新依赖项:
dependencies {
def lifecycle_version = "2.0.0"
def room_version = "2.1.0-alpha03"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
}
谢谢,这解决了我的问题。我投了你一票,接受了你的回答。如果你认为这是一个被问得很好的问题,你能不能也给我一张赞成票?谢谢,这就解决了我的问题。我投了你一票,接受了你的回答。如果你认为这是一个被问得很好的问题,你能不能也给我一张赞成票?