Android 根据 SDK 平台版本使用不同的清单
Android Use different manifest depending on SDK Platform Version
是否可以根据 Android SDK 版本更改清单属性?
例如:当 SDK 版本 < 24 时 android:largeHeap
为 true
,当 SDK >= 24 时 false
?
<?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>
答案是否定的。但是你可以像
那样合并(覆盖SDK特定的库)它们
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
xmlns:tools="http://schemas.android.com/tools">
<uses-sdk tools:overrideLibrary="com.example.lib1, com.example.lib2"/>
...
试试这个
res/values/bool.xml
<resources>
<bool name="largeheap">true</bool>
</resources>
res/values-v24/bool.xml
<resources>
<bool name="largeheap">false</bool>
</resources>
Android 清单文件:
<application
android:largeHeap="@bool/largeheap"
android:allowBackup="true"
android:icon="@drawable/ic_launcher">
....
</application>
在res/values/bool.xml
中制作true
,在res/values-v24/bool.xml
中制作false
。 Android API 级别 24,因此 -v24
将用于 24 及更高版本。
是否可以根据 Android SDK 版本更改清单属性?
例如:当 SDK 版本 < 24 时 android:largeHeap
为 true
,当 SDK >= 24 时 false
?
<?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>
答案是否定的。但是你可以像
那样合并(覆盖SDK特定的库)它们 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app"
xmlns:tools="http://schemas.android.com/tools">
<uses-sdk tools:overrideLibrary="com.example.lib1, com.example.lib2"/>
...
试试这个
res/values/bool.xml
<resources>
<bool name="largeheap">true</bool>
</resources>
res/values-v24/bool.xml
<resources>
<bool name="largeheap">false</bool>
</resources>
Android 清单文件:
<application
android:largeHeap="@bool/largeheap"
android:allowBackup="true"
android:icon="@drawable/ic_launcher">
....
</application>
在res/values/bool.xml
中制作true
,在res/values-v24/bool.xml
中制作false
。 Android API 级别 24,因此 -v24
将用于 24 及更高版本。