Search Unity

How to control if the Purchasing Android plugins are completely removed for certain build types

Discussion in 'Unity IAP' started by jason_yak, Jun 14, 2018.

  1. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    Hi there,

    I realise there's been a lot of questions around this topic. I've searched extensively but still can't find the exact answers I'm after and couldn't find any documentation for this method: UnityPurchasingEditor.TargetAndroidStore()

    I have a very complex build pipeline that compiles several different Android build variations supporting many platforms like Google Play, Xiaomi, TapTap, doing demo and google instant app variations. Long story short though is that I need to have absolute control over whether the Purchasing plugin files are compiled in or not. My ideal scenario is that by default no plugin files to do with the Purchasing will be compiled into an APK at all, and then just for certain build types I can have the plugin be compiled in.

    I use an editor script that calls BuildPipeline.BuildPlayer() which allows me to run some pre-build processes, so I'm guessing for Google Play I would call this before building the APK:
    UnityPurchasingEditor.TargetAndroidStore( UnityEngine.Purchasing.AppStore.GooglePlay );

    However for other build types that do not use the plugin files what are my options for this? I saw that there is the enum values: UnityEngine.Purchasing.AppStore.fake and UnityEngine.Purchasing.AppStore.NotSpecified, would either of these options mean that the plugin files are completely stripped and not compiled in? or would it be possible, and if so, more reliable to ensure that no unwanted files are compiled in if I was to run my own process to temporarily remove the folders:
    /Assets/Plugins/UnityChannel/
    /Assets/Plugins/UnityPurchasing/
    and then put them back after the build has completed? or would this be likely to cause some issues?

    Lastly, my own build script is always going to run when compiling out an APK, so it's always either going to strip out the plugin files (with whatever method I end up using) or it's always going to call the TargetAndroidStore() method. Knowing this does it even matter what target is selected as the default in Window > Unity IAP > Android > ?

    Thanks for your help,

    Jason
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We implement stub dll's for stores that are not targeted which are still included in a build. Regarding temporarily removing the folders, if you are using any IAP functionality, those folders are required. If you are not planning to use IAP, you can disable IAP in the Services window, and if you have no active references, you might be able to delete those folders. I would recommend that you test your build process.
     
  3. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    It’s sounds like the temp removal should work well in my case, because I will inject a custom compiler symbol and wrap all IAP usage code e.g #if USING_IAP, so I won’t have any broken references within my own code.. but I was concerned that if I have IAP turn on in services and removed the folders that internally Unity would be expecting the classes to be there for the initialisation or something else.

    Is there a way to turn off the IAP service in editor code, so I can do this temporarily before building and then back on again? If I can’t, do you know if there’s any functionality that will run with the IAP services turned on even if the those two folders have been removed? Also if I can’t then I’d have to always leave it on because I build out dozens of build variations from a single unity project and would need it on at least for Google Play.

    Also when you mentioned the stub dll’s for non-targeted modules, so if I chose the NotSpecified module, does this compile in all compete modules or would it compile in all empty stub modules? If the latter it sounds like this could be another solution I could try perhaps.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I would recommend that you test your process, this is not a work flow that we have tested. I'm not familiar with a way in code to add/remove services, but you could try editing /ProjectSettings/UnityConnectSettings.asset and setting the services to 0 (off).