【问题标题】:Android Material and appcompat Manifest merger failed in react-native or ExpoKitAndroid Material 和 appcompat Manifest 合并在 react-native 或 ExpoKit 中失败
【发布时间】:2019-06-18 05:40:29
【问题描述】:

我将“android.support:appcompat-v7”更新为28.0.0

但它带来了构建错误。

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.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).

    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:8:5-23:19 to override.

然后我的 Logcat 中出现此错误:

清单合并失败

我的 app.gradle:

  configurations.all {
    resolutionStrategy.force 'com.android.support:design:28.0.0'
    resolutionStrategy.force "com.android.support:support-v4:28.0.0"
    resolutionStrategy.force "com.android.support:support-media-compat:28.0.0"
  }
...
dependencies {
  implementation 'com.android.support:multidex:1.0.1'

  // Our dependencies
  implementation 'com.android.support:appcompat-v7:28.0.0'


  implementation 'com.android.support:appcompat-v7:28.0.0'
}

我该如何解决?

我需要你的解决方案。

提前谢谢你。

【问题讨论】:

  • 遇到同样的问题....我的应用昨天运行良好,但今天我只运行命令react-native run-android,剩下的就是历史了。
  • @PatelDhara 不幸的是,没有,如果我有解决方案,我一定会在哪里发布一些内容
  • @PatelDhara 这很棒,你是怎么做到的?你能分享一下解决方案吗?
  • @MDHusnainTahir 我已经分享了我的解决方案作为答案。你可以在下面看到。如果该解决方案对您不起作用,请共享您的 package.json 文件。我可以帮你

标签: android react-native react-native-android expo


【解决方案1】:

'react-native-device-info' 升级到version 2.1.2 为我修复了该错误。见github.com/facebook/react-native/issues/25294#issuecomment-503024749

简而言之:库使用"services-gcm:+"作为依赖,最新的gcm版本导致了这个问题。

【讨论】:

    【解决方案2】:

    根本原因是相关迁移到Androidx,google play服务更新到androidX 感谢MR03web 这个问题属于react-native-device-info?最好的选择是使用

    升级react-native-device-info
    yarn upgrade react-native-device-info@2.1.2
    cd android && gradlew clean
    react-native run-android
    

    或者如果您不想升级,您应该像这样从react-native-device-info 中排除com.google.android.gms。谢谢

    implementation(project(":react-native-device-info"),  {
      exclude group: "com.google.android.gms"
    })
    implementation "com.google.android.gms:play-services-gcm:16.0.0"
    

    【讨论】:

    • 我没有使用包react-native-device-info,我得到了同样的错误。
    • 谢谢伙计。这对我有用 "react-native": "0.59.5",
    【解决方案3】:

    将以下内容添加到您的 gradle.properties 然后清理/重建

    googlePlayServicesVersion=16.1.0
    firebaseVersion=17.6.0
    

    【讨论】:

      【解决方案4】:

      我通过参考@MehulSolanki 的答案通过搜索找到了解决方案。

      我加了

      tools:replace="android:appComponentFactory"
      android:appComponentFactory="whateverString"
      

      在我的AndroidManifest.xml

      并更新 com.android.tools.build:gradl:

      dependencies {
          classpath 'com.android.tools.build:gradle:3.2.1'
        }
      

      并将其添加到您的 gradle.properties 文件中

      android.useAndroidX=true
      android.enableJetifier=true
      

      错误:[TAG] 无法解析变量“${animal.sniffer.version}”

      错误:[TAG] 无法解析变量“${junit.version}”

      如果出现上述错误

      1. 文件 -> 使缓存无效/重新启动
      2. 构建 -> 清理项目

      错误:包 android.support.annotation 不存在 错误:找不到符号类 Nullable

      如果出现上述错误

      添加implementation 'androidx.annotation:annotation:1.1.0'

      更改import android.support.annotation.Nullable; => androidx.annotation.Nullable;

      更改import android.support.annotation.NonNull; => androidx.annotation.NonNull;

      编译版本目标版本应该是28.

      【讨论】:

      • @HussainSherwani 你能更新classpath 'com.android.tools.build:gradle:3.2.1'吗?
      • 类路径已更新,即classpath 'com.android.tools.build:gradle:3.3.1'
      • @HussainSherwani 将此添加到您的 gradle.properties 文件中 android.useAndroidX=true android.enableJetifier=true
      • 感谢伙伴的帮助,但这不会起作用,因为这些行 libraries 不使用 androidx package 在添加这些行后将无法编译我在 @react-native-community_netinfo 库中遇到问题使用 android 包而不是 androidx
      • @HussainSherwani 你添加了 real-native-commonity_netinfo 库吗?
      【解决方案5】:

      AndroidManifest.xml 内的&lt;application&gt; 标签中添加'tools:replace="android:appComponentFactory"'

      你的AndroidManifest.xml

      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="ru.chopcode.myapplication">
      
          <application
              tools:replace="android:appComponentFactory"
              android:allowBackup="true"
              android:icon="@mipmap/ic_launcher"
              android:label="@string/app_name"
              android:roundIcon="@mipmap/ic_launcher_round"
              android:supportsRtl="true"
              android:theme="@style/AppTheme">
         </application>
      

      【讨论】:

        【解决方案6】:

        降级 Google Play 服务版本。在android/app/build.gradle

        compile 'com.google.android.gms:play-services-&lt;service_name&gt;:+'

        compile 'com.google.android.gms:play-services-&lt;service_name&gt;:16.0.0'

        所以在我的例子中 location。但在其他人的情况下,它可能是任何其他 Google Play 服务(如列表中的http://www.androiddocs.com/google/play-services/setup.html)。

        【讨论】:

        • 降级 google play 服务版本对我有用!谢谢
        【解决方案7】:

        在这个问题上花了一整天。终于解决了这个问题。

        我从 react-native-device-info 和 react-native-fast-image 库中得到了这个错误。 我只是从 package.json 文件中删除该库,然后安装

        "react-native-device-info": "^2.1.2", "react-native-fast-image": "^6.0.3" 这个最新版本

        我用过以下gradle版本

        classpath 'com.android.tools.build:gradle:3.3.1'
        

        我使用了以下属性版本

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

        我用过以下版本

        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
        

        【讨论】:

          【解决方案8】:

          This 答案应该可以帮助大多数人。如果它仍然没有,那么解决这个问题的方法(这不是那么好)是你在 android studio 中打开 android 项目。那应该获取所有的gradle文件。在右侧,视图应该是 android。

          从这里只需检查每个 gradle 构建文件在 google play 服务或 firebase 服务或任何此类库之前是否有 + 标志。 this 回答中也对此进行了解释。

          之后,您可以按照上面答案中的说明进行更改。 像这样。

          implementation(project(":react-native-admob"),  {
                  exclude group: "com.google.android.gms"
          })
          implementation "com.google.android.gms:play-services-ads:16.0.0"
          

          或者,如果库正在使用一个变量,或者作为最后的手段自行更改它,您可以提供一个变量。

          我把它放在这里的原因是,任何厌倦了这个突然突然出现的错误的新手都可以有效地解决它而不是......死。哈哈。

          【讨论】:

            【解决方案9】:

            我也遇到了同样的问题,升级react-native-device-info然后运行以下命令

            npm upgrade react-native-device-info@latest
            react-native run-android
            

            【讨论】:

              【解决方案10】:

              根据@Frank's的回答库使用services-gcm:+作为依赖,最新的gcm版本导致了这个问题。

              我在我的项目中使用了:react-native-admob。所以我只是在android/app/build.gradle中更改以下行

              发件人:

              implementation project(':react-native-admob')
              

              到:

              implementation(project(":react-native-admob"),  {
                      exclude group: "com.google.android.gms"
              })
              implementation "com.google.android.gms:play-services-ads:16.0.0"
              

              【讨论】:

                【解决方案11】:

                如果你没有使用react-native-device-info,但有同样的错误,它可能是你项目中的另一个库。

                使用它来查找相关库:

                cd your-react-native-project/android
                ./gradlew app:dependencies > deps.txt
                

                然后检查 deps.txt 文件中的关键字“androidx”。然后你就可以快速找到哪个原生模块正在使用它。

                在我的例子中是react-native-camera,上面的解决方案很好但还不够,所以我不得不将它添加到local.properties:

                firebaseVersion=17.6.0
                googlePlayServicesVersion=16.1.0
                googlePlayServicesVisionVersion=16.2.0
                

                编辑: 在这些修复之后,运行./gradlew app:dependencies &gt; deps.txt 并搜索“androidx”没有返回任何结果——这就是我们正在寻找的。​​p>

                在项目上运行 clean 后,构建工作正常。

                【讨论】:

                  【解决方案12】:

                  升级react-native-device-info 到版本 2.1.2 修复我的问题

                  【讨论】:

                    【解决方案13】:

                    Google Play 服务的重大更改。见Release Notes

                    解决此问题的简单方法是更改​​ Google Play 服务的版本。

                    将所有 com.google.android.gms:play-services-* 依赖项更改为版本 16

                    【讨论】:

                      猜你喜欢
                      • 2015-09-12
                      • 2017-03-13
                      • 2017-05-30
                      • 1970-01-01
                      • 2023-01-04
                      • 2020-01-03
                      • 1970-01-01
                      • 1970-01-01
                      相关资源
                      最近更新 更多