尝试安装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'
}

清单合并失败:属性应用程序@appcomponentFactory value =(android.support.v4.app.corecomponentfactory(来自[com.android.support:support:support:28.0.0.0] androidmanifest.xml:22:18-91 也存在于[androidx.core:core:1.0.0] androidmanifest.xml:22:18-86 value =(androidx.core.app.corecomponentfactory(。 建议:添加'工具:替换=" android:appcomponent-factory"'to androidManifest.xml:9:5-30:19 to overtride。

问题是由于您尝试使用支持库以及Android X依赖项,这些依赖性是在Google Play Services的最后(第18(版中实现的。要解决问题,您可以通过对AndroidManifest.xml进行以下更改来迁移到Android X:

替换以下行:

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

最新更新