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

hon*_*lop 34 android react-native react-native-android expo

我将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.
Run Code Online (Sandbox Code Playgroud)

然后我在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'
}
Run Code Online (Sandbox Code Playgroud)

我如何解决它?

我需要你的解决方案。

先感谢您。

Fra*_*ank 49

升级'react-native-device-info'version 2.1.2固定的错误我。见github.com/facebook/react-native/issues/25294#issuecomment-503024749

简而言之:该库用作"services-gcm:+"依赖项,而最新的gcm版本导致了此问题。


Hus*_*ani 13

根本原因与迁移到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
Run Code Online (Sandbox Code Playgroud)

否则,如果您不想升级,则应com.google.android.gms避免react-native-device-info这种情况。谢谢

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


Yin*_*nka 7

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

googlePlayServicesVersion=16.1.0
firebaseVersion=17.6.0
Run Code Online (Sandbox Code Playgroud)


Meh*_*nki 5

添加'tools:replace="android:appComponentFactory"'您的AndroidManifest.xml内部<application>标签

你的 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>
Run Code Online (Sandbox Code Playgroud)


hon*_*lop 5

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

我加

tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString"
Run Code Online (Sandbox Code Playgroud)

在我身上 AndroidManifest.xml

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

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
  }
Run Code Online (Sandbox Code Playgroud)

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

android.useAndroidX=true
android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)

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

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

如果出现上述错误

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

错误:程序包android.support.annotation不存在错误:找不到符号类可为空

如果出现上述错误

implementation 'androidx.annotation:annotation:1.1.0'

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

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

编译版本目标版本应为28。