简体   繁体   English

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

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

I updated 'android.support:appcompat-v7' to 28.0.0 .我将 'android.support:appcompat-v7' 更新为28.0.0

But it brought an error from the build.但它带来了构建错误。

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.

Then I get this error in my Logcat:然后我在我的 Logcat 中收到此错误:

Manifest merger failed清单合并失败

my app.gradle:我的 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'
}

how do I fix it?我如何解决它?

I need your solutions.我需要你的解决方案。

Thank you in advance.先感谢您。

Upgrading 'react-native-device-info' to version 2.1.2 fixed the error for me.'react-native-device-info'升级到version 2.1.2为我修复了错误。 See github.com/facebook/react-native/issues/25294#issuecomment-503024749github.com/facebook/react-native/issues/25294#issuecomment-503024749

In short: the library used "services-gcm:+" as a dependency, and the latest gcm version caused this problem.简而言之:库使用了"services-gcm:+"作为依赖,最新的gcm版本导致了这个问题。

The root cause is related migration to Androidx , google play service updated to androidX Thanks to MR03web This problem belongs to react-native-device-info?根本原因是迁移到Androidx相关,google play 服务更新到 androidX 感谢MR03web这个问题属于 react-native-device-info? best option is to upgrade react-native-device-info using最好的选择是使用升级react-native-device-info

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

or if you don't want to upgrade you should exclude com.google.android.gms from react-native-device-info like this.或者如果你不想升级,你应该像这样从react-native-device-info排除com.google.android.gms Thanks谢谢

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

Add the following to your gradle.properties then clean/rebuild将以下内容添加到您的 gradle.properties 然后清理/重建

googlePlayServicesVersion=16.1.0
firebaseVersion=17.6.0

I found a solution through my search by referring to @MehulSolanki answer.我通过参考@MehulSolanki 答案通过搜索找到了解决方案。

I add我加

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

in my on AndroidManifest.xml在我的AndroidManifest.xml

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

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

And add this in your gradle.properties file并将其添加到您的 gradle.properties 文件中

android.useAndroidX=true
android.enableJetifier=true

ERROR: [TAG] Failed to resolve variable '${animal.sniffer.version}'错误:[TAG] 无法解析变量“${animal.sniffer.version}”

ERROR: [TAG] Failed to resolve variable '${junit.version}'错误:[TAG] 无法解析变量“${junit.version}”

In case of above error如果出现上述错误

  1. File -> Invalidate Caches / restart文件 -> 使缓存无效/重新启动
  2. Build -> Clean project构建 -> 清理项目

error: package android.support.annotation does not exist error: cannot find symbol class Nullable错误:包 android.support.annotation 不存在错误:找不到符号类 Nullable

In case of above error如果出现上述错误

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

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

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

Compile version and target version should be 28.编译版本目标版本应该是28。

Add 'tools:replace="android:appComponentFactory"' in your AndroidManifest.xml inside <application> tag<application>标签内的AndroidManifest.xml添加'tools:replace="android:appComponentFactory"'

Your AndroidManifest.xml你的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>

Downgrade Google Play service version.降级 Google Play 服务版本。 In android/app/build.gradle changeandroid/app/build.gradle更改

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

to

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

So in my case < sevice_name > was location .所以在我的情况下< sevice_name >location But in someone's else case it may be any other Google Play Service (like in list here http://www.androiddocs.com/google/play-services/setup.html ).但在其他情况下,它可能是任何其他 Google Play 服务(如http://www.androiddocs.com/google/play-services/setup.html中的列表)。

After spending a whole day on this issue.在这个问题上花了一整天之后。 Finally, I have resolved this issue.最后,我已经解决了这个问题。

I got that error from react-native-device-info and react-native-fast-image library.我从 react-native-device-info 和 react-native-fast-image 库中得到了那个错误。 I just remove that library from package.json file and then install我只是从 package.json 文件中删除该库,然后安装

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

I have used below gradle version我使用了以下 gradle 版本

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

I have used below properties version我使用了以下属性版本

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

I have used below versions我使用过以下版本

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

According to @Frank's answer the library used services-gcm:+ as a dependency, and the latest gcm version caused this problem.根据@Frank 的回答,库使用services-gcm:+作为依赖项,最新的 gcm 版本导致了这个问题。

And I had used :react-native-admob in my project.我在我的项目中使用了:react-native-admob So I just change the following lines in android/app/build.gradle所以我只是在android/app/build.gradle更改以下几行

From:从:

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

TO :到 :

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

This answer should help most people.这个答案应该可以帮助大多数人。 If it still does not then the way to solve this (which is not that good) is that you open the android project in android studio.如果它仍然没有那么解决这个问题的方法(不是那么好)是你在android studio中打开android项目。 That should fetch all the gradle files.那应该获取所有的gradle文件。 On the right side the view should be android.在右侧,视图应该是 android。

在此处输入图片说明

From here just check each gradle build file for a + sign ahead of google play services or firebase services or any such library.从这里开始,只需在 google play 服务或 firebase 服务或任何此类库之前检查每个 gradle 构建文件是否有+号。 This has also been explained in this answer.这在这个答案中也有解释。

After which you either change it like explained in the answer above.之后,您可以按照上面的答案中的说明进行更改。 like so.像这样。

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

Or you provide a variable if the library is using one or as a last resort change it there itself.或者,如果库正在使用一个变量,或者作为最后的手段更改它本身,则您提供一个变量。

The reason I put it here is so that any newbie who is sick of this error which randomly appeared out of nowhere all of a sudden can solve it effectively and not...die.我把它放在这里的原因是,任何对这个突然突然出现的错误感到厌烦的新手都可以有效地解决它,而不是……死。 lol.哈哈。

I had the same problem, just upgrade react-native-device-info and run the following command我遇到了同样的问题,只需升级react-native-device-info并运行以下命令

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

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

If you are not using react-native-device-info , but have the same error, its probably another library in your project.如果你没有使用react-native-device-info ,但有同样的错误,它可能是你项目中的另一个库。

Use this to find the library in question:使用它来查找有问题的库:

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

Then inspect the deps.txt file for keyword "androidx".然后检查 deps.txt 文件中的关键字“androidx”。 Then you can quickly find which native module is using it.然后你可以快速找到哪个原生模块正在使用它。

In my case it was react-native-camera , for which solution above was good but not enough so I had to add this to local.properties:就我而言,它是react-native-camera ,上面的解决方案很好但还不够,所以我不得不将它添加到 local.properties 中:

firebaseVersion=17.6.0
googlePlayServicesVersion=16.1.0
googlePlayServicesVisionVersion=16.2.0

EDIT: After these fixes, running ./gradlew app:dependencies > deps.txt and searching for "androidx" returned no results - this is what we are looking for.编辑:在这些修复之后,运行./gradlew app:dependencies > deps.txt并搜索“androidx”没有返回任何结果 - 这就是我们正在寻找的。

After running clean on the project, build worked.在项目上运行干净后,构建工作。

Google play services breaking changes.谷歌播放服务重大变化。 See Release Notes .请参阅发行说明

The simple way to resolve this issue is just changing the version of Google play services.解决此问题的简单方法就是更改 Google Play 服务的版本。

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

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

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