private static void CheckCompatibilityWithAllSessionConfigs( ARCoreExtensionsProjectSettings settings, Dictionary <ARCoreExtensionsConfig, string> sessionToSceneMap, UnityEditor.BuildTarget buildTarget) { List <IDependentModule> featureModules = DependentModulesManager.GetModules(); foreach (IDependentModule module in featureModules) { ModuleNecessity moduleNecessity = ModuleNecessity.NotRequired; foreach (var entry in sessionToSceneMap) { ARCoreExtensionsConfig sessionConfig = entry.Key; if (!module.IsCompatible(settings, sessionConfig, buildTarget)) { throw new BuildFailedException( string.Format( "{0} isn't compatible with the ARCoreExtensionsConfig in {1}.", module.GetType().Name, entry.Value)); } moduleNecessity = (ModuleNecessity)Math.Max( (int)moduleNecessity, (int)module.GetModuleNecessity(sessionConfig)); } if (moduleNecessity == ModuleNecessity.NotRequired && module.IsEnabled(settings, buildTarget)) { Debug.LogWarning(module.GetEnabledNotRequiredWarning(settings, buildTarget)); } } }
/// <summary> /// Manage the ios dependencies based on the project settings. /// </summary> /// <param name="settings"> /// The <see cref="ARCoreExtensionsProjectSettings"/> used by current build. /// </param> public void ManageIOSDependencies(ARCoreExtensionsProjectSettings settings) { _enabledIOSTemplate.Clear(); List <IDependentModule> featureModules = DependentModulesManager.GetModules(); foreach (IDependentModule module in featureModules) { string[] iOSDependenciesTemplates = module.GetIOSDependenciesTemplateFileNames(); if (iOSDependenciesTemplates != null && iOSDependenciesTemplates.Length > 0) { bool isModuleEnabled = module.IsEnabled( settings, UnityEditor.BuildTarget.iOS); foreach (string iOSDependenciesTemplateFile in iOSDependenciesTemplates) { if (!string.IsNullOrEmpty(iOSDependenciesTemplateFile)) { Debug.LogFormat("ARCoreExtensions: {0} {1} for {2}.", isModuleEnabled ? "Include" : "Exclude", iOSDependenciesTemplateFile, module.GetType().Name); IOSSupportHelper.UpdateIOSPodDependencies( isModuleEnabled, iOSDependenciesTemplateFile); if (isModuleEnabled) { _enabledIOSTemplate.Add(iOSDependenciesTemplateFile); } } } } } }
/// <summary> /// Manage the ios dependecies based on the project settings. /// </summary> /// <param name="settings"> /// The <see cref="ARCoreExtensionsProjectSettings"/> used by current build. /// </param> public void ManageIOSDependencies(ARCoreExtensionsProjectSettings settings) { _enabledIOSTemplate.Clear(); List <IDependentModule> featureModules = DependentModulesManager.GetModules(); foreach (IDependentModule module in featureModules) { string iOSDependenciesTemplateFile = module.GetIOSDependenciesTemplateFileName(); if (!string.IsNullOrEmpty(iOSDependenciesTemplateFile)) { bool isModuleEnabled = module.IsEnabled( settings, UnityEditor.BuildTarget.iOS); if (isModuleEnabled) { Debug.LogFormat("ARCoreExtensions: Include {0} for {1}.", iOSDependenciesTemplateFile, module.GetType().Name); _enabledIOSTemplate.Add(iOSDependenciesTemplateFile); IOSSupportHelper.UpdateIOSPodDependencies( true, iOSDependenciesTemplateFile); } else { Debug.LogFormat("ARCoreExtensions: Exclude {0} for {1}.", iOSDependenciesTemplateFile, module.GetType().Name); IOSSupportHelper.UpdateIOSPodDependencies( false, iOSDependenciesTemplateFile); } } } }
/// <summary> /// Manage the android dependecies based on the project settings. /// </summary> /// <param name="settings">The <see cref="ARCoreExtensionsProjectSettings"/> used by /// current build.</param> public void ManageAndroidDependencies(ARCoreExtensionsProjectSettings settings) { List <IDependentModule> featureModules = DependentModulesManager.GetModules(); string folderPath = AssetDatabase.GUIDToAssetPath(_buildResourceFolderGUID) + _dependenciesDirectory; Directory.CreateDirectory(folderPath); foreach (IDependentModule module in featureModules) { if (module.IsEnabled(settings, UnityEditor.BuildTarget.Android)) { string dependenciesSnippet = module.GetAndroidDependenciesSnippet(settings); if (!string.IsNullOrEmpty(dependenciesSnippet)) { string fileName = module.GetType().Name + _androidDependenciesFileSuffix; string fullPath = Path.Combine(folderPath, fileName); string finalSnippet = XDocument.Parse(string.Format( _androidDependenciesFormat, dependenciesSnippet)).ToString(); File.WriteAllText(fullPath, finalSnippet); Debug.LogFormat("Module {0} added Android library dependencies:\n{1}", module.GetType().Name, finalSnippet); AssetDatabase.Refresh(); AndroidDependenciesHelper.DoPlayServicesResolve(); } } } }
/// <summary> /// Inject module proguard rules based on the project settings. /// </summary> /// <param name="settings">The <see cref="ARCoreExtensionsProjectSettings"/> used by /// current build.</param> public void InjectModuleProguardRules(ARCoreExtensionsProjectSettings settings) { bool needToEnableProguardInBuild = false; StringBuilder moduleProguardSnippets = new StringBuilder(); List <IDependentModule> featureModules = DependentModulesManager.GetModules(); foreach (IDependentModule module in featureModules) { if (module.IsEnabled(settings)) { string moduleProguardSnippet = module.GetProguardSnippet(settings); if (!string.IsNullOrEmpty(moduleProguardSnippet)) { needToEnableProguardInBuild = true; moduleProguardSnippets.AppendFormat("\n## {0} ##\n{1}\n", module.GetType().Name, moduleProguardSnippet); } } } if (needToEnableProguardInBuild) { string previousProguardRule = LoadPreviousProguardRule(); string userProguardFullPath = Path.Combine( Application.dataPath, _userProguardDirectory + _userProguardFile); string curModuleProguardRule = moduleProguardSnippets.ToString(); Directory.CreateDirectory( Path.Combine(Application.dataPath, _userProguardDirectory)); File.WriteAllText(userProguardFullPath, ReplaceModuleProguardRule(previousProguardRule, curModuleProguardRule)); } }
/// <summary> /// Return the XML snippet needs to be included if location module is enabled. /// The string output would be added as a child node of in the ‘manifest’ node /// of the customized AndroidManifest.xml. The android namespace would be provided /// and feature developers could use it directly. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The XML string snippet to add as a child of node 'manifest'.</returns> public override string GetAndroidManifestSnippet(ARCoreExtensionsProjectSettings settings) { return(@" <uses-permission android:name=""android.permission.ACCESS_FINE_LOCATION""/> <uses-feature android:name=""android.hardware.location.gps"" android:required=""true""/> <uses-feature android:name=""android.hardware.location"" android:required=""true""/>"); }
/// <summary> /// Updates the Scripting Define Symbols on iOS platforms based on the given project /// settings. /// </summary> /// <param name="projectSettings">The project settings for update.</param> public static void UpdateIOSScriptingDefineSymbols( ARCoreExtensionsProjectSettings projectSettings) { bool iosEnabled = projectSettings.IsIOSSupportEnabled; UpdateIOSScriptingDefineSymbols(ARCoreExtensionIOSSupportSymbol, iosEnabled); Dictionary <string, bool> iOSFeatureEnabled = projectSettings.GetIOSSymbolsStatus(); foreach (var keyvalue in iOSFeatureEnabled) { UpdateIOSScriptingDefineSymbols(keyvalue.Key, iosEnabled && keyvalue.Value); } }
private void SetEnabledModules(ARCoreExtensionsProjectSettings settings) { List <string> modulesEnabled = new List <string>(); foreach (IDependentModule module in DependentModulesManager.GetModules()) { if (module.IsEnabled(settings, UnityEditor.BuildTarget.Android)) { modulesEnabled.Add(module.GetType().Name); } } RuntimeConfig.SetEnabledModules(modulesEnabled); }
private void ManageAndroidDependencies(ARCoreExtensionsProjectSettings settings) { List <IDependentModule> featureModules = DependentModulesManager.GetModules(); foreach (IDependentModule module in featureModules) { if (!module.IsEnabled(settings, UnityEditor.BuildTarget.Android)) { continue; } JarArtifact[] dependencies = module.GetAndroidDependencies(settings); if (dependencies != null && dependencies.Length > 0) { ExternalDependencyResolverHelper.RegisterAndroidDependencies(dependencies); } } }
private void SetApiKeyOnIOS(ARCoreExtensionsProjectSettings settings) { if (string.IsNullOrEmpty(settings.IOSCloudServicesApiKey)) { RuntimeConfig.SetIOSApiKey(string.Empty); return; } if (!settings.IsIOSSupportEnabled) { Debug.LogWarning("Failed to enable Cloud Anchor on iOS because iOS Support " + "is not enabled. Go to 'Project Settings > XR > ARCore Extensionts' " + "to change the settings."); RuntimeConfig.SetIOSApiKey(string.Empty); return; } RuntimeConfig.SetIOSApiKey(settings.IOSCloudServicesApiKey); }
/// <summary> /// Checking whether location module is compatible with given Project Settings. /// If it returns false, the preprocessbuild will throw a general Build Failure Error /// with detailed error messages. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public override bool IsCompatibleWithSessionConfig(ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig) { CloudAnchorMode cloudAnchorMode = sessionConfig.CloudAnchorMode; bool isRequired = cloudAnchorMode == CloudAnchorMode.EnabledWithEarthLocalization; if (isRequired && !IsEnabled(settings)) { Debug.LogErrorFormat( "LocationModule is required by CloudAnchorMode {0}. Navigate to " + "'Project Settings > XR > ARCore Extensions' and select " + "Earth Cloud Anchor Enabled.", cloudAnchorMode); return(false); } else { return(true); } }
public void Load() { // If a settings file exists, load it now. if (File.Exists(k_ProjectSettingsPath)) { ARCoreExtensionsProjectSettings settings = JsonUtility.FromJson <ARCoreExtensionsProjectSettings>( File.ReadAllText(k_ProjectSettingsPath)); AndroidCloudServicesApiKey = settings.AndroidCloudServicesApiKey; } else { // Default settings. AndroidCloudServicesApiKey = string.Empty; } // Update the settings version as needed. Version = Google.XR.ARCoreExtensions.VersionInfo.Version; }
/// <summary> /// Generate the AndroidManifest XDocument based on the ARCoreProjectSettings. /// This function would be used in Tests. /// </summary> /// <param name="manifestDoc">Original AndroidManifest XML Document.</param> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The XDocument of the final AndroidManifest.</returns> public static XDocument GenerateCustomizedAndroidManifest( XDocument manifestDoc, ARCoreExtensionsProjectSettings settings) { XElement mergedRoot = manifestDoc.Root; List <IDependentModule> featureModules = DependentModulesManager.GetModules(); foreach (IDependentModule module in featureModules) { if (module.IsEnabled(settings, UnityEditor.BuildTarget.Android)) { XDocument xDocument = AndroidManifestMerger.TransferToXDocument( module.GetAndroidManifestSnippet(settings)); mergedRoot = AndroidManifestMerger.MergeXElement( mergedRoot, xDocument.Root); } } return(new XDocument(mergedRoot)); }
private static void CheckCompatibilityWithAllSesssionConfigs( ARCoreExtensionsProjectSettings settings, Dictionary <ARCoreExtensionsConfig, string> sessionToSceneMap) { List <IDependentModule> featureModules = GetModules(); foreach (IDependentModule module in featureModules) { foreach (var entry in sessionToSceneMap) { if (!module.IsCompatibleWithSessionConfig( settings, entry.Key)) { throw new BuildFailedException( string.Format( "{0} isn't compatible with the ARCoreExtensionsConfig in {1}", module.GetType().Name, entry.Value)); } } } }
/// <summary> /// Loads previous settings. /// </summary> public void Load() { // Default settings. IsIOSSupportEnabled = false; AndroidAuthenticationStrategySetting = AndroidAuthenticationStrategy.None; IOSAuthenticationStrategySetting = IOSAuthenticationStrategy.None; AndroidCloudServicesApiKey = string.Empty; IOSCloudServicesApiKey = string.Empty; if (File.Exists(_projectSettingsPath)) { ARCoreExtensionsProjectSettings settings = JsonUtility.FromJson <ARCoreExtensionsProjectSettings>( File.ReadAllText(_projectSettingsPath)); foreach (FieldInfo fieldInfo in this.GetType().GetFields()) { fieldInfo.SetValue(this, fieldInfo.GetValue(settings)); } } if (AndroidAuthenticationStrategySetting == AndroidAuthenticationStrategy.None) { AndroidAuthenticationStrategySetting = string.IsNullOrEmpty(AndroidCloudServicesApiKey) ? AndroidAuthenticationStrategy.Keyless : AndroidAuthenticationStrategy.ApiKey; } if (IOSAuthenticationStrategySetting == IOSAuthenticationStrategy.None) { IOSAuthenticationStrategySetting = string.IsNullOrEmpty(IOSCloudServicesApiKey) ? IOSAuthenticationStrategy.AuthenticationToken : IOSAuthenticationStrategy.ApiKey; } // Update the settings version as needed. Version = VersionInfo.Version; }
/// <summary> /// Checking whether it needs to be included in the customized AndroidManifest. /// The default values for new fields in ARCoreExtensionsProjectSettings should cause the /// associated module to return false. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The boolean shows whether the module is enabled.</returns> public virtual bool IsEnabled(ARCoreExtensionsProjectSettings settings) { return(false); }
/// <summary> /// Return the Proguard to include if this module is enabled. The string output will be /// added into "proguard-user.txt" directly. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The proguard rule string snippet.</returns> public override string GetProguardSnippet(ARCoreExtensionsProjectSettings settings) { return(@"-keep class com.google.android.gms.common.** { *; } -keep class com.google.android.gms.auth.** { *; } -keep class com.google.android.gms.tasks.** { *; }"); }
/// <summary> /// Return the XML snippet to include if this module is enabled. The string output will be /// added as a child node of the ‘manifest’ node of the customized AndroidManifest.xml. /// The android namespace will be available. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The XML string snippet to add as a child of node 'manifest'.</returns> public virtual string GetAndroidManifestSnippet(ARCoreExtensionsProjectSettings settings) { return(string.Empty); }
/// <summary> /// Return the Proguard snippet to include if this module is enabled. The string output /// will be added into "proguard-user.txt" directly. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The proguard rule string snippet.</returns> public virtual string GetProguardSnippet(ARCoreExtensionsProjectSettings settings) { return(string.Empty); }
/// <summary> /// Checking whether this module is compatible with given ARCoreExtensionsConfig. /// If it returns false, the preprocessbuild will throw a general Build Failure Error. /// A feature developer should use this function to log detailed error messages that /// also include a recommendation of how to resolve the issue. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public virtual bool IsCompatibleWithSessionConfig( ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig) { return(true); }
/// <summary> /// Checking whether it needs to be included in the customized AndroidManifest. /// The default values for new fields in ARCoreProjectSettings should cause the /// associated module to return false. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The boolean shows whether the module is enabled.</returns> public override bool IsEnabled(ARCoreExtensionsProjectSettings settings) { return(settings.AndroidAuthenticationStrategySetting == AndroidAuthenticationStrategy.Keyless); }
/// <summary> /// Checking whether it needs to be included in the customized AndroidManifest. /// The default values for new fields in ARCoreProjectSettings should cause the /// associated module to return false. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <returns>The boolean shows whether the module is enabled.</returns> public override bool IsEnabled(ARCoreExtensionsProjectSettings settings) { return(settings.EarthCloudAnchorEnabled); }