-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·67 lines (51 loc) · 1.86 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Prompt for the Application ID
echo "Please enter your Google Application ID:"
read APPLICATION_ID
# Path to manifest
MANIFEST_PATH="./library/src/main/AndroidManifest.xml"
# Verify that the manifest file exists
if [ ! -f "$MANIFEST_PATH" ]; then
echo "Error: AndroidManifest.xml not found at $MANIFEST_PATH"
exit 1
fi
# Log the initial content of the file
#echo "Initial content of AndroidManifest.xml:"
#cat "$MANIFEST_PATH"
# Run Python script to modify the manifest correctly while preserving the namespace
python3 - <<EOF
import xml.etree.ElementTree as ET
manifest_path = "$MANIFEST_PATH"
app_id = "$APPLICATION_ID"
# Define the namespace correctly
android_ns = "http://schemas.android.com/apk/res/android"
ET.register_namespace('android', android_ns)
# Parse the XML file
tree = ET.parse(manifest_path)
root = tree.getroot()
# Ensure the correct namespace prefix is preserved
for meta_data in root.findall(".//application/meta-data"):
name_attr = meta_data.attrib.get(f"{{{android_ns}}}name")
if name_attr == "com.google.android.gms.games.APP_ID":
meta_data.set(f"{{{android_ns}}}value", app_id)
# Write changes back to the file
tree.write(manifest_path, encoding="utf-8", xml_declaration=True)
# Fix any unwanted namespace aliasing
with open(manifest_path, "r") as file:
content = file.read()
content = content.replace('xmlns:ns0', 'xmlns:android').replace('ns0:', 'android:')
with open(manifest_path, "w") as file:
file.write(content)
EOF
# Check if the update was successful
if grep -q "android:value=\"$APPLICATION_ID\"" "$MANIFEST_PATH"; then
echo "Updated Google Application ID: $APPLICATION_ID"
else
echo "Failed to update AndroidManifest.xml."
exit 1
fi
# Log the modified content of the file
# echo "Modified content of AndroidManifest.xml:"
# cat "$MANIFEST_PATH"
# Run the build command
./gradlew :library:assemble