Created
May 31, 2017 09:52
-
-
Save Tamplier/d56300c846ee62879c85125bdf711de3 to your computer and use it in GitHub Desktop.
Unity Jar Resolver Dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using UnityEditor; | |
[InitializeOnLoad] | |
public class MyDependencies : AssetPostprocessor { | |
#if UNITY_ANDROID | |
public static object svcSupport; | |
#endif | |
static MyDependencies() { | |
RegisterDependencies(); | |
} | |
public static void RegisterDependencies() { | |
#if UNITY_ANDROID | |
RegisterAndroidDependencies(); | |
#endif | |
} | |
public static void RegisterAndroidDependencies() { | |
Type playServicesSupport = Google.VersionHandler.FindClass( | |
"Google.JarResolver", "Google.JarResolver.PlayServicesSupport"); | |
if (playServicesSupport == null) { | |
return; | |
} | |
svcSupport = svcSupport ?? Google.VersionHandler.InvokeStaticMethod( | |
playServicesSupport, "CreateInstance", | |
new object[] { | |
"GooglePlayGames", | |
EditorPrefs.GetString("AndroidSdkRoot"), | |
"ProjectSettings" | |
}); | |
Google.VersionHandler.InvokeInstanceMethod( | |
svcSupport, "DependOn", | |
new object[] { | |
"com.google.android.gms", | |
"play-services-ads", | |
"10.+" }, | |
namedArgs: new Dictionary<string, object>() { | |
{"packageIds", new string[] { "extra-google-m2repository" } } | |
}); | |
Google.VersionHandler.InvokeInstanceMethod( | |
svcSupport, "DependOn", | |
new object[] { | |
"com.google.android.gms", | |
"play-services-location", | |
"10.+" }, | |
namedArgs: new Dictionary<string, object>() { | |
{"packageIds", new string[] { "extra-google-m2repository" } } | |
}); | |
Google.VersionHandler.InvokeInstanceMethod( | |
svcSupport, "DependOn", | |
new object[] { "com.android.support", "support-v4", "23.+" }, | |
namedArgs: new Dictionary<string, object>() { | |
{"packageIds", new string[] { "extra-android-m2repository" } } | |
}); | |
UnityEngine.Debug.Log("Finished"); | |
} | |
// Handle delayed loading of the dependency resolvers. | |
private static void OnPostprocessAllAssets( | |
string[] importedAssets, string[] deletedAssets, | |
string[] movedAssets, string[] movedFromPath) { | |
foreach (string asset in importedAssets) { | |
if (asset.Contains("JarResolver")) { | |
RegisterDependencies(); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment