Search Unity

Resolved How to keep Oculus IAP working in build when exporting in IL2CPP ?

Discussion in 'VR' started by HediB, Nov 17, 2020.

  1. HediB

    HediB

    Joined:
    Mar 10, 2020
    Posts:
    2
    Hi everyone !

    If an expert know a solution to let Unity keep Oculus IAP (In-App Purchase) when exporting in IL2CPP (not stripped), you will save the lives of so many people !

    ******* Description *******​
    When I export my app Build with Unity in "Mono" and purchase in-app (while playing in Oculus GO), my Unity script using Oculus IAP (In-App Purchase) works perfectly fine.
    But when I export with IL2CPP instead of Mono, the Oculus IAP doesn't work anymore at all.


    ******* Issue *******​
    It is surely due to IL2CPP code Stripping (optimization) but even when I tried to link/add Oculus.VR Assemblies (in Unity Asset/ root folder) to the link.xml file, in order to keep IAP reflections code working in my script, Unity is still stripping IAP when exporting in the build in IL2CPP (IAP is not working in the app).
    To be clear, when I export the build in Mono, it is working perfeclty fine, so I don't understand what I'm missing with IL2CPP (stripping) with Oculus.VR ...

    ******* "link.xml" file / Oculus.VR Assemblies well added ? *******​

    <linker>
    <assembly fullname="netstandard" preserve="all"/>
    <assembly fullname="Assembly-CSharp">
    <namespace fullname="Oculus.Platform" preserve="all" />
    <type fullname="Oculus.Platform.IAP" preserve="all" />
    <type fullname="Oculus.Platform.Core" preserve="all" />
    <type fullname="Oculus.Platform.CAPI" preserve="all" />
    <type fullname="Oculus.Platform.Request" preserve="all" />
    <type fullname="Oculus.Platform.Message" preserve="all" />
    <namespace fullname="Oculus.Platform.Models" preserve="all" />
    <type fullname="Oculus.Platform.Models.Purchase" preserve="all" />
    <type fullname="Oculus.Platform.Models.PurchaseList" preserve="all" />
    <type fullname="Oculus.Platform.Models.Error" preserve="all" />
    </assembly>

    <!-- Oculus VR -->
    <assembly fullname="Oculus.VR" preserve="all" />
    <assembly fullname="Oculus.VR.Editor" preserve="all" />
    <assembly fullname="Oculus.VR.Scripts.Editor" preserve="all" />
    <assembly fullname="ovrplatform_standalone" preserve="all" />
    <!-- ======= -->
    </linker>


    ******* info Oculus IAP *******​
    My Script purchase with this line of code (working in Mono / not in IL2CPP) : IAP.LaunchCheckoutFlow(sku).OnComplete(LaunchCheckoutFlowCallback);

    IAP (public static partial class IAP) is from Platform.cs Script [Unity Assets > Oculus > Platform > Scripts > Platform.cs]

    ******* Need a Hero who know the Solution *******​
    Should we add a specific code in the script using the IAP ? Like a method UsedOnlyForAOTCodeGeneration() ? or using Namespace + [Preserve] ? Or link.xml is not correct ?

    Is someone know how to manage Unity export build in IL2CPP with Oculus IAP (Oculus.VR) without stripping this IAP ?
    I can't find any documentation about this specific issue...

    Again and for information, the IAP request from Oculus.Platform.IAP Class (see below) is correctly coded :
    IAP.LaunchCheckoutFlow(sku).OnComplete(LaunchCheckoutFlowCallback);

    The purchase is not the problem at all (it is perfectly working when the build is exported in Mono).
    The main issue is when we export in IL2CPP : then the Oculus IAP is not working anymore in the app.

    Please can someone help ! T_T
     
    Last edited: Nov 18, 2020
  2. HediB

    HediB

    Joined:
    Mar 10, 2020
    Posts:
    2
    Solved !

    In fact it was easy but tricky...

    When we export in Mono, we are in ARMV7 (32 bits), but when we switch to IL2CPP, we should export in ARM64 (64bits). Even if we check the Unity PlayerSetting Target Architecture ARM64, we also need to NOT FORGUET specify it in Oculus Platform Edit Settgins.

    So, no need to add some assembly in link.xml for Oculus Platform to work. We just need to go to :
    1. Unity Menu : Oculus > Platform > Edit Settings
    2. Unity Inspector : Unity Inspector : OculusPlatformSettings - Build Settings > Check "Enable ARM64 Support"

    And it's done !
    All your previous Oculus Platform services will work again as they did in Mono !

    For information, when checking this checkbox, it automatically enable the libovrplatformloader located in Unity Project window : Oculus > Platform > Plugins > Android64 that was initially "disabled" ( libovrplatformloader.so.disabled became enabled -> libovrplatformloader.so ).

    That is why when you switch from Mono to IL2CPP ARM64, the Oculus Platform is disabled, waiting for the checkbox to be checked in order to work on Android 64 bits.

    Easy but tricky when you start your project in Mono 32 bits, you don't check this checkbox for the first time and forguet it after a while not using it.

    So, Remember to Check "Enable ARM64 Support" in OculusPlatformSettings when you switch from Mono to IL2CPP ! :) It will save you days of searching why the it doesn't work, thinking it's code stripping / file link.xml without success, until you find this is just a simple (old friend) checkbox to enabled in ARM64 ahah !

    Hope this could help you! ;)