#android #android-gradle-plugin #android-manifest
#Android #android-gradle-плагин #android-манифест
Вопрос:
Мой файл манифеста:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.com.myapplication"
>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
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:configChanges="orientation"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Мне нужно удалить android:configChanges="orientation"
и android:screenOrientation="portrait"
для debug
buildType.
Как я могу это сделать с помощью gradle?
PS Я знаю, что у меня может быть 2 разных файла манифеста. Но мне нужно иметь один (его легко забыть добавить действие к одному из них)
Ответ №1:
Самый простой способ решить эту проблему — использовать заполнители манифеста:
1) Измените манифест следующим образом:
<activity
android:name=".MainActivity"
android:configChanges="${configChanges}"
android:screenOrientation="${screenOrientation}"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
2) добавьте заполнители манифеста в gradle:
defaultConfig {
manifestPlaceholders = [ screenOrientation:"portrait", configChanges:"orientation"]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
manifestPlaceholders = [ screenOrientation:"unspecified", configChanges:""]
}
}
Ответ №2:
Я думаю, вы можете определить resValue
в своей конфигурации debug и release, например:
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "screenOrientation" , "landscape"
}
debug {
minifyEnabled false
debuggable true
resValue "string", "screenOrientation" , "portrait"
}
и чем вы можете получить доступ к значению из AndroidManifest android:screenOrientation="@string/screenOrientation
Комментарии:
1. невозможно установить строковый ресурс на
android:screenOrientation
, также невозможно установить ресурс наandroid:configChanges