Skip to content

Commit 74ef331

Browse files
authored
Merge pull request #179 from firebase/version_workflow
Fix android dependency related logic
2 parents 476e4b8 + 9feede4 commit 74ef331

File tree

8 files changed

+155
-20
lines changed

8 files changed

+155
-20
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# Higher CMake version needed for improvments in UseSwig.cmake and string join
1818
cmake_minimum_required (VERSION 3.13.4)
1919
set (CMAKE_CXX_STANDARD 11)
20+
set (CMAKE_CXX_FLAGS "-fexceptions")
2021

2122
# Turn on virtual folders for visual studio
2223
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Home brew can be used to install required dependencies:
3636
# https://github.com/protocolbuffers/protobuf/blob/master/kokoro/macos/prepare_build_macos_rc#L20
3737
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
3838
source $HOME/.rvm/scripts/rvm
39-
brew install cmake protobuf python2 mono swig@3
39+
brew install cmake protobuf python mono swig
4040
sudo chown -R $(whoami) /usr/local
4141

4242
export PATH="/usr/local/opt/swig@3/bin:$PATH"

build_android.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ mkdir -p android_build
8080
pushd android_build
8181

8282
# Configure cmake with option value
83-
cmake .. ${CMAKE_OPTIONS} -DANDROID_ABI=armeabi-v7a "$@"
83+
cmake .. ${CMAKE_OPTIONS} "$@"
8484
check_exit_code $?
8585

8686
# Build the SDK

