Skip to content

Commit bc6e00a

Browse files
authored
Remove property tags from Android builds (#939)
1 parent efbb21e commit bc6e00a

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

.github/workflows/integration_tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ jobs:
243243
--plugin_dir ~/Downloads/firebase_unity_sdk \
244244
--output_directory "${{ github.workspace }}" \
245245
--artifact_name "${{ steps.matrix_info.outputs.info }}" \
246+
--notimestamp \
246247
--force_latest_runtime \
247248
--ci
248249
- name: Return Unity license
@@ -420,6 +421,7 @@ jobs:
420421
--plugin_dir ~/Downloads/firebase_unity_sdk \
421422
--output_directory "${{ github.workspace }}" \
422423
--artifact_name "${{ steps.matrix_info.outputs.info }}" \
424+
--notimestamp \
423425
--force_latest_runtime \
424426
--ci
425427
- name: Return Unity license

editor/app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ else()
2424
endif()
2525

2626
set(firebase_app_editor_src
27+
src/AnalyticsFixPropertyRemover.cs
2728
src/AndroidAPILevelChecker.cs
2829
src/ApiInfo.cs
2930
src/AssemblyInfo.cs
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
namespace Firebase.Editor {
18+
using System;
19+
using System.IO;
20+
using System.Xml;
21+
using UnityEngine;
22+
using UnityEditor;
23+
using UnityEditor.Build;
24+
using UnityEditor.Build.Reporting;
25+
26+
internal class AnalyticsFixPropertyRemover : IPreprocessBuildWithReport {
27+
private static string DefaultAndroidManifestContents = String.Join("\n",
28+
"<?xml version=\"1.0\" encoding=\"utf-8\"?>",
29+
"<manifest",
30+
" xmlns:android=\"http://schemas.android.com/apk/res/android\"",
31+
" package=\"com.unity3d.player\"",
32+
" xmlns:tools=\"http://schemas.android.com/tools\">",
33+
" <application>",
34+
" <activity android:name=\"com.unity3d.player.UnityPlayerActivity\"",
35+
" android:theme=\"@style/UnityThemeSelector\">",
36+
" <intent-filter>",
37+
" <action android:name=\"android.intent.action.MAIN\" />",
38+
" <category android:name=\"android.intent.category.LAUNCHER\" />",
39+
" </intent-filter>",
40+
" <meta-data android:name=\"unityplayer.UnityActivity\" android:value=\"true\" />",
41+
" </activity>",
42+
" </application>",
43+
"</manifest>"
44+
);
45+
46+
private static string SearchTag = "AnalyticsFixPropertyRemover";
47+
private static string CommentToAdd = "This was added by the AnalyticsFixPropertyRemover. " +
48+
"If you want to prevent the generation of this, have \"" + SearchTag +
49+
"\" included in a comment";
50+
51+
public int callbackOrder { get { return 0; } }
52+
53+
public void OnPreprocessBuild(BuildReport report) {
54+
// Only run this logic when building for Android.
55+
if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android) {
56+
return;
57+
}
58+
59+
// Locate the AndroidManifest file.
60+
string androidPluginsDir = Path.Combine(Application.dataPath, "Plugins", "Android");
61+
string androidManifestPath = Path.Combine(androidPluginsDir, "AndroidManifest.xml");
62+
63+
// If the AndroidManifest file doesn't exist, generate it.
64+
if (!File.Exists(androidManifestPath)) {
65+
File.WriteAllText(androidManifestPath, DefaultAndroidManifestContents);
66+
}
67+
68+
// Check for the SearchTag, and if present there is nothing to do.
69+
if (File.ReadAllText(androidManifestPath).Contains(SearchTag)) {
70+
return;
71+
}
72+
73+
XmlDocument doc = new XmlDocument();
74+
doc.Load(androidManifestPath);
75+
76+
// Find the "application" node
77+
XmlNode applicationNode = doc.SelectSingleNode("/manifest/application");
78+
79+
if (applicationNode != null) {
80+
// Create the new "property" node
81+
XmlElement propertyNode = doc.CreateElement("property");
82+
83+
// Create and add the attribute (with namespace)
84+
XmlAttribute toolsAttribute = doc.CreateAttribute("tools", "node", "http://schemas.android.com/tools");
85+
toolsAttribute.Value = "removeAll";
86+
propertyNode.Attributes.Append(toolsAttribute);
87+
88+
// Create a comment node, and add it before the property node
89+
XmlComment comment = doc.CreateComment(CommentToAdd);
90+
91+
// Add the new node to the "application" node
92+
applicationNode.AppendChild(propertyNode);
93+
applicationNode.InsertBefore(comment, propertyNode);
94+
95+
// Save the modified XML document
96+
doc.Save(androidManifestPath);
97+
}
98+
else {
99+
Debug.LogError("Could not find the 'application' node in the AndroidManifest.xml file.");
100+
}
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)