在AndroidManifest中添加'tools:replace ="Android:value"'到<meta-data>元素

D.H*_*ges 55 android gradle android-manifest android-support-library android-studio

我正在关注HeadFirst Android开发中的教程并在添加后遇到问题:private ActionBarDrawerToggle drawerToggle;

该控件已弃用,因此我按照Stack上的说明通过将com.android.support:appcompat-v7:26.0.0-alpha1添加到应用程序模块依赖项来解决该问题

但现在我收到以下构建错误:

错误:任务':app:processDebugManifest'的执行失败.

清单合并失败:来自[com.android.support:recyclerview-v7:25.3.1]的属性meta-data#android.support.VERSION@value value =(25.3.1)AndroidManifest.xml:24:9-31也是出现在[com.android.support:appcompat-v7:26.0.0-alpha1] AndroidManifest.xml:27:9-38 value =(26.0.0-alpha1).建议:在AndroidManifest.xml:22:5-24:34中添加'tools:replace ="android:value"'来覆盖.

这是代码:

Sag*_*iri 182

问题是所有具有相同版本和主要版本的支持库必须匹配编译SDK版本.

因此,请尝试强制使用特定的支持库版本.把它放在你的app模块的末尾build.gradle.

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.0'
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • @sagar giri我得到无法解决符号'DependencyResolveDetails'错误.你能告诉我解决方案吗? (7认同)
  • 这对我有用.不确定为什么它不被接受为有效答案. (2认同)

Led*_*ine 19

如果您还没有,请先将此行添加到清单标记中:

xmlns:tools="http://schemas.android.com/tools"
Run Code Online (Sandbox Code Playgroud)

例:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.winanainc"
    android:versionCode="3"
    android:versionName="1.2"
    xmlns:tools="http://schemas.android.com/tools">
Run Code Online (Sandbox Code Playgroud)

然后在您的应用程序中添加此元标记以覆盖您的构建工具版本,在本例中我选择了版本25.3.1

<application>
   ...
   ..
    <meta-data
        tools:replace="android:value"
        android:name="android.support.VERSION"
        android:value="25.3.1" />
</application>
Run Code Online (Sandbox Code Playgroud)


Dar*_*ush 5

将所有支持库版本更改为25.3.1并像魅力一样工作:

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
Run Code Online (Sandbox Code Playgroud)

您还需要将以下参数更改为25:

compileSdkVersion 25
targetSdkVersion 25
Run Code Online (Sandbox Code Playgroud)


小智 5

 <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:largeHeap="true"
            android:supportsRtl="true"
            android:theme="@style/AppTheme"

            >
            <meta-data
                tools:replace="android:value"
                android:name="android.support.VERSION"
                android:value="26.0.0" />
        </application>
Run Code Online (Sandbox Code Playgroud)


Amb*_*mar 5

        Add <meta-data> tag in manifest.xml file as below...


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

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

        <application
            android:name=".MyApplication"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity
                android:name=".MainActivity"
                android:theme="@style/AppTheme">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>

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

            **<meta-data
                tools:replace="android:value"
                android:name="android.support.VERSION"
                android:value="25.3.1" />//this 25.3.1 version should be same which we defined in the build.gradle file. i am using compileSdkVersion 25**

        </application>
 </manifest>
Run Code Online (Sandbox Code Playgroud)

它会起作用@Ambilpura ....