添加react-native-admob库后,我收到下一条错误消息
清单合并失败:来自[com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91的属性application @ appComponentFactory value =(android.support.v4.app.CoreComponentFactory) 也存在于[androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value =(androidx.core.app.CoreComponentFactory)。 建议:在AndroidManifest.xml:7:5-117的元素上添加'tools:replace =“ android:appComponentFactory”'以进行覆盖。
我尝试按照建议添加'tools:replace =“ android:appComponentFactory”,但构建仍然失败。
"dependencies": {
"@react-native-community/async-storage": "^1.4.0",
"formik": "^1.5.4",
"mobx": "^5.9.4",
"mobx-react": "^5.4.3",
"native-base": "^2.12.1",
"react": "16.8.3",
"react-native": "0.59.5",
"react-native-admob": "^2.0.0-beta.5",
"react-native-check-box": "^2.1.7",
"react-native-gesture-handler": "^1.2.1",
"react-native-iphone-x-helper": "^1.2.0",
"react-native-modal": "^10.0.0",
"react-native-numeric-input": "^1.6.5",
"react-native-pose": "^0.9.0",
"react-native-swipeable": "^0.6.0",
"react-native-vector-icons": "^6.4.2",
"react-navigation": "^3.9.1",
"styled-components": "^4.2.0"
}
app / build.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.rntodo"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
implementation project(':react-native-admob')
implementation 'com.google.android.gms:play-services-ads:16.0.0'
implementation project(':@react-native-community_async-storage')
implementation project(':react-native-vector-icons')
implementation project(':react-native-gesture-handler')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
android / build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
google()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
}
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rntodo">
<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>
</manifest>
我不确定我从哪里有依赖androidx.core:core:1.0.0。 请告诉我如何解决清单合并冲突。谢谢
答案 0 :(得分:0)
该库引用旧的Android支持库中的某些文件和类。从0.60开始,使用AndroidX支持库代替android-support。这意味着所有依赖项都必须依赖它。
幸运的是,存在一个将lib转换为新格式的工具。称为喷射器:https://www.npmjs.com/package/jetifier。您可以使用它并将其添加为yarn / npm安装后脚本,以便在每次安装yarn / npm后将其应用于所有node_modules依赖项。
您的库中存在另一种替代方法,因为另一位作者报告说他创建了一个react-native-admob分支并将其更新为最新的AndroidX支持库,请参见https://github.com/sbugert/react-native-admob/issues/459
答案 1 :(得分:0)
您必须使用jetifier来解决此问题,因为react native已移至支持AndroidX依赖关系的0.60+,并且大多数库都在这样做,以赶上react native。
android.enableJetifier=true
android.useAndroidX=true