Android 根据 SDK 平台版本使用不同的清单

Kir*_*Rao 4 android android-manifest

清单属性是否可以根据 Android SDK 版本进行更改?

例如:已经android:largeHeaptrue当SDK版本<24和false当SDK> = 24?

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"

        android:largeHeap="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>
    </application>

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

cha*_*ohd 6

尝试这个

res/values/bool.xml

<resources>
    <bool name="largeheap">true</bool>
</resources>
Run Code Online (Sandbox Code Playgroud)

res/values-v24/bool.xml

<resources>
    <bool name="largeheap">false</bool>
</resources>
Run Code Online (Sandbox Code Playgroud)

Android 清单文件:

<application
        android:largeHeap="@bool/largeheap"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher">
                ....
</application>
Run Code Online (Sandbox Code Playgroud)

trueres/values/bool.xmlfalseres/values-v24/bool.xml。Android API 级别 24,因此-v24将用于 24 及更高版本。