java - 导入模块后清单合并失败
问题描述
嗨,我正在开发一个 sdk,当我将这些 SDK 添加到应用程序项目中时,我收到以下错误:
清单合并失败:属性 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.1] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:22:5-125:19 to override.
build.gradle 如下
应用程序构建.gradle
dependencies {
implementation project(':sdkA')
implementation project(':sdkB')
implementation 'org.webrtc:google-webrtc:1.0.28032'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:preference-v7:28.0.0'
implementation 'com.android.support:preference-v14:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:gridlayout-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'io.michaelrocks:libphonenumber-android:8.4.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android:flexbox:1.0.0'
implementation 'com.github.woxthebox:draglistview:1.6.3'
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16'
implementation('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
transitive = true
}
// Google Lifecycle Components
implementation "android.arch.lifecycle:extensions:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
}
sdkA 的 build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'org.webrtc:google-webrtc:1.0.28032'
implementation('io.socket:socket.io-client:1.0.0') {
exclude group: 'org.json', module: 'json'
}
implementation('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
transitive = true
}
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
// Google Lifecycle Components
implementation "android.arch.lifecycle:extensions:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
sdkB 的 build.gradle
dependencies {
implementation "com.android.support:appcompat-v7:27.1.1"
implementation "com.android.support:recyclerview-v7:27.1.1"
}
怎么解决?
谢谢
解决方案
好的,我在最后一天左右一直在自己解决这个问题。恶梦。
但我现在至少可以为我一直在从事的项目工作,该项目非常大,并且有很多额外的 android 依赖项。
请参阅 Mike Hardy 提供了很大帮助的这个问题。https://github.com/mikehardy/jetifier/issues/27
我建议在 0.60.0 登陆之前避免使用 AndroidX。
问题
的根源对于我们大多数人来说,问题的根源是+
gradle 依赖项中的范围选择器。
如此处所示,作为 react-native-google-analytics-bridge 中的示例:
compile "com.google.android.gms:play-services-analytics:${safeExtGet('googlePlayServicesVersion', '+')}"
compile "com.google.android.gms:play-services-tagmanager-v4-impl:${safeExtGet('googlePlayServicesVersion', '+')}"
对于我们大多数人来说,我们没有在顶级 android/build.gradle 中设置 googlePlayServicesVersion 值
所以我们要指定googlePlayServicesVersion = "16.+"
+,因为还有其他各种可用的谷歌服务包,它们的版本号并不相同。这将捕获 16.XX 而不会超过。17.XX 有进一步的问题。
我们还想将 supportLibVersion 设置为 28.0.0,这是 android 支持库使用的:com.android.support:appcompat-v7 最常见。
解决方案
安卓/build.gradle
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 21
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
googlePlayServicesVersion = "16.+"
}
...
AndroidManifest.xml 顶行:
<manifest
xmlns:tools="http://schemas.android.com/tools"
应用标签:
tools:replace="android:appComponentFactory"
android:appComponentFactory="android.support.v4.app.CoreComponentFactory"
确保您的 gradle-wrapper.properties 使用 4.10.1
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
最后确保你没有使用 android X。
gradle.properties:
android.enableJetifier=false
android.useAndroidX=false
附加步骤(您可能需要这个)
失败也不起作用尝试添加jetifier。我们将使用它来运行您的 node_modules 并确保所有内容都使用非 androidx 库。
npm i jetifier --save-dev
或者yarn add jetifier --dev
然后添加到安装后脚本
"scripts": {
"postinstall": "jetify -r"
}
推荐阅读
- angular - How can I get a component instance from within an event handler in Angular?
- r - 如何在 R 中绘制顶级观察值
- reactjs - 如何使用 Appsync Graphql 实现群聊?
- google-apps-script - 使用自动脚本发送电子邮件
- javascript - React Native 无法读取未定义的属性“导航”
- entity-framework-core - 调用标准库 DLL 时无法加载文件或程序集“Microsoft.EntityFrameworkCore”
- visual-studio-code - phpcs:请求工作区/配置失败并显示消息:无法找到 phpcs
- java - 为什么 Java *sort* HashMap 条目,即使它不应该?
- python - 当我计算列表中连续元素之间的差异时,如何保持列表中的第一个元素不变?
- c# - 无法加载文件或程序集 CefSharp.Core.Runtime