build_package.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# Lint as: python2
1817
"""Packages zip files from unity builds into unity packages.
1918
2019
Takes packages produced from the unity sdk builds i.e.:

cmake/android_dependencies.cmake

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,61 @@
1616

1717
set(FIREBASE_APP_ANDROID_DEPS
1818
"com.google.firebase:firebase-common:20.0.0"
19-
"com.google.firebase:firebase-analytics:20.0.0"
19+
"com.google.firebase:firebase-analytics:20.1.0"
20+
"com.google.android.gms:play-services-base:18.0.1"
2021
)
2122

2223
set(FIREBASE_ANALYTICS_ANDROID_DEPS
23-
"com.google.firebase:firebase-analytics:20.0.0"
24+
"com.google.firebase:firebase-analytics:20.1.0"
2425
)
2526

2627
set(FIREBASE_AUTH_ANDROID_DEPS
2728
"com.google.firebase:firebase-auth:21.0.1"
28-
"com.google.firebase:firebase-analytics:20.0.0"
29+
"com.google.firebase:firebase-analytics:20.1.0"
2930
)
3031

3132
set(FIREBASE_CRASHLYTICS_ANDROID_DEPS
32-
"com.google.firebase:firebase-crashlytics-ndk:18.2.4"
33-
"com.google.firebase:firebase-analytics:19.0.0"
33+
"com.google.firebase:firebase-crashlytics-ndk:18.2.8"
34+
"com.google.firebase:firebase-analytics:20.1.0"
3435
)
3536

3637
set(FIREBASE_DATABASE_ANDROID_DEPS
3738
"com.google.firebase:firebase-database:20.0.3"
38-
"com.google.firebase:firebase-analytics:20.0.0"
39+
"com.google.firebase:firebase-analytics:20.1.0"
40+
"com.google.android.gms:play-services-base:18.0.1"
3941
)
4042

4143
set(FIREBASE_DYNAMIC_LINKS_ANDROID_DEPS
42-
"com.google.android.gms:play-services-appinvite:18.0.0"
43-
"com.google.firebase:firebase-analytics:20.0.0"
44+
"com.google.firebase:firebase-dynamic-links:21.0.0"
45+
"com.google.firebase:firebase-analytics:20.1.0"
46+
)
47+
48+
set(FIREBASE_FIRESTORE_ANDROID_DEPS
49+
"com.google.firebase:firebase-firestore:24.0.1"
50+
"com.google.firebase:firebase-analytics:20.1.0"
4451
)
4552

4653
set(FIREBASE_FUNCTIONS_ANDROID_DEPS
4754
"com.google.firebase:firebase-functions:20.0.1"
48-
"com.google.firebase:firebase-analytics:20.0.0"
55+
"com.google.firebase:firebase-analytics:20.1.0"
56+
)
57+
58+
set(FIREBASE_INSTALLATIONS_ANDROID_DEPS
59+
"com.google.firebase:firebase-installations:17.0.0"
60+
"com.google.firebase:firebase-analytics:20.1.0"
4961
)
5062

5163
set(FIREBASE_MESSAGING_ANDROID_DEPS
5264
"com.google.firebase:firebase-messaging:23.0.0"
53-
"com.google.firebase:firebase-analytics:20.0.0"
65+
"com.google.firebase:firebase-analytics:20.1.0"
5466
)
5567

5668
set(FIREBASE_REMOTE_CONFIG_ANDROID_DEPS
5769
"com.google.firebase:firebase-config:21.0.1"
58-
"com.google.firebase:firebase-analytics:20.0.0"
70+
"com.google.firebase:firebase-analytics:20.1.0"
5971
)
6072

6173
set(FIREBASE_STORAGE_ANDROID_DEPS
6274
"com.google.firebase:firebase-storage:20.0.0"
63-
"com.google.firebase:firebase-analytics:20.0.0"
75+
"com.google.firebase:firebase-analytics:20.1.0"
6476
)

cmake/firebase_unity_version.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

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

17-
set(FIREBASE_UNITY_SDK_VERSION "8.5.0"
17+
set(FIREBASE_UNITY_SDK_VERSION "8.8.1"
1818
CACHE STRING "The version of the Unity SDK, used in the names of files.")
1919

20-
set(FIREBASE_IOS_POD_VERSION "8.9.0"
20+
set(FIREBASE_IOS_POD_VERSION "8.10.0"
2121
CACHE STRING "The version of the top-level Firebase Cocoapod to use.")
2222

2323
# https://github.com/googlesamples/unity-jar-resolver
@@ -27,7 +27,7 @@ set(FIREBASE_UNITY_JAR_RESOLVER_VERSION "1.2.169"
2727
)
2828

2929
# https://github.com/firebase/firebase-cpp-sdk
30-
set(FIREBASE_CPP_SDK_PRESET_VERSION "v8.8.0"
30+
set(FIREBASE_CPP_SDK_PRESET_VERSION "v8.9.0"
3131
CACHE STRING
3232
"Version tag of Firebase CPP SDK to download (if no local or not passed in) and use (no trailing .0)"
3333
)

firestore/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ if (FIREBASE_INCLUDE_UNITY)
159159
IOS_DEPS
160160
"Firebase/Firestore"
161161
ANDROID_DEPS
162-
${FIREBASE_DATABASE_ANDROID_DEPS}
162+
${FIREBASE_FIRESTORE_ANDROID_DEPS}
163163
ANDROID_SPEC
164164
"firestore"
165165
)

scripts/update_versions.py

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# Lint as: python2
1817
"""Update the version numbers in cmake/firebase_unity_version.cmake.
1918
2019
To use locally, make sure call following installation first.
@@ -24,6 +23,9 @@
2423
python scripts/update_versions.py --unity_sdk_version=<version number>
2524
"""
2625
import os
26+
import re
27+
import requests
28+
from xml.etree import ElementTree
2729

2830
from github import Github
2931
from absl import app
@@ -50,6 +52,126 @@ def get_ios_pod_version_from_cpp():
5052
result = line.split()
5153
return result[-1].strip("\'")
5254

55+
########## Android versions update #############################
56+
57+
# Android gMaven repository from where we scan available Android packages
58+
# and their versions
59+
GMAVEN_MASTER_INDEX = "https://dl.google.com/dl/android/maven2/master-index.xml"
60+
GMAVEN_GROUP_INDEX = "https://dl.google.com/dl/android/maven2/{0}/group-index.xml"
61+
62+
# Regex to match versions with just digits (ignoring things like -alpha, -beta)
63+
RE_NON_EXPERIMENTAL_VERSION = re.compile('[0-9.]+$')
64+
65+
def get_latest_maven_versions(ignore_packages=None, allow_experimental=False):
66+
"""Gets latest versions of android packages from google Maven repository.
67+
68+
Args:
69+
ignore_packages (list[str], optional): Case insensitive list of substrings
70+
If any of these substrings are present in the android package name, it
71+
will not be updated.
72+
Eg: ['Foo', 'bar'] will ignore all android packages that have 'foo' or
73+
'bar' in their name. For example, 'my.android.foo.package',
74+
'myfoo.android.package'
75+
allow_experimental (bool): Allow experimental versions.
76+
Eg: 1.2.3-alpha, 1.2.3-beta, 1.2.3-rc
77+
78+
Returns:
79+
dict: Dictionary of the form {<str>: list(str)} containing full name of
80+
android package as the key and its list of versions as value.
81+
"""
82+
if ignore_packages is None:
83+
ignore_packages = []
84+
85+
latest_versions = {}
86+
response = requests.get(GMAVEN_MASTER_INDEX)
87+
index_xml = ElementTree.fromstring(response.content)
88+
for index_child in index_xml:
89+
group_name = index_child.tag
90+
group_path = group_name.replace('.', '/')
91+
response = requests.get(GMAVEN_GROUP_INDEX.format(group_path))
92+
group_xml = ElementTree.fromstring(response.content)
93+
for group_child in group_xml:
94+
package_name = group_child.tag.replace('-', '_')
95+
package_full_name = group_name + "." + package_name
96+
if any(ignore_package.lower().replace('-', '_') in package_full_name.lower()
97+
for ignore_package in ignore_packages):
98+
continue
99+
versions = group_child.attrib['versions'].split(',')
100+
if not allow_experimental:
101+
versions = [version for version in versions
102+
if re.match(RE_NON_EXPERIMENTAL_VERSION, version) or '-cppsdk' in version]
103+
if versions:
104+
latest_valid_version = versions[-1]
105+
latest_versions[package_full_name] = latest_valid_version
106+
return latest_versions
107+
108+
# Regex to match lines like:
109+
# 'com.google.firebase:firebase-auth:1.2.3'
110+
RE_GENERIC_DEPENDENCY_MODULE = re.compile(
111+
r"(?P<quote>[\'\"])(?P<pkg>[a-zA-Z0-9._-]+:[a-zA-Z0-9._-]+):([0-9.]+)[\'\"]"
112+
)
113+
114+
def modify_dependency_file(dependency_filepath, version_map):
115+
"""Modify a dependency file to reference the correct module versions.
116+
117+
Looks for lines like: 'com.google.firebase:firebase-auth:1.2.3'
118+
for modules matching the ones in the version map, and modifies them in-place.
119+
120+
Args:
121+
dependency_filename: Relative path to the dependency file to edit.
122+
version_map: Dictionary of packages to version numbers, e.g. {
123+
'com.google.firebase.firebase_auth': '15.0.0' }
124+
"""
125+
global logfile_lines
126+
logging.debug('Reading dependency file: {0}'.format(dependency_filepath))
127+
lines = None
128+
with open(dependency_filepath, "r") as dependency_file:
129+
lines = dependency_file.readlines()
130+
if not lines:
131+
logging.fatal('Update failed. ' +
132+
'Could not read contents from file {0}.'.format(dependency_filepath))
133+
134+
output_lines = []
135+
136+
# Replacement function, look up the version number of the given pkg.
137+
def replace_dependency(m):
138+
if not m.group('pkg'):
139+
return m.group(0)
140+
pkg = m.group('pkg').replace('-', '_').replace(':', '.')
141+
if pkg not in version_map:
142+
return m.group(0)
143+
quote_type = m.group('quote')
144+
if not quote_type:
145+
quote_type = "'"
146+
return '%s%s:%s%s' % (quote_type, m.group('pkg'), version_map[pkg],
147+
quote_type)
148+
149+
substituted_pairs = []
150+
to_update = False
151+
for line in lines:
152+
substituted_line = re.sub(RE_GENERIC_DEPENDENCY_MODULE, replace_dependency,
153+
line)
154+
output_lines.append(substituted_line)
155+
if substituted_line != line:
156+
substituted_pairs.append((line, substituted_line))
157+
to_update = True
158+
log_match = re.search(RE_GENERIC_DEPENDENCY_MODULE, line)
159+
log_pkg = log_match.group('pkg').replace('-', '_').replace(':', '.')
160+
161+
if to_update:
162+
print('Updating contents of {0}'.format(dependency_filepath))
163+
for original, substituted in substituted_pairs:
164+
print('(-) ' + original + '(+) ' + substituted)
165+
with open(dependency_filepath, 'w') as dependency_file:
166+
dependency_file.writelines(output_lines)
167+
print()
168+
169+
def update_android_deps():
170+
deps_path = os.path.join(os.getcwd(), "cmake", "android_dependencies.cmake")
171+
latest_android_versions_map = get_latest_maven_versions()
172+
modify_dependency_file(deps_path, latest_android_versions_map)
173+
174+
53175
def update_unity_version(unity_sdk_version):
54176
version_cmake_path = os.path.join(os.getcwd(), "cmake", "firebase_unity_version.cmake")
55177
replacement = ""
@@ -86,6 +208,7 @@ def main(argv):
86208
raise app.UsageError('Please set unity_sdk_version.')
87209

88210
update_unity_version(FLAGS.unity_sdk_version)
211+
update_android_deps()
89212

90213
if __name__ == '__main__':
91214
app.run(main)

0 commit comments

Comments
 (0)