React-native错误:清单合并失败

时间:2019-07-10 19:15:54

标签: android react-native android-appcompat androidx

运行我的应用程序时出现此错误:

Manifest merger failed : Attribute application@appComponentFactory value=(androidx.core.app.CoreComponentFactory) from [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86
        is also present at [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
        Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:7:5-117 to override.

我尝试添加到gradle.properties

android.useAndroidX=true
android.enableJetifier=true

,以及(对于AndroidManifest)

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

还有(build.gradle)

implementation "androidx.appcompat:appcompat:1.0.0"

替换上一个

implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"

但不为我工作。

-Android Manifest.xml-

<uses-permission android:name="android.permission.INTERNET" />

<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:roundIcon="@mipmap/ic_launcher_round"
  android:allowBackup="false"
  android:theme="@style/AppTheme">
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

-build.gradle-

dependencies {
    implementation project(':react-native-exit-app')
    implementation project(':react-native-firebase')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompatv7:
 ${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation "com.google.android.gms:play-services-base:16.1.0"
    implementation "com.google.firebase:firebase-core:17.0.0"
    implementation 'com.google.firebase:firebase-auth:18.0.0'
    implementation 'com.google.firebase:firebase-database:18.0.0'
}

1 个答案:

答案 0 :(得分:0)

这意味着您的一个库正在使用AndroidX。因此,您必须将应用程序转换为AndroidX。

  • android.useAndroidX = true android.enableJetifier = true将这些行放入gradle.properties中。
  • npm install --save-dev jetifier
  • npx jetify
  • npx react-native run-android(您的应用应正确编译和运行)
  • 在package.json的postinstall目标中调用npx jetify运行(每当依赖项更新时,您都必须再次进行jetify)