Problem with Android API 27 and later


#1

With Android API 27 and later, you can no longer specify screen orientation in the manifest file:

android:screenOrientation="portrait"

if you have a style setting of:

<item name="android:windowIsTranslucent">true</item>

Instead, you need to request the desired screen orientation in the onCreate method of the main activity:

        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

Otherwise, your app will not run.

I need to figure out how to get the above code snippet inserted into the main activity java file as part of a ‘uno build …’ process. Does anyone know where I need to start looking in order to figure out how to do this?

AC


#3

Hello! Is this the same issue as this:


#4

Hi,

We experienced the same issue a few weeks ago after making a new release for the production environment. We couldn’t find any solution in the forums and we had to fix it immediately. Since we are catching the errors through Raygun, we identified the source of the error in Java code. And the only way we could find to fix the problem was to make the necessary changes in the source code, generated by Fuse, using Android Studio and then packaged the app again using Android Studio.

It was an easy problem to fix without understanding anything about Java or Android development :slight_smile: However, I don’t think we will be that lucky next time!

We have invested a lot in our app developed by Fuse but unfortunately, we might have to accept the fact that it’s dying.


#5

Hello ipek! Good thing that you found the solution, but could you share it with us? The reason why open source communities are dying is because people are not sharing their work and solutions to common problems. :slightly_smiling_face:


#6

Hi Matti,

As acoad mentioned the problem was because of this following line:
<item name="android:windowIsTranslucent">true</item>

Since there was no way of us being able to integrate the removal of this line during theuno build process, we installed Android Studio, found the line and removed it. And luckily, we didn’t face any problems that we couldn’t solve when we hit build in Android Studio. Basically, we are now dependant on Android Studio to make the build and packaging. This was what I advised acoad to do, if, in case, he can’t find any other solution.

Believe me, if I had a better solution I would be happy to share it with the community. I can not call mine a solid solution, it was just bypassing the problem. Now I have to make a new release and shouldn’t forget to remove this line for Android :slight_smile:


#7

Thanks for the clarification!


#8

Hello! I might add that removing {“Orientations”: “Portrait”} from .unoconfig fixed this issue for me.


#9

Come to think of it; for some apps it’s not convenient to allow both orientations, so if you wish to keep the orientation only to portrait, this fix works also now that Uno is open source:

  1. Edit the styles.xml in Uno source: https://github.com/fuse-open/uno/blob/8582e76cd9de40a8568ca757837cdc64211c9403/lib/UnoCore/Targets/Android/app/src/main/res/values/styles.xml
  2. Change windowIsTranslucent=true to windowIsTranslucent=false
  3. Build Uno with “make release” and copy over the Fuselibs/Stuff as instructed in: Oct 2018 - How to update to latest Fuselibs and Uno

Some people are saying that defining the window’s translucency to false has some effect on splash screens (if you are using those), but i’d rather have my app not crash and is fixed to portrait mode.