gradle 中的错误

Error in gradle

同步时出现 gradle 问题。 应用级别 gradle 文件

Manifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.aparna.search_recy">

    <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"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

build.gradle

    android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.aparna.search_recy"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

     buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:support-v13:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.android.support:cardview-v7:26.0.2'
}

错误:

Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.1.0) from [com.android.support:support-v13:26.1.0] AndroidManifest.xml:28:13-35 is also present at [com.android.support:cardview-v7:26.0.2] AndroidManifest.xml:25:13-35 value=(26.0.2). Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:26:9-28:38 to override.

将您的 cardview-v7:26.0.2 版本更改为 26.1.0

实际上,如果您在依赖项中使用不同的不同版本,就会出现此错误。

为避免此错误,您只需将 cardview-v7:26.0.2 版本更改为 26.1.0。

它将解决您的问题

建议:将 'tools:replace="android:value"' 添加到位于 AndroidManifest.xml:26:9-28:38 的元素以覆盖。

出现这个问题是因为当你使用不同的库时,它们中的AndroidManifest相互冲突。

首先您可以在 compileSdkVersion 下面添加缺少的 buildToolVersion 然后使用相同的版本 也缺少 compile 'com.android.support:recyclerview-v7: 版本所以添加这个 检查下面的代码

      android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1" //change here
    defaultConfig {
        applicationId "com.aparna.search_recy"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

     buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:support-v13:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.android.support:recyclerview-v7:26.1.0' //change here
    compile 'com.android.support:cardview-v7:26.1.0'
}

终于清理并重建项目 如果这不起作用转到 File->Invalidate Caches / Restart

试试这些组合。因为版本在依赖项中混合,导致构建时运行时崩溃 gradle.
所有 com.android.support 库必须使用完全相同的版本 specification.There 是不兼容或可能导致错误的库或工具和库的一些组合。

用下面提到的依赖项替换依赖项。

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:support-v4:27.0.2'
    implementation 'com.android.support:design:27.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    implementation 'com.android.support:recyclerview-v7:27.0.2'
    implementation 'com.android.support:cardview-v7:27.0.2'

只需将错误中的库添加到您的 build.gradle,但更改版本以匹配您正在使用的其他库。

对我来说,我的 build.gradle 文件是这样的:

implementation 'com.android.support:appcompat-v7:27.1.1'

我收到这个错误:

Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.0.2) from [com.android.support:recyclerview-v7:26.0.2] AndroidManifest.xml:25:13-35 is also present at [com.android.support:support-v4:26.1.0] AndroidManifest.xml:28:13-35 value=(26.1.0). Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:23:9-25:38 to override.

所以我将 recyclerview-v7:26.0.2 添加到 build.gradle 但将其更改为 27.1.1 以匹配我的 appcompat-v7。我再次构建它并得到了类似的错误,但这次是 com.android.support:percent:26.0.2.

我再次将其添加到我的 gradle.build 文件中,但将其更改为 27.1.1 以匹配我的 appcompat-v7

总而言之,这:

implementation 'com.android.support:appcompat-v7:27.1.1'

变成了这个

implementation 'com.android.support:appcompat-v7:27.1.1'
// Had to add recyclerview
implementation 'com.android.support:recyclerview-v7:27.1.1'
// Had to add percent
implementation 'com.android.support:percent:27.1.1'

然后它工作正常。

我想 appcompat-v7 必须将那些旧版本的库硬编码到其中。

对我来说,启用 jetifier 和 androidx 解决了这个错误