繁体   English   中英

Android Material 和 appcompat Manifest 合并在 react-native 或 ExpoKit 中失败

[英]Android Material and appcompat Manifest merger failed in react-native or ExpoKit

我将 '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-device-info'升级到version 2.1.2为我修复了错误。 github.com/facebook/react-native/issues/25294#issuecomment-503024749

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

根本原因是迁移到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"

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

googlePlayServicesVersion=16.1.0
firebaseVersion=17.6.0

我通过参考@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。

<application>标签内的AndroidManifest.xml添加'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>

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

compile 'com.google.android.gms:play-services-<service_name>:+'

compile 'com.google.android.gms:play-services-<service_name>:16.0.0'

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

在这个问题上花了一整天之后。 最后,我已经解决了这个问题。

我从 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"

根据@Frank 的回答,库使用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"

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

在此处输入图片说明

从这里开始,只需在 google play 服务或 firebase 服务或任何此类库之前检查每个 gradle 构建文件是否有+号。 这在这个答案中也有解释。

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

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

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

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

我遇到了同样的问题,只需升级react-native-device-info并运行以下命令

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

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

如果你没有使用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 > deps.txt并搜索“androidx”没有返回任何结果 - 这就是我们正在寻找的。

在项目上运行干净后,构建工作。

谷歌播放服务重大变化。 请参阅发行说明

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

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

暂无
暂无

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

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