Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set screenOrientation to "portrait" in release build only

In **AndroidManifest.xml** I have an **Activity** in portrait mode:

    <activity
        android:name=".home.MainActivity"
        android:screenOrientation="portrait">

I found it useful to temporary remove android:screenOrientation="portrait" line during development in order to earlier catch bugs related to saving instance state.

Is it possible to set screen orientation to portrait in the release build only and for the debug build keep the default behaviour?

like image 542
Piotr Aleksander Chmielowski Avatar asked Dec 28 '25 22:12

Piotr Aleksander Chmielowski


2 Answers

It can be achieved by mentioning configuration for release in build.gradle file of app using manifestPlaceholder property as shown below. And remove it from manifest file. Also for debug build you can specify separately as well.

android {
    ...
    buildTypes {
        release {
            ...
            manifestPlaceholders.screenOrientation = "portrait"
        }
        debug {...}
    }
}

To understand more on manifestPlaceholders and build favour kindly refer here and at official site

like image 121
Shadow Droid Avatar answered Dec 31 '25 12:12

Shadow Droid


You can override parts of your AndroidManifest in debug build. In src/debug create another AndroidManifest.xml, and tell the merge tool to replace the screenOrientation attribute for your activity:

    <activity
        android:name=".home.MainActivity"
        tools:replace="android:screenOrientation"
        android:screenOrientation="unspecified"/>

See docs for more information.

like image 23
K-dari Avatar answered Dec 31 '25 12:12

K-dari