简体   繁体   English

清单合并失败-Android Studio错误

[英]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 . 我通过Refactor > Rename将包的名称更改为“ com.xxx.xxx”,并将包和应用程序标识符的名称更改为manifestgradle 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 . 根据指示将delevopers.google入门delevopers.google中级广告内置到我的应用程序中,这些广告先前包含在project structure AdMob中 When using gradle, but it cost me to try to run the application on a physical level. 使用gradle时,尝试在物理级别上运行该应用程序花了我很多时间。

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) 如果您在gradle属性中宣传android.useAndroidX = trueandroid.enableJetifier = true ,那么一切都会变得更糟,因为我的MainActivity.java扩展名是AppCompatActivity ,而上面的gradle属性未使用它(android.useAndroidX = true)

It is because in gradle you have to also change it to androidX and check your dependency with this 这是因为在gradle中,您还必须将其更改为androidX并以此检查您的依赖性

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 有时我们忘记定义testInstruement运行器

Well since you did not post your build.gradle file 好吧,因为您没有发布build.gradle文件

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 我怀疑您拥有旧的android支持库,并且正在尝试迁移到AndroidX,根据您的错误,看来您应该改用这个

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 现在,在尝试手动修复androidx路径之前,我还建议您将其他几个文件以相同的方式关联到文件,我建议您更新到最新版本的Android Studio (3.4.2)并在其中单击“ Migrate to AndroidX ”。重构菜单

点击迁移到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 app是您模块的名称

Cheers 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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