简体   繁体   中英

Manifest merger failed - android studio error

I changed the name of the package to "com.xxx.xxx" with Refactor > Rename and changed the name of the package and application identifiers to manifest and gradle . Successful synchronization, everything is OK. According to the instructions delevopers.google Getting Started and delevopers.google Intermediate Ads ads built into my application, previously included in the project structure AdMob . When using gradle, but it cost me to try to run the application on a physical level.

Manifest merge error: Attribute application @ appComponentFactory value = (android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml: 22: 18-91
also present in [androidx.core: core: 1.0.0] AndroidManifest.xml: 22: 18-86 value = (androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools: replace = "android: appComponentFactory"' to the <application> element in AndroidManifest.xml: 8: 5-27: 19 to override.

If you advertise android.useAndroidX = true and android.enableJetifier = true in the gradle properties, then everything becomes even worse, because my MainActivity.java extendit is AppCompatActivity , which is not used with the above gradle properties (android.useAndroidX = true)

It is because in gradle you have to also change it to androidX and check your dependency with this

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.0'

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.google.android.gms:play-services-ads:18.1.1'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}




android {
    compileSdkVersion 28

defaultConfig {
        applicationId "com.example1.*appname*"
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 3
        versionName "3.0"
        **testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"**//check this is their or not
    }

sometimes we forget to define testInstruement runner

Well since you did not post your build.gradle file

I suspect that you have the old android support libraries and you are trying to migrate to AndroidX, According to your error it appears that you should be using this one instead

implementation "androidx.appcompat:appcompat:1.0.2"

of

implementation "com.android.support:support-compat:28.0.0"

And a couple of other files related files in that same manner, now before trying to manually fix the paths of androidx , I would recommend that you update to the latest version of Android Studio (3.4.2) and do click Migrate to AndroidX inside the refactor menu

点击迁移到Android X

Now sometimes, the error might be in the libraries you want to depend to If that's the case , heres a workaround ...

configurations {
    all*.exclude module: 'support-v4' // This removes all other versions of `support-v4` if gets duplicated from all the artifacts.
    api project(':your-awesome-library-goes-here')
}

also if there is a slight chance that you are using butterknife

        android{
.
.
           // Butterknife requires Java 8.
            compileOptions {
                sourceCompatibility JavaVersion.VERSION_1_8
                targetCompatibility JavaVersion.VERSION_1_8
            }
.
.
        }

Do a sync , if you still see errors ... then try to check for dependencies to see which library is the culprit

./gradlew app:androidDependencies

Where app is your module's name

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM