Skip to content

Commit

Permalink
Fix issue with Android package name (#266)
Browse files Browse the repository at this point in the history
* Replace the package name in the Android srcaar

* Update build_aar.cmake

* Fix python script, and update version number
  • Loading branch information
a-maurice authored May 3, 2022
1 parent dcde678 commit e1ba4e7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
22 changes: 21 additions & 1 deletion aar_builder/build_aar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# limitations under the License.
"""Combines some base files and the given files into an aar file."""

import re
import shutil
import tempfile
import os
import zipfile
from absl import app
Expand All @@ -37,6 +40,8 @@
flags.DEFINE_string("classes_jar", None,
"Location of the classes.jar file to include " +
"in the aar. A default is used if not provided.")
flags.DEFINE_string("manifest_package_name", None,
"Package name to overwrite the AndroidManifest with.")


def main(unused_argv):
Expand All @@ -59,6 +64,21 @@ def main(unused_argv):
if FLAGS.classes_jar:
classes_jar_file = os.path.normcase(FLAGS.classes_jar)

# Edit the AndroidManifest file, replacing the package name
# with the provided one
temp_dir = tempfile.mkdtemp()
patched_manifest = shutil.copy(android_manifest_file, temp_dir)
if FLAGS.manifest_package_name:
with open(patched_manifest, "r") as new_file:
contents = new_file.read()

contents = re.sub('package=".+"',
'package="%s"' % FLAGS.manifest_package_name,
contents)

with open(patched_manifest, "w") as new_file:
new_file.write(contents)

# Delete the aar file, if it already exists
if os.path.exists(output_file):
os.remove(output_file)
Expand All @@ -79,7 +99,7 @@ def main(unused_argv):

with zipfile.ZipFile(output_file, "w") as myzip:
# Write the generic base files that are required in an aar file.
myzip.write(android_manifest_file, "AndroidManifest.xml")
myzip.write(patched_manifest, "AndroidManifest.xml")
myzip.write(classes_jar_file, "classes.jar")
myzip.write(os.path.join(file_dir, "R.txt"), "R.txt")
myzip.writestr("res/", "")
Expand Down
4 changes: 3 additions & 1 deletion cmake/build_aar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ set(MAVEN_TEMPLATE ${CMAKE_CURRENT_LIST_DIR}/maven.template)
# Optional Args:
# ANDROID_MANIFEST: The custom AndroidManifest file to include.
# CLASSES_JAR: The custom classes.jar file to include.
# MANIFEST_PACKAGE_NAME: Package name to overwrite the AndroidManifest with.
function(build_aar LIBRARY_NAME LIBRARY_TARGET PROGUARD_TARGET
ARTIFACT_ID VERSION)
# Parse the additional arguments
set(single ANDROID_MANIFEST CLASSES_JAR)
set(single ANDROID_MANIFEST CLASSES_JAR MANIFEST_PACKAGE_NAME)
cmake_parse_arguments(BUILD_AAR_ARGS "" "${single}" "" ${ARGN})

set(AAR_NAME "${ARTIFACT_ID}-${VERSION}")
Expand All @@ -51,6 +52,7 @@ function(build_aar LIBRARY_NAME LIBRARY_TARGET PROGUARD_TARGET
"--proguard_file=${${PROGUARD_TARGET}}"
"--android_manifest=${BUILD_AAR_ARGS_ANDROID_MANIFEST}"
"--classes_jar=${BUILD_AAR_ARGS_CLASSES_JAR}"
"--manifest_package_name=${BUILD_AAR_ARGS_MANIFEST_PACKAGE_NAME}"
DEPENDS
"${LIBRARY_TARGET}"
"${PROGUARD_TARGET}"
Expand Down
2 changes: 2 additions & 0 deletions cmake/build_firebase_aar.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ function(build_firebase_aar LIBRARY_NAME ARTIFACT_NAME LIBRARY_TARGET
${FIREBASE_AAR_ARGS_ANDROID_MANIFEST}
CLASSES_JAR
${FIREBASE_AAR_ARGS_CLASSES_JAR}
MANIFEST_PACKAGE_NAME
"com.google.firebase.unity.${LIBRARY_NAME}"
)
endfunction()
2 changes: 1 addition & 1 deletion cmake/firebase_unity_version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# This file defines the version numbers used by the Firebase Unity SDK.

set(FIREBASE_UNITY_SDK_VERSION "8.10.0"
set(FIREBASE_UNITY_SDK_VERSION "8.10.1"
CACHE STRING "The version of the Unity SDK, used in the names of files.")

set(FIREBASE_IOS_POD_VERSION "8.15.0"
Expand Down
4 changes: 4 additions & 0 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ Support

Release Notes
-------------
### 8.10.1
- Changes
- General (Android): Fix an issue when building with mainTemplate.gradle.

### 8.10.0
- Changes
- General (Editor, macOS): Fix an issue when finding "python" executable.
Expand Down

0 comments on commit e1ba4e7

Please sign in to comment.