Skip to content

Commit 71274f8

Browse files
authored
Add logic to use the special Android files for Messaging (#234)
1 parent bebd137 commit 71274f8

File tree

7 files changed

+61
-3
lines changed

7 files changed

+61
-3
lines changed

aar_builder/build_aar.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
flags.DEFINE_string("proguard_file", None,
3232
"Location of the proguard file to include in the aar")
3333
flags.mark_flag_as_required("proguard_file")
34+
flags.DEFINE_string("android_manifest", None,
35+
"Location of the AndroidManifest.xml file to include " +
36+
"in the aar. A default is used if not provided.")
37+
flags.DEFINE_string("classes_jar", None,
38+
"Location of the classes.jar file to include " +
39+
"in the aar. A default is used if not provided.")
3440

3541

3642
def main(unused_argv):
@@ -45,6 +51,14 @@ def main(unused_argv):
4551

4652
file_dir = os.path.dirname(os.path.realpath(__file__))
4753

54+
# Use the default or custom AndroidManifest.xml and classes.jar
55+
android_manifest_file = os.path.join(file_dir, "AndroidManifest.xml")
56+
if FLAGS.android_manifest:
57+
android_manifest_file = os.path.normcase(FLAGS.android_manifest)
58+
classes_jar_file = os.path.join(file_dir, "classes.jar")
59+
if FLAGS.classes_jar:
60+
classes_jar_file = os.path.normcase(FLAGS.classes_jar)
61+
4862
# Delete the aar file, if it already exists
4963
if os.path.exists(output_file):
5064
os.remove(output_file)
@@ -65,9 +79,8 @@ def main(unused_argv):
6579

6680
with zipfile.ZipFile(output_file, "w") as myzip:
6781
# Write the generic base files that are required in an aar file.
68-
myzip.write(
69-
os.path.join(file_dir, "AndroidManifest.xml"), "AndroidManifest.xml")
70-
myzip.write(os.path.join(file_dir, "classes.jar"), "classes.jar")
82+
myzip.write(android_manifest_file, "AndroidManifest.xml")
83+
myzip.write(classes_jar_file, "classes.jar")
7184
myzip.write(os.path.join(file_dir, "R.txt"), "R.txt")
7285
myzip.writestr("res/", "")
7386
# Write the provided library to the proper architecture, and proguard file.

cmake/build_aar.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ set(MAVEN_TEMPLATE ${CMAKE_CURRENT_LIST_DIR}/maven.template)
2929
# PROGUARD_TARGET: The target that outputs the proguard file.
3030
# ARTIFACT_ID: The artifact id to use with the generated files.
3131
# VERSION: The version number to tag the generated files with.
32+
#
33+
# Optional Args:
34+
# ANDROID_MANIFEST: The custom AndroidManifest file to include.
35+
# CLASSES_JAR: The custom classes.jar file to include.
3236
function(build_aar LIBRARY_NAME LIBRARY_TARGET PROGUARD_TARGET
3337
ARTIFACT_ID VERSION)
38+
# Parse the additional arguments
39+
set(single ANDROID_MANIFEST CLASSES_JAR)
40+
cmake_parse_arguments(BUILD_AAR_ARGS "" "${single}" "" ${ARGN})
41+
3442
set(AAR_NAME "${ARTIFACT_ID}-${VERSION}")
3543
set(OUTPUT_AAR "${CMAKE_CURRENT_BINARY_DIR}/${AAR_NAME}.srcaar")
3644

@@ -41,6 +49,8 @@ function(build_aar LIBRARY_NAME LIBRARY_TARGET PROGUARD_TARGET
4149
"--library_file=$<TARGET_FILE:${LIBRARY_TARGET}>"
4250
"--architecture=${ANDROID_ABI}"
4351
"--proguard_file=${${PROGUARD_TARGET}}"
52+
"--android_manifest=${BUILD_AAR_ARGS_ANDROID_MANIFEST}"
53+
"--classes_jar=${BUILD_AAR_ARGS_CLASSES_JAR}"
4454
DEPENDS
4555
"${LIBRARY_TARGET}"
4656
"${PROGUARD_TARGET}"

cmake/build_firebase_aar.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ include(build_aar)
2424
# ARTIFACT_NAME: The name to use in the artifact id.
2525
# LIBRARY_TARGET: The target that outputs the shared libary to include.
2626
# PROGUARD_TARGET: The target that outputs the proguard file.
27+
#
28+
# Optional Args:
29+
# ANDROID_MANIFEST: The custom AndroidManifest file to include.
30+
# CLASSES_JAR: The custom classes.jar file to include.
2731
function(build_firebase_aar LIBRARY_NAME ARTIFACT_NAME LIBRARY_TARGET
2832
PROGUARD_TARGET)
33+
# Parse the additional arguments
34+
set(single ANDROID_MANIFEST CLASSES_JAR)
35+
cmake_parse_arguments(FIREBASE_AAR_ARGS "" "${single}" "" ${ARGN})
36+
2937
# Set the variables expected by the templates
3038
set(ARTIFACT_ID "firebase-${ARTIFACT_NAME}-unity")
3139
set(VERSION "${FIREBASE_UNITY_SDK_VERSION}")
@@ -35,5 +43,9 @@ function(build_firebase_aar LIBRARY_NAME ARTIFACT_NAME LIBRARY_TARGET
3543
${PROGUARD_TARGET}
3644
${ARTIFACT_ID}
3745
${VERSION}
46+
ANDROID_MANIFEST
47+
${FIREBASE_AAR_ARGS_ANDROID_MANIFEST}
48+
CLASSES_JAR
49+
${FIREBASE_AAR_ARGS_CLASSES_JAR}
3850
)
3951
endfunction()

cmake/build_shared.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,16 @@ include(build_firebase_aar)
2323
# LIBRARY_NAME: The name of the library, used to determine the targets.
2424
# ARTIFACT_NAME: The name used to generate the artifact id used by the srcaar.
2525
# OUTPUT_NAME: The output name to use for the shared library
26+
#
27+
# Optional Args:
28+
# ANDROID_MANIFEST: The custom AndroidManifest file to include.
29+
# CLASSES_JAR: The custom classes.jar file to include.
2630
function(build_firebase_shared LIBRARY_NAME ARTIFACT_NAME OUTPUT_NAME)
2731

32+
set(single ANDROID_MANIFEST CLASSES_JAR)
33+
# Parse the arguments
34+
cmake_parse_arguments(FIREBASE_SHARED_ARGS "" "${single}" "" ${ARGN})
35+
2836
set(shared_target "firebase_${LIBRARY_NAME}_shared")
2937

3038
add_library(${shared_target} SHARED
@@ -93,6 +101,10 @@ function(build_firebase_shared LIBRARY_NAME ARTIFACT_NAME OUTPUT_NAME)
93101
${ARTIFACT_NAME}
94102
${shared_target}
95103
"FIREBASE_CPP_${UPPER_BASENAME}_PROGUARD"
104+
ANDROID_MANIFEST
105+
${FIREBASE_SHARED_ARGS_ANDROID_MANIFEST}
106+
CLASSES_JAR
107+
${FIREBASE_SHARED_ARGS_CLASSES_JAR}
96108
)
97109
endif()
98110

messaging/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ build_firebase_shared(
5858
messaging
5959
messaging
6060
FirebaseCppMessaging
61+
ANDROID_MANIFEST
62+
"${CMAKE_CURRENT_LIST_DIR}/AndroidManifest.xml"
63+
CLASSES_JAR
64+
"${CMAKE_CURRENT_LIST_DIR}/activity/classes.jar"
6165
)
6266
endif()
6367

messaging/activity/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The classes.jar file is a combination of the following:
2+
- The MessagingUnityPlayerActivity.java file
3+
- The firebase_messaging_cpp.aar file from the Firebase C++ SDK
4+
- The java source files from Flatbuffers
5+
And it is compiled by linking against the UnityPlayerActivity and the classes.jar provided by Unity.
6+
7+
This gets included in the firebase-messaging-unity-{version}.srcaar that is built. For now, we have this file checked in and used directly, but the plan is to switch to generating the classes.jar file as part of the open source build process.

messaging/activity/classes.jar

82.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)