- Home /
Change Plugin platforms by scripting
I am making an Android game for both Google Play Store and Amazon Store.
I am using a user-defined scripting symbol "UNITY_AMAZON" and pre-processing to do the store specific scripting, but I also need to exclude some plugins when building for each target. I don't want some of the play-services .arr files in the Amazon build and I don't want the Amazon .jars in the GooglePlay build.
Of course, I can always manually select and deselect the files I want from the editor. I am asking if this can be done by scripting to automate the process as there are quite many files to change.
Answer by Claytonious · Nov 21, 2017 at 05:17 PM
Yes. Get its importer and then change settings on that. For example, this turns off the Android platform on a native library:
((PluginImporter)PluginImporter.GetAtPath("Assets/Plugins/Android/libs/armeabi-v7a/libovrplatformloader.so")).SetCompatibleWithPlatform(BuildTarget.Android, false);
Answer by adarshnambiar · Mar 23, 2017 at 07:34 PM
I found some related discussion Check this if you haven't
Thank you, I couldn't find that discussion by myself. From what I've read there, I understand that there is no built-in way to do what I need. I will come back with an answer after I implement a workaround. I'm thinking about storing every file's path/name in an editor script that will move them to another folder before the build starts and after that, it will restore the files to their original directory.
Answer by SohailBukhari · Mar 24, 2017 at 01:47 PM
You have to adjust the settings on the library asset in the inspector to choose on which platform(s) this library should be included and used.
I know this. But I need to change a lot of files. Imagine having to do this manually for 20 files in multiple folders per platform per build. Chances to miss something are really high. $$anonymous$$y question is if this can be done by scripting. For example, make a list of files and then set them to be included in Android if certain conditions are met.
Answer by xLeo · May 05, 2021 at 06:13 PM
@a96andrei: We use this code to disable plugins like Firebase (since some features depend on Google Play Services):
public static void ToggleFirebaseRemoteConfigDependencies(bool supportsGooglePlayServices)
{
Debug.LogFormat("[ToggleFirebaseRemoteConfigDependencies] Platform supports Google Play Services: {0}", supportsGooglePlayServices);
const string remoteConfigPath = "Assets/Firebase/Plugins/Firebase.RemoteConfig.dll";
TogglePluginEnabledOrDisabled(remoteConfigPath, supportsGooglePlayServices, BuildTarget.Android);
}
private static void TogglePluginEnabledOrDisabled(string filePath, bool enableFile, BuildTarget buildTarget)
{
var pluginImporter = AssetImporter.GetAtPath(filePath) as PluginImporter;
if (!pluginImporter)
{
Debug.LogWarningFormat("[TogglePluginEnabledOrDisabled] Aborting: Couldn't find plugin importer for File Path: {0}", filePath);
return;
}
pluginImporter.SetCompatibleWithPlatform(buildTarget, enableFile);
EditorUtility.SetDirty(pluginImporter);
pluginImporter.SaveAndReimport();
Debug.LogFormat("[TogglePluginEnabledOrDisabled] Target State: {0}; Platform: {1}; File Path: {2}",
enableFile, buildTarget, filePath);
}
Your answer
Follow this Question
Related Questions
Unity Android App closed suddenly 0 Answers
Unity is unable to find native libraries. 0 Answers
why unity not resolving aar and jar files 0 Answers
Custom Pre Build Process? 4 Answers