Skip to content

Commit 42ce22f

Browse files
committed
Handle the C++ SDK being built for Android without doing Gradle first
Add logic that allows CMake to invoke gradle if the dexed jar files are not present already. Defines the proguard files with the same logic, so that the Unity SDK, which needs to access the proguard file, can access it. Currently the build logic of CMake invoking Gradle causes some parts of the build to be unnecessarily duplicated, and will need to be improved in the future. PiperOrigin-RevId: 277102239
1 parent 897300c commit 42ce22f

File tree

11 files changed

+108
-10
lines changed

11 files changed

+108
-10
lines changed

admob/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
cmake_minimum_required (VERSION 3.1)
1818
set (CMAKE_CXX_STANDARD 11)
1919

20+
include(binary_to_array)
2021
include(download_pod_headers)
22+
include(firebase_cpp_gradle)
2123

2224
project(firebase_admob NONE)
2325
enable_language(C)
@@ -36,6 +38,8 @@ set(common_SRCS
3638
src/common/rewarded_video_internal.cc)
3739

3840
# Define the resource build needed for Android
41+
firebase_cpp_gradle(":admob:admob_resources:generateDexJarRelease"
42+
"${CMAKE_CURRENT_LIST_DIR}/admob_resources/build/dexed.jar")
3943
binary_to_array("admob_resources"
4044
"${CMAKE_CURRENT_LIST_DIR}/admob_resources/build/dexed.jar"
4145
"firebase_admob"
@@ -107,7 +111,9 @@ else()
107111
add_definitions(-include assert.h -include string.h)
108112
endif()
109113

110-
if(IOS)
114+
if(ANDROID)
115+
firebase_cpp_proguard_file(admob)
116+
elseif(IOS)
111117
# AdMob for iOS uses weak references, which requires enabling Automatic
112118
# Reference Counting (ARC).
113119
set_property(

analytics/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ cmake_minimum_required (VERSION 3.1)
1818
set (CMAKE_CXX_STANDARD 11)
1919

2020
include(download_pod_headers)
21+
include(firebase_cpp_gradle)
2122

2223
project(firebase_analytics NONE)
2324
enable_language(C)
@@ -121,7 +122,9 @@ else()
121122
add_definitions(-include assert.h -include string.h)
122123
endif()
123124

124-
if(IOS)
125+
if(ANDROID)
126+
firebase_cpp_proguard_file(analytics)
127+
elseif(IOS)
125128
# Enable Automatic Reference Counting (ARC).
126129
set_property(
127130
TARGET firebase_analytics

app/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set (CMAKE_CXX_STANDARD 11)
2020
include(FindPkgConfig)
2121
include(binary_to_array)
2222
include(download_pod_headers)
23+
include(firebase_cpp_gradle)
2324

2425
project(firebase_app NONE)
2526
enable_language(C)
@@ -32,14 +33,20 @@ binary_to_array("google_services_resource"
3233
"${FIREBASE_GEN_FILE_DIR}/app")
3334

3435
# Define the resource builds needed for Android
36+
firebase_cpp_gradle(":app:app_resources:generateDexJarRelease"
37+
"${CMAKE_CURRENT_LIST_DIR}/app_resources/build/dexed.jar")
3538
binary_to_array("app_resources"
3639
"${CMAKE_CURRENT_LIST_DIR}/app_resources/build/dexed.jar"
3740
"firebase_app"
3841
"${FIREBASE_GEN_FILE_DIR}/app")
42+
firebase_cpp_gradle(":app:google_api_resources:generateDexJarRelease"
43+
"${CMAKE_CURRENT_LIST_DIR}/google_api_resources/build/dexed.jar")
3944
binary_to_array("google_api_resources"
4045
"${CMAKE_CURRENT_LIST_DIR}/google_api_resources/build/dexed.jar"
4146
"google_api"
4247
"${FIREBASE_GEN_FILE_DIR}/app")
48+
firebase_cpp_gradle(":app:invites_resources:generateDexJarRelease"
49+
"${CMAKE_CURRENT_LIST_DIR}/invites_resources/build/dexed.jar")
4350
binary_to_array("invites_resources"
4451
"${CMAKE_CURRENT_LIST_DIR}/invites_resources/build/dexed.jar"
4552
"firebase_invites"
@@ -340,7 +347,9 @@ if(MSVC)
340347
add_definitions(-DNOMINMAX)
341348
endif()
342349

343-
if(IOS)
350+
if(ANDROID)
351+
firebase_cpp_proguard_file(app)
352+
elseif(IOS)
344353
# Enable Automatic Reference Counting (ARC).
345354
set_property(
346355
TARGET firebase_app

auth/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set (CMAKE_CXX_STANDARD 11)
1919

2020
include(binary_to_array)
2121
include(download_pod_headers)
22+
include(firebase_cpp_gradle)
2223

2324
project(firebase_auth NONE)
2425
enable_language(C)
@@ -64,6 +65,8 @@ set(common_SRCS
6465
src/user.cc)
6566

6667
# Define the resource build needed for Android
68+
firebase_cpp_gradle(":auth:auth_resources:generateDexJarRelease"
69+
"${CMAKE_CURRENT_LIST_DIR}/auth_resources/build/dexed.jar")
6770
binary_to_array("auth_resources"
6871
"${CMAKE_CURRENT_LIST_DIR}/auth_resources/build/dexed.jar"
6972
"firebase_auth"
@@ -196,7 +199,9 @@ if(MSVC)
196199
add_definitions(-DNOMINMAX)
197200
endif()
198201

199-
if(IOS)
202+
if(ANDROID)
203+
firebase_cpp_proguard_file(auth)
204+
elseif(IOS)
200205
# Enable Automatic Reference Counting (ARC).
201206
set_property(
202207
TARGET firebase_auth

cmake/firebase_cpp_gradle.cmake

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2019 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# If the expected file does not already exist, defines a custom command to use
16+
# the Gradle Wrapper in the root directory to invoke the given build rule.
17+
#
18+
# Args:
19+
# GRADLE_TARGET: The gradle target that will be built, if needed.
20+
# EXPECTED_FILE: The expected output from the gradle target.
21+
function(firebase_cpp_gradle GRADLE_TARGET EXPECTED_FILE)
22+
if(NOT EXISTS ${EXPECTED_FILE})
23+
if(WIN32)
24+
set(gradle_command "gradlew.bat")
25+
else()
26+
set(gradle_command "./gradlew")
27+
endif()
28+
29+
# Run gradle to generated the expected file
30+
add_custom_command(
31+
COMMAND ${gradle_command} ${GRADLE_TARGET}
32+
OUTPUT ${EXPECTED_FILE}
33+
WORKING_DIRECTORY ${FIREBASE_SOURCE_DIR}
34+
)
35+
endif()
36+
endfunction()
37+
38+
# Defines a variable for generating the proguard file for a given library.
39+
# The variable is FIREBASE_CPP_${LIBRARY_NAME}_PROGUARD, all in upper case.
40+
#
41+
# Args:
42+
# LIBRARY_NAME: The name of the library to define the proguard file for.
43+
function(firebase_cpp_proguard_file LIBRARY_NAME)
44+
string(TOUPPER "${LIBRARY_NAME}" upper_name)
45+
set(proguard_var "FIREBASE_CPP_${upper_name}_PROGUARD")
46+
set(${proguard_var}
47+
"${FIREBASE_SOURCE_DIR}/${LIBRARY_NAME}/build/${LIBRARY_NAME}.pro")
48+
set("${proguard_var}" "${${proguard_var}}" PARENT_SCOPE)
49+
50+
firebase_cpp_gradle(":${LIBRARY_NAME}:externalNativeBuildRelease"
51+
"${${proguard_var}}")
52+
endfunction()

database/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set (CMAKE_CXX_STANDARD 11)
1919

2020
include(binary_to_array)
2121
include(download_pod_headers)
22+
include(firebase_cpp_gradle)
2223

2324
project(firebase_database NONE)
2425
enable_language(C)
@@ -36,6 +37,8 @@ set(common_SRCS
3637
src/common/query.cc)
3738

3839
# Define the resource build needed for Android
40+
firebase_cpp_gradle(":database:database_resources:generateDexJarRelease"
41+
"${CMAKE_CURRENT_LIST_DIR}/database_resources/build/dexed.jar")
3942
binary_to_array("database_resources"
4043
"${CMAKE_CURRENT_LIST_DIR}/database_resources/build/dexed.jar"
4144
"firebase_database_resources"
@@ -194,7 +197,9 @@ else()
194197
add_definitions(-include assert.h -include string.h)
195198
endif()
196199

197-
if(IOS)
200+
if(ANDROID)
201+
firebase_cpp_proguard_file(database)
202+
elseif(IOS)
198203
# Enable Automatic Reference Counting (ARC)
199204
set_property(
200205
TARGET firebase_database

functions/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set (CMAKE_CXX_STANDARD 11)
1919

2020
include(binary_to_array)
2121
include(download_pod_headers)
22+
include(firebase_cpp_gradle)
2223

2324
project(firebase_functions NONE)
2425
enable_language(C)
@@ -97,7 +98,9 @@ else()
9798
add_definitions(-include assert.h -include string.h)
9899
endif()
99100

100-
if(IOS)
101+
if(ANDROID)
102+
firebase_cpp_proguard_file(functions)
103+
elseif(IOS)
101104
# Enable Automatic Reference Counting (ARC).
102105
set_property(
103106
TARGET firebase_functions

instance_id/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set (CMAKE_CXX_STANDARD 11)
1919

2020
include(binary_to_array)
2121
include(download_pod_headers)
22+
include(firebase_cpp_gradle)
2223

2324
project(firebase_instance_id NONE)
2425
enable_language(C)
@@ -94,7 +95,9 @@ else()
9495
add_definitions(-include assert.h -include string.h)
9596
endif()
9697

97-
if(IOS)
98+
if(ANDROID)
99+
firebase_cpp_proguard_file(instance_id)
100+
elseif(IOS)
98101
# Enable Automatic Reference Counting (ARC).
99102
set_property(
100103
TARGET firebase_instance_id

messaging/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set (CMAKE_CXX_STANDARD 11)
1919

2020
include(binary_to_array)
2121
include(download_pod_headers)
22+
include(firebase_cpp_gradle)
2223

2324
project(firebase_messaging NONE)
2425
enable_language(C)
@@ -113,7 +114,9 @@ else()
113114
add_definitions(-include assert.h -include string.h)
114115
endif()
115116

116-
if(IOS)
117+
if(ANDROID)
118+
firebase_cpp_proguard_file(messaging)
119+
elseif(IOS)
117120
# Enable Automatic Reference Counting (ARC).
118121
set_property(
119122
TARGET firebase_messaging

remote_config/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ cmake_minimum_required (VERSION 3.1)
1818
set (CMAKE_CXX_STANDARD 11)
1919

2020
include(download_pod_headers)
21+
include(firebase_cpp_gradle)
2122

2223
project(firebase_remote_config NONE)
2324
enable_language(C)
@@ -124,7 +125,9 @@ else()
124125
add_definitions(-include assert.h -include string.h)
125126
endif()
126127

127-
if(IOS)
128+
if(ANDROID)
129+
firebase_cpp_proguard_file(remote_config)
130+
elseif(IOS)
128131
# Enable Automatic Reference Counting (ARC).
129132
set_property(
130133
TARGET firebase_remote_config

0 commit comments

Comments
 (0)