导入模块后清单合并失败 [英] Manifest merger failed after import a module

查看:98
本文介绍了导入模块后清单合并失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个SDK,当我将这些SDK添加到应用程序项目中时,出现以下错误:

Hi I am developing a sdk, and when I add these SDK into a app proyect I get the following error:

清单合并失败:属性application @ appComponentFactory 值=(android.support.v4.app.CoreComponentFactory)来自 [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91

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.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是以下

The build.gradle are the followings

应用程序build.gradle

App build.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

build.gradle of sdkA

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

build.gradle of sdkB

dependencies {
    implementation "com.android.support:appcompat-v7:27.1.1"
    implementation "com.android.support:recyclerview-v7:27.1.1"
}

如何解决?

谢谢

推荐答案

好,我在过去约一天的时间里一直在自己解决此问题.噩梦.

Ok I've been tackling this issue myself for the last day or so. nightmare.

但是我现在至少在我一直在从事的项目中都可以使用它,该项目相当大,并且具有许多其他的android依赖项.

but I have it working now at least for the project I've been working on which is quite large and with lots of additional android dependencies.

在迈克·哈迪(Mike Hardy)给予了极大帮助的情况下,请参见此问题. https://github.com/mikehardy/jetifier/issues/27

See this issue where Mike Hardy has been a great help. https://github.com/mikehardy/jetifier/issues/27

我建议在0.60.0降落之前避免使用AndroidX.

问题的来源 对于我们大多数人来说,问题的根源是gradle依赖项中的+范围选择器.

SOURCE OF THE PROBLEM the source of the problem for most of us is the + range selector in gradle dependencies.

如下所示,作为react-native-google-analytics-bridge中的示例:

as shown here as an example in 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值

for most of us we're not setting a googlePlayServicesVersion value in the top level android/build.gradle

所以我们要指定googlePlayServicesVersion = "16.+" +,因为还有其他各种Google服务包可用,而且它们的版本号也不尽相同.这将捕获16.X.X并且不会超过该值. 17.X.X还有其他问题.

so we'll want to specify googlePlayServicesVersion = "16.+" + because theres various other google service packages available and they're not all at the same version number. this will capture 16.X.X and not go above. 17.X.X holds further issues.

我们还想将supportLibVersion设置为28.0.0,这是android支持库使用的:com.android.support:appcompat-v7最常见.

And we also want to set supportLibVersion to 28.0.0 which is used by the android support libraries: com.android.support:appcompat-v7 the most common.

解决方案

android/build.gradle

android/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"

AndroidManifest.xml top line: <manifest xmlns:tools="http://schemas.android.com/tools"

应用标签: tools:replace="android:appComponentFactory" android:appComponentFactory="android.support.v4.app.CoreComponentFactory"

application tag: tools:replace="android:appComponentFactory" android:appComponentFactory="android.support.v4.app.CoreComponentFactory"

使用4.10.1确保gradle-wrapper.properties

ensure your gradle-wrapper.properties using 4.10.1

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

并最终确保您没有使用android X.

and finally ensure you are not using android X.

gradle.properties:

gradle.properties:

android.enableJetifier=false
android.useAndroidX=false

其他步骤(您可能需要此步骤)

失败的尝试也尝试添加喷射器.我们将使用它来运行您的node_modules并确保所有内容都使用非androidx库.

failing that doesn't work try adding jetifier as well. We'll use this to run through your node_modules and ensure everything is using the non androidx libraries.

npm i jetifier --save-devyarn add jetifier --dev

然后添加到安装后脚本

"scripts": {
   "postinstall": "jetify -r"
}

这篇关于导入模块后清单合并失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