/// <summary> /// Compare two dictionaries of AarExplodeData. /// </summary> private bool CompareExplodeData(Dictionary <string, AarExplodeData> explodeData1, Dictionary <string, AarExplodeData> explodeData2) { if (explodeData1 == explodeData2) { return(true); } if (explodeData1 == null || explodeData2 == null) { return(false); } if (explodeData1.Count != explodeData2.Count) { return(false); } foreach (var item in explodeData1) { AarExplodeData data = null; if (!explodeData2.TryGetValue(item.Key, out data)) { return(false); } if (!item.Value.Equals(data)) { return(false); } } return(true); }
/// <summary> /// Determined whether an aar file should be exploded (extracted). /// /// This is required for some aars so that the Unity Jar Resolver can perform variable /// expansion on manifests in the package before they're merged by aapt. /// </summary> /// <returns><c>true</c>, if the aar should be exploded, <c>false</c> otherwise.</returns> /// <param name="aarFile">The aar file.</param> internal virtual bool ShouldExplode(string aarFile) { AarExplodeData aarData = null; if (!aarExplodeData.TryGetValue(aarFile, out aarData)) { aarData = new AarExplodeData(); } bool explode = !SupportsAarFiles; if (!explode) { System.DateTime modificationTime = File.GetLastWriteTime(aarFile); if (modificationTime.CompareTo(aarData.modificationTime) <= 0) { explode = aarData.explode; } } if (!explode) { string temporaryDirectory = CreateTemporaryDirectory(); if (temporaryDirectory == null) { return(false); } string manifestFilename = "AndroidManifest.xml"; try { if (ExtractAar(aarFile, new string[] { manifestFilename }, temporaryDirectory)) { string manifestPath = Path.Combine(temporaryDirectory, manifestFilename); if (File.Exists(manifestPath)) { string manifest = File.ReadAllText(manifestPath); explode = manifest.IndexOf("${applicationId}") >= 0; } aarData.modificationTime = File.GetLastWriteTime(aarFile); } } catch (System.Exception e) { Debug.Log("Unable to examine AAR file " + aarFile + ", err: " + e); throw e; } finally { PlayServicesSupport.DeleteExistingFileOrDirectory(temporaryDirectory); } } aarData.explode = explode; aarExplodeData[aarFile] = aarData; return(explode); }
/// <summary> /// Load data cached in aarExplodeDataFile into aarExplodeData. /// </summary> private void LoadAarExplodeCache() { if (!File.Exists(aarExplodeDataFile)) return; XmlTextReader reader = new XmlTextReader(new StreamReader(aarExplodeDataFile)); aarExplodeData.Clear(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "aars") { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "explodeData") { string aar = ""; AarExplodeData aarData = new AarExplodeData(); do { if (!reader.Read()) break; if (reader.NodeType == XmlNodeType.Element) { string elementName = reader.Name; if (reader.Read() && reader.NodeType == XmlNodeType.Text) { if (elementName == "aar") { aar = reader.ReadContentAsString(); } else if (elementName == "modificationTime") { aarData.modificationTime = reader.ReadContentAsDateTime(); } else if (elementName == "explode") { aarData.explode = reader.ReadContentAsBoolean(); } else if (elementName == "bundleId") { aarData.bundleId = reader.ReadContentAsString(); } else if (elementName == "path") { aarData.path = reader.ReadContentAsString(); } } } } while (!(reader.Name == "explodeData" && reader.NodeType == XmlNodeType.EndElement)); if (aar != "") aarExplodeData[aar] = aarData; } } } } }
/// <summary> /// Load data cached in aarExplodeDataFile into aarExplodeData. /// </summary> private void LoadAarExplodeCache() { if (!File.Exists(aarExplodeDataFile)) { return; } XmlTextReader reader = new XmlTextReader(new StreamReader(aarExplodeDataFile)); aarExplodeData.Clear(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "aars") { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "explodeData") { string aar = ""; AarExplodeData aarData = new AarExplodeData(); do { if (!reader.Read()) { break; } if (reader.NodeType == XmlNodeType.Element) { string elementName = reader.Name; if (reader.Read() && reader.NodeType == XmlNodeType.Text) { if (elementName == "aar") { aar = reader.ReadContentAsString(); } else if (elementName == "modificationTime") { aarData.modificationTime = reader.ReadContentAsDateTime(); } else if (elementName == "explode") { aarData.explode = reader.ReadContentAsBoolean(); } else if (elementName == "bundleId") { aarData.bundleId = reader.ReadContentAsString(); } else if (elementName == "path") { aarData.path = reader.ReadContentAsString(); } } } } while (!(reader.Name == "explodeData" && reader.NodeType == XmlNodeType.EndElement)); if (aar != "") { aarExplodeData[aar] = aarData; } } } } } }
/// <summary> /// Determined whether an aar file should be exploded (extracted). /// /// This is required for some aars so that the Unity Jar Resolver can perform variable /// expansion on manifests in the package before they're merged by aapt. /// </summary> /// <returns><c>true</c>, if the aar should be exploded, <c>false</c> otherwise.</returns> /// <param name="aarFile">The aar file.</param> internal virtual bool ShouldExplode(string aarFile) { AarExplodeData aarData = null; if (!aarExplodeData.TryGetValue(aarFile, out aarData)) { aarData = new AarExplodeData(); } bool explosionEnabled = true; // Unfortunately, as of Unity 5.5.0f3, Unity does not set the applicationId variable // in the build.gradle it generates. This results in non-functional libraries that // require the ${applicationId} variable to be expanded in their AndroidManifest.xml. // To work around this when Gradle builds are enabled, explosion is enabled for all // AARs that require variable expansion unless this behavior is explicitly disabled // in the settings dialog. if (PlayServicesResolver.GradleBuildEnabled && PlayServicesResolver.ProjectExportEnabled && !SettingsDialog.ExplodeAars) { explosionEnabled = false; } bool explode = false; if (explosionEnabled) { explode = !SupportsAarFiles; if (!explode) { System.DateTime modificationTime = File.GetLastWriteTime(aarFile); if (modificationTime.CompareTo(aarData.modificationTime) <= 0) { explode = aarData.explode; } } if (!explode) { string temporaryDirectory = CreateTemporaryDirectory(); if (temporaryDirectory == null) { return(false); } string manifestFilename = "AndroidManifest.xml"; try { if (ExtractAar(aarFile, new string[] { manifestFilename }, temporaryDirectory)) { string manifestPath = Path.Combine(temporaryDirectory, manifestFilename); if (File.Exists(manifestPath)) { string manifest = File.ReadAllText(manifestPath); explode = manifest.IndexOf("${applicationId}") >= 0; } aarData.modificationTime = File.GetLastWriteTime(aarFile); } } catch (System.Exception e) { Debug.Log("Unable to examine AAR file " + aarFile + ", err: " + e); throw e; } finally { PlayServicesSupport.DeleteExistingFileOrDirectory(temporaryDirectory); } } } aarData.explode = explode; aarExplodeData[aarFile] = aarData; return(explode); }
/// <summary> /// Determined whether an aar file should be exploded (extracted). /// /// This is required for some aars so that the Unity Jar Resolver can perform variable /// expansion on manifests in the package before they're merged by aapt. /// </summary> /// <returns><c>true</c>, if the aar should be exploded, <c>false</c> otherwise.</returns> /// <param name="aarFile">The aar file.</param> internal virtual bool ShouldExplode(string aarFile) { AarExplodeData aarData = null; if (!aarExplodeData.TryGetValue(aarFile, out aarData)) aarData = new AarExplodeData(); bool explode = !SupportsAarFiles; if (!explode) { System.DateTime modificationTime = File.GetLastWriteTime(aarFile); if (modificationTime.CompareTo(aarData.modificationTime) <= 0) { explode = aarData.explode; } } if (!explode) { string temporaryDirectory = CreateTemporaryDirectory(); if (temporaryDirectory == null) return false; string manifestFilename = "AndroidManifest.xml"; try { if (ExtractAar(aarFile, new string[] {manifestFilename}, temporaryDirectory)) { string manifestPath = Path.Combine(temporaryDirectory, manifestFilename); if (File.Exists(manifestPath)) { string manifest = File.ReadAllText(manifestPath); explode = manifest.IndexOf("${applicationId}") >= 0; } aarData.modificationTime = File.GetLastWriteTime(aarFile); } } catch (System.Exception e) { Debug.Log("Unable to examine AAR file " + aarFile + ", err: " + e); throw e; } finally { PlayServicesSupport.DeleteExistingFileOrDirectory(temporaryDirectory); } } aarData.explode = explode; aarExplodeData[aarFile] = aarData; return explode; }