android - 尝试安装 admob 时总是出现明显的合并错误
问题描述
我尝试在我的项目中添加 admob,并且我还尝试tools:replace="android:appComponentFactory"
在清单中添加应用程序,但此时它给出了另一个错误:
tools:replace="android:appComponentFactory"
代替<application>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admobessay"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
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">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
</application>
</manifest>
我的build.gradle
:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.admobessay"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android- optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.android.gms:play-services-ads:18.0.0'
}
清单合并失败:来自 [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)。建议:将 'tools:replace="android:appComponentFactory"' 添加到 AndroidManifest.xml:9:5-30:19 的元素以覆盖。
解决方案
问题是由于您尝试使用支持库以及 Android X 依赖项,这些依赖项在 Google Play 服务的最后(第 18 个)版本中实现。要解决此问题,您可以通过对您的 进行以下更改来迁移到 Android X AndroidManifest.xml
:
替换以下行:
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
用这些:
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
此外,将这些标志设置到gradle.properties
项目根目录中的文件可能会有所帮助:
android.useAndroidX=true
android.enableJetifier=true
推荐阅读
- python - 请求通讯录时出现错误 400 INVALID_ARGUMENT
- c# - 等待 UI 线程上的任务而不产生死锁
- angular - 如何在 ngx-admin 的多个 x 轴图表中加载动态数据
- mongodb - 在 Mongo 对象中添加一个新字段,并在一个查询中使用另一个字段的值进行初始化
- laravel - 有没有办法通过路由名称将组件导入vue js中的另一个组件
- javascript - 将日期字符串格式化为日期
- mysql - 我需要显示来自 BRAND_CAR 的所有汽车,即使其中没有汽车
- javascript - 将十六进制数组转换为 ASCII 数组(Javascript)
- elasticsearch - elasticsearch max 聚合返回多个结果
- kubernetes - 如何在 istio 中配置入口网关?