Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

java - Manifest merger failed after import a module

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

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.

The build.gradle are the followings

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

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

build.gradle of sdkB

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

How can solve it?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.

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

I would recommend to avoid AndroidX until 0.60.0 has landed.

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

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', '+')}"

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

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.

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.

SOLUTION

android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 21
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
        googlePlayServicesVersion = "16.+"
    }
...

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

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

ensure your gradle-wrapper.properties using 4.10.1

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

and finally ensure you are not using android X.

gradle.properties:

android.enableJetifier=false
android.useAndroidX=false

Additional Step (You might need this)

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-dev or yarn add jetifier --dev

then add to postinstall script

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...