Screen orientation not changing when rotating Android device

I’m currently using SDL2 version 2.0.5 for the Android port of my game, which works just fine, but I would like to upgrade to a newer SDL version.

However, I have the problem that automatic screen rotation does not work anymore when using a newer version of SDL2. It still rotates 180° from landscape mode to flipped landscape mode when turning the device by 180°, but it refuses to rotate from landscape to portrait mode or from portrait to landscape mode, but just stays in whatever orientation the game was started with (either landscape or portrait mode).

I’ve encountered this problem when using SDL2 versions 2.0.6 or 2.0.8 (newer versions 2.0.9 and 2.0.10 unfortunately refuse to compile on my development system).

I have tested (and reproduced) this odd behavior on Android 4.4 and Android 9.

I have the suspicion that it may have something to do with my “AndroidManifest.xml” file, but haven’t found a solution so far.

Any idea what might go wrong here?

Here’s my “AndroidManifest.xml” file:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.artsoft.rocksndiamonds"
      android:versionCode="4010301"
      android:versionName="4.1.3.1"
      android:installLocation="auto">

    <application android:label="@string/app_name"
                 android:icon="@drawable/ic_launcher"
                 android:allowBackup="true"
                 android:debuggable="true"
                 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                 android:hardwareAccelerated="true">
        <activity android:name="RocksNDiamonds"
                  android:configChanges="keyboardHidden|orientation|screenSize"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

    <!-- Android 2.3.3 (min) / Android 4.2.2 (target) -->
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" />

    <!-- OpenGL ES 2.0 -->
    <uses-feature android:glEsVersion="0x00020000" /> 

    <!-- Allow writing to external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Allow doing network operations -->
    <uses-permission android:name="android.permission.INTERNET" /> 
</manifest> 

Any hint or help would be highly appreciated.

I think you should try to solve this first ! try to fix compiling latest hg source.

I think you are right. It’s always best to do such tests with the latest SDL versions (both stable and from the repository).

So I’ll try again to compile the latest SDL code, and see if that helps…

Check out my tutorial how to build the latest SDL with android studio.
https://discourse.libsdl.org/t/building-sdl2-0-10-in-android-studio-3-4-2-in-windows-10

Regarding the screen orientation . Try adding the screenOrientation under activity:

<activity android:name="RocksNDiamonds"
                  android:configChanges="keyboardHidden|orientation|screenSize"
                  android:label="@string/app_name"
                  android:screenOrientation="sensorLandscape">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

Read more about it here: https://developer.android.com/guide/topics/manifest/activity-element#screen

Another note: Do you really need the:

<!-- Allow writing to external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />