导入模块后清单合并失败

时间:2019-06-28 09:02:23

标签: java android gradle android-manifest

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

  

清单合并失败:属性application @ appComponentFactory   值=(android.support.v4.app.CoreComponentFactory)来自   [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是以下

应用程序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

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"
}

如何解决?

谢谢

2 个答案:

答案 0 :(得分: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.+" +,因为还有其他各种Google服务包可用,而且它们的版本号也不相同。这将捕获16.X.X而不是上方。 17.X.X还有其他问题。

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

解决方案

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"

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

使用4.10.1确保gradle-wrapper.properties

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

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

gradle.properties:

android.enableJetifier=false
android.useAndroidX=false

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

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

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

然后添加到安装后脚本

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

答案 1 :(得分:-1)

尝试应用建议,添加

key

到应用标签

相关问题