Search Unity

Is there anyway to swich the plugin import setting inside a package?

Discussion in 'Package Manager' started by watsonsong, May 8, 2019.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    375
    I move my code into the new package folder, and met some problem.
    I build some different plugins(*.aar for android, *.framework for ios) for one function. Such as the Ad SDK or Analyzer SDK. I want to switch different SDK with the same purpose.
    What I do is encapsul the SDKs into my own plugin to provide the same interface, and change the plugin import setting before the unity build player.

    I put the plugins in the Assets folder in the old times. But in package it seems can not modify the import setting. Is there any way or API can change the plugin import setting before build a player?
     
  2. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    144
    Hi @watsonsong,

    Packages are meant to be generally immutable (non-modifiable). While they _can_ be altered in some cases, for instance while developing them, they are considered immutable when they are pulled into a project through the project manifest's "dependencies" or through the "dependencies" of another package.

    If I understand correctly, you have a single managed plugin that acts as a shared interface to platform-specific SDK implementations, correct? I'm not entirely clear why you need to alter import settings dynamically.

    In your managed plugin scripts, you can wrap the native plugin calls with
    #if
    statements (e.g.
    #if UNITY_ANDROID
    ) and configure the platforms in your plugin's Assembly Definition (.asmdef file). You can mark this managed plugin to be compiled and included only for iOS and Androir, for instance.
     
  3. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    375
    There have different vendors of our game. And this game will build different apk for different vendors on android platform.
    Each vendors has it's own SDK and provide something like account system, payment or report. You may think that maybe I need to build different apk file for google, facebook and twitter.
    So there has 3 aar package and when build the apk, I want only one of them is active and only one will build into the apk. I do not want embed other aar into the final apk.
     
  4. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    144
    Hi @watsonsong,

    Thank you for explaining in detail your use case! Now I fully understand why you need this functionality. Unfortunately I don't have a really good answer for you at the moment. You could try to implement a workaround involving copying the native plugins under the Assets/Plugins directory, where you would have full control over them. To avoid GUID conflicts, you could include them in your package in a .unitypackage, or simply in a folder starting with '.' or ending with '~' so the Asset database ignores them. That would work, but of course that's neither straightforward nor very user friendly.

    I'll try to see if there is a better answer than that workaround.
     
  5. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    375
    Well, I find a new API in plugin import: DefineConstraints.
    I thinks may be I could switch defines to enable or disable different plugin.
    Thank you~
     
    maximeb_unity likes this.
  6. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    375
    Well, I find the DefineConstraints only work for c# dlls. But not for native plugins, defineConstraints is not show on the GUI.
    I test the script this define is add into the meta file. It could be good to add it on the Plugin Inspector.
     
    Last edited: May 22, 2019
  7. maximeb_unity

    maximeb_unity

    Unity Technologies

    Joined:
    Mar 20, 2018
    Posts:
    144
    Indeed. Unfortunately I haven't found a better solution for you yet, but we're tracking this as a feature request now. We're looking into solutions to solve this problem (and the broader problem of not being able to easily update import settings for packaged assets).