Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

android:hardwareAccelerated is forced false in all Activities

Discussion in 'Android' started by KJoanette, May 23, 2018.

  1. KJoanette

    KJoanette

    Joined:
    Jun 8, 2013
    Posts:
    59
    I'm not sure when this change happened but the built in android post processor is forcing all activities in the manifest to have android:hardwareAccelerated=false

    This means it is impossible to override without writing out own post processor to undo this change. It should never be forced to be false or true on all activities as this could negatively interfere with other native activities a developer adds.

    It would be helpful to have this at least as a flag in the editor settings along with the correct name of the main activity (for the times when you need to override the default Unity activity)

    EDIT: This occurs in Unity 2018.1.0f2
     
  2. povilas

    povilas

    Unity Technologies

    Joined:
    Jan 28, 2014
    Posts:
    427
    Hi. We patch android:hardwareAccelerated to false to disable hardware acceleration for native UI. This is never useful for Unity activities (if not, please shout), but still uses various resources. In particular, a separate render thread is created causing the GPU driver to take slow, properly synchronized path and slowing down the app regardless of whether native UI is used or not.

    When legacy internal build system was used the android:hardwareAccelerated setting was parsed as false even if not specified in the manifest. When we switched to Gradle by default, we noticed the performance regression due to setting switching to true for some reason and after some investigation concluded that hardcoding this value to the manifest is the best fix. The parsing of the manifest happens in the zygote process, so we concluded this to be some obscure bug of Android and moved on.

    What exact problems does this cause to you? Hardware acceleration should be turned off only for Unity activities.
     
  3. Ordas

    Ordas

    Joined:
    Apr 22, 2013
    Posts:
    2
    It is required for using webview to load HTML5 content on android in any sort of performant way
     
    Carlogeno likes this.
  4. kheldorin

    kheldorin

    Joined:
    May 28, 2015
    Posts:
    22
    Anyone know what's the workaround for this? I tried using a PostProcessBuild and it still gets overriden
     
  5. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,160
    The flag should be set only on Unity activity. Is it set for you for all activities, as stated in the thread title?
     
  6. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,160
    We've observed severe performance issues (up to 70% slowdown of draw calls) on some devices when hardware acceleration was enabled. @povilas explained why in the post before. On the other hand, there is zero performance improvement when it is enabled on Unity activity because we don't make use of native UI elements.

    If you are absolutely sure you need the hardware acceleration, you can to the following:
    - Extract your native UI into a separate activity and enable hardware acceleration there (preferred way)
    - Modify the Unity manifest, for examply by utilizing IPostGenerateGradleAndroidProject interface (sample here: https://github.com/Over17/UnityAndroidManifestCallback)
     
    code-kiwi and codestage like this.
  7. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,516
    Maybe but, our plugin adds webview to existing unity activity as we can pass the information from webview to unity very quickly.

    Whereas, if we go for a new activity, all unitysendmessage calls are queued and won't fire until we finish the new activity where webview is rendered. As hardware flag was disabled, the scrolling of webviews and other content was too slow.
    Glad I found this thread! Thanks to @KJoanette for creating a thread on this!


    Anyways, thanks for pointing at IPostGenerateGradleAndroidProject as it should be good enough for handling the situation. It would be great if you can let us know from which unity version this was changed so that we can add the fix accordingly.


    Cheers,
    Ayyappa
     
  8. Tagazou

    Tagazou

    Joined:
    Mar 27, 2017
    Posts:
    3
    Hi,

    I'm stuck with this issue too. I'm using @Voxel-Busters ' plugin and without this flag set to true gifs won't be animated in the webviews.

    I've tried to use IPostGenerateGradleAndroidProject but it's 2018 only, and although I've been able to use it to fix the manifest there are too many new bugs for me to do such an update, as I'm close to the release date.

    Using IPreprocessBuild/IPostprocessBuild isn't a solution, because the first one is called too early and the latter too late.

    The only workaround I have is to export the gradle project, patch the manifest myself and then build the apk, which is painful.
     
  9. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,516
    @Tagazou Please ping us on skype. I will get you the file which should work without any issues.

    However, the mentioned interface seems to be from 2018.3
     
  10. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    1,973
    You can enable hardware acceleration for whole app by forcing a manifest change but I have observed various negative side effects of this in the Unity content (apart from the possible slowdown mentioned above) so I suggest only enabling hardware acceleration for a webview activity and not the unity activity - you can do on per-activity basis as detailed here: https://developer.android.com/guide/topics/graphics/hardware-accel
     
  11. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    1,973
    This will not work in 2017.4.11/LTS and nor does adding a root manifest with hardware acceleration set to true as somewhere between 2017.4.0 and 2017.4.11 you/Unity changed the unity content to use an activity with hardware acceleration off.
     
  12. unity_CK-reaVvdteplw

    unity_CK-reaVvdteplw

    Joined:
    Sep 11, 2018
    Posts:
    2
    I am using Unity 2017.4.3f1.
    In the same way, "android: hardwareAccelerated = false" is set on all screens.
    How can I make it true? I am very embarrassed.
     
  13. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,160
    Why do you need it?
     
  14. unity_CK-reaVvdteplw

    unity_CK-reaVvdteplw

    Joined:
    Sep 11, 2018
    Posts:
    2
    Because graph drawing is slow, I'd like to confirm it by setting it to true.
     
  15. idchlife

    idchlife

    Joined:
    Jul 25, 2016
    Posts:
    15
    Actually I'm experiencing issues with this, because I'm using package to add WebView to Unity app with AR also inside it.

    All Android phones, even top tier, experiencing lags-to-freeze and heat the phones with hardwareAccelerated=false.
    Package developer recommends to set to true, and it worked for some times, as I see it, but now Unity, as I suspect, overrides it and just uses false instead.
     
  16. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,160
    I have nothing else to add at the moment.
    Use the external packages and webviews in a separate activity; feel free to allow hardware acceleration for that activity.
     
    idchlife likes this.
  17. idchlife

    idchlife

    Joined:
    Jul 25, 2016
    Posts:
    15
    thanks!

    Solved this by exporting to Android project and changing option there. It works.
     
  18. Mandelboxed

    Mandelboxed

    Joined:
    Apr 17, 2015
    Posts:
    49
    There are obviously legitimate use cases. Why are we not given any options here? Not every plugin can be modified and this was something that could much more easily be controlled in previous Unity versions...
     
  19. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,516
    For webviews, we don't see any other option if Unity chooses this way. Also, I need to accept this was mentioned sometime back that its better to avoid adding to Unity's default activity. But we mostly use because of the ease it gives us for better handling.

    However, do you have any restrictions on using fragments with in Unity's default activity?

    Thanks,
    VB Team
     
  20. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,160
    Unfortunately I don't have a 100% answer, but our permissions dialog is shown from a fragment so it should be doable.
    Feel free to submit a bug report if it doesn't work for you.
     
  21. changchou

    changchou

    Joined:
    Mar 17, 2014
    Posts:
    2
    admob native video ad need it
     
  22. dohaiha930

    dohaiha930

    Joined:
    Mar 27, 2018
    Posts:
    55
    Yeah, Admob Native Video MediaView need hardwareAccelerated=true to working on UnityPlayerActivity.
    I try to add another Manifest file to Plugins/Android folder of UnityPlayerActivity but it's still force hardwareAccelerated=false.

    How can i change it?
     
    Last edited: Jul 2, 2019
  23. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    250
    We're using UniWebview, and this package is also recommending setting hardware acceleration to true. Unfortunately, it does not use a separate activity for the webview, it just sub-classes UnityActivity. And Unity overrides the acceleration setting for this, most likely because it is still marked as being the Unity activity.

    How can we change this behaviour?
     
    raul_tinca and Tostifrosti like this.
  24. And42

    And42

    Joined:
    May 26, 2020
    Posts:
    1
    Just an additional note. For me it seems like the best way for this to work is to have hardware acceleration enabled for all native views except for the unity ones. This way unity drawing procedures will not be slowed down while the native views (like the mentioned Webview) will be as performant as expected. As I can tell from the generated android code there is a couple of unity views which are added to the activity (like a SurfaceView). To enable the logic I described, it can be enough to enable acceleration in the manifest for the activity and call this code for every unity rendering view:
    Code (csharp):
    1. unityView.setLayerType(View.LAYER_TYPE_NONE, null);
    according to this: https://developer.android.com/guide/topics/graphics/hardware-accel#controlling. Though, I don't really know unity internal logic; so, I can't guarantee that will work
     
  25. waldgeist

    waldgeist

    Joined:
    May 6, 2017
    Posts:
    250
    How can that be done, if the activity comes from a third party package (in my case UniWebView) which runs in the main activity?
     
  26. JessHolle

    JessHolle

    Joined:
    Jul 9, 2019
    Posts:
    14
    We also have this issue -- in this case not with a WebView, but rather with using the ExoPlayer movie player within native 2D UI which is laid out over part of the Unity 3D view. This therefore has to be in the UnityPlayerActivity.
     
  27. Yiming075

    Yiming075

    Joined:
    Mar 24, 2017
    Posts:
    29
  28. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,516
    For any one who wants to automate adding the flag, we made a script which will cover it.
    Check out this script.
     
    akbay likes this.
  29. qilin598866753

    qilin598866753

    Joined:
    Nov 28, 2021
    Posts:
    6
    Same Issue,open keyboard and input multiline enough(fill keyboard input preview), the input preview will display error.
     
  30. qilin598866753

    qilin598866753

    Joined:
    Nov 28, 2021
    Posts:
    6
    when android:hardwareAccelerated set false, the keyboard preview display error, after input multiline. It's 100% happen, once input multiline enough.
     
unityunity