Skip to content

Commit b92e273

Browse files
author
Brian Chen
committed
Merge branch 'master' into bc/index-scheduler
2 parents c660690 + b7915e3 commit b92e273

File tree

40 files changed

+696
-394
lines changed

40 files changed

+696
-394
lines changed

apk-size/app/build.gradle

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,42 @@
1515
apply plugin: "com.android.application"
1616
apply from: "default.gradle"
1717
android {
18-
flavorDimensions "apkSize"
18+
flavorDimensions "firebase", "abi"
19+
20+
// https://developer.android.com/ndk/guides/abis
21+
productFlavors {
22+
"universal" {
23+
dimension "abi"
24+
}
25+
26+
"armeabi-v7a" {
27+
dimension "abi"
28+
ndk {
29+
abiFilters "armeabi-v7a"
30+
}
31+
}
32+
33+
"arm64-v8a" {
34+
dimension "abi"
35+
ndk {
36+
abiFilters "arm64-v8a"
37+
}
38+
}
39+
40+
"x86" {
41+
dimension "abi"
42+
ndk {
43+
abiFilters "x86"
44+
}
45+
}
46+
47+
"x86_64" {
48+
dimension "abi"
49+
ndk {
50+
abiFilters "x86_64"
51+
}
52+
}
53+
}
1954

2055
compileOptions {
2156
sourceCompatibility JavaVersion.VERSION_1_8

apk-size/app/configure.gradle

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,30 @@ if (project.hasProperty('sdks')) {
2626
sdks.split(',').each { sdk ->
2727
def (groupId, artifactId, version) = sdk.split(':')
2828
productFlavors.create(artifactId) {
29-
dimension 'apkSize'
29+
dimension 'firebase'
3030
}
3131
dependencies.add("${artifactId}Implementation", sdk)
3232
}
33+
34+
// Ignore debug builds as measurements are not reproducible due to disabled ZipAlign.
35+
// Ignore per-architecture builds for all products except for firebase-crashlytics-ndk.
36+
variantFilter { variant ->
37+
def buildType = variant.buildType.name
38+
def flavors = variant.flavors*.name
39+
if (buildType == 'debug'
40+
|| ('firebase-crashlytics-ndk' in flavors && 'universal' in flavors)
41+
|| !('firebase-crashlytics-ndk' in flavors || 'universal' in flavors)) {
42+
setIgnore(true)
43+
}
44+
}
45+
46+
applicationVariants.all { variant ->
47+
def product = variant.productFlavors[0].name
48+
def abi = variant.productFlavors[1].name
49+
def buildType = variant.buildType.name
50+
variant.outputs.all {
51+
outputFileName = "${product}::${buildType}::${abi}.apk"
52+
}
53+
}
3354
}
3455
}

apk-size/app/default.gradle

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ android {
5757
shrinkResources false
5858
}
5959
}
60-
61-
variantFilter { variant ->
62-
def buildTypeName = variant.buildType*.name
63-
if (buildTypeName.contains('debug')) {
64-
setIgnore(true)
65-
}
66-
}
6760
}
6861

6962
dependencies {

apk-size/app/src/base/base.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
android {
1717
productFlavors {
1818
base {
19-
dimension "apkSize"
19+
dimension "firebase"
2020
applicationId "com.google.apksize.base"
2121
}
2222
}

apk-size/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
# limitations under the License.
1414

1515
android.useAndroidX=true
16+
android.enableJetifier=true
1617

1718
org.gradle.jvmargs=-Xmx8g -XX:MaxPermSize=8g
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
version=16.0.1
2+
latestReleasedVersion=16.0.0-beta02

ci/fireci/fireciplugins/binary_size.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def binary_size(pull_request, log, metrics_service_url, access_token):
5959

6060
gradle.run('assemble', '--continue', gradle.P('sdks', sdks), workdir='apk-size', check=False)
6161

62-
test_results = _measure_aar_sizes(artifacts) + _measure_apk_sizes(artifacts)
62+
test_results = _measure_aar_sizes(artifacts) + _measure_apk_sizes()
6363
test_report = {'metric': 'BinarySize', 'results': test_results, 'log': log}
6464

6565
uploader.post_report(test_report, metrics_service_url, access_token)
@@ -79,17 +79,17 @@ def _measure_aar_sizes(artifacts):
7979
return test_results
8080

8181

82-
def _measure_apk_sizes(artifacts):
82+
def _measure_apk_sizes():
8383
test_results = []
8484

85-
for artifact in artifacts:
86-
group_id, artifact_id, version = artifact.split(':')
87-
apk_files = glob.glob(f'./apk-size/**/{artifact_id}/**/*.apk', recursive=True)
85+
apk_files = glob.glob(fr'./apk-size/**/*.apk', recursive=True)
86+
for apk_file in apk_files:
87+
filename = os.path.basename(apk_file)
88+
artifact, build_type, abi = os.path.splitext(filename)[0].split('::')
89+
apk_type = build_type if abi == 'universal' else f'{build_type} / {abi}'
90+
apk_size = os.path.getsize(apk_file)
8891

89-
for apk_file in apk_files:
90-
build_type = re.search(fr'{artifact_id}/([^/]*)/', apk_file).group(1)
91-
apk_size = os.path.getsize(apk_file)
92-
test_results.append({'sdk': artifact_id, 'type': f'apk ({build_type})', 'value': apk_size})
92+
test_results.append({'sdk': artifact, 'type': f'apk ({apk_type})', 'value': apk_size})
9393

9494
return test_results
9595

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/CheckForUpdateClient.java renamed to firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/CheckForNewReleaseClient.java

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,33 @@
3636
import java.util.concurrent.Executor;
3737
import java.util.concurrent.Executors;
3838

39-
class CheckForUpdateClient {
40-
private static final int UPDATE_THREAD_POOL_SIZE = 4;
39+
class CheckForNewReleaseClient {
40+
private static final int NEW_RELEASE_THREAD_POOL_SIZE = 4;
41+
private static final String TAG = "CheckForNewReleaseClient:";
4142

4243
private final FirebaseApp firebaseApp;
4344
private final FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient;
4445
private final FirebaseInstallationsApi firebaseInstallationsApi;
4546
private static final ConcurrentMap<String, String> cachedCodeHashes = new ConcurrentHashMap<>();
4647
private final ReleaseIdentifierStorage releaseIdentifierStorage;
4748

48-
Task<AppDistributionReleaseInternal> cachedCheckForUpdate = null;
49-
private final Executor checkForUpdateExecutor;
49+
Task<AppDistributionReleaseInternal> cachedCheckForNewRelease = null;
50+
private final Executor checkForNewReleaseExecutor;
5051

51-
CheckForUpdateClient(
52+
CheckForNewReleaseClient(
5253
@NonNull FirebaseApp firebaseApp,
5354
@NonNull FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient,
5455
@NonNull FirebaseInstallationsApi firebaseInstallationsApi) {
5556
this.firebaseApp = firebaseApp;
5657
this.firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient;
5758
this.firebaseInstallationsApi = firebaseInstallationsApi;
5859
// TODO: verify if this is best way to use executorservice here
59-
this.checkForUpdateExecutor = Executors.newFixedThreadPool(UPDATE_THREAD_POOL_SIZE);
60+
this.checkForNewReleaseExecutor = Executors.newFixedThreadPool(NEW_RELEASE_THREAD_POOL_SIZE);
6061
this.releaseIdentifierStorage =
6162
new ReleaseIdentifierStorage(firebaseApp.getApplicationContext());
6263
}
6364

64-
CheckForUpdateClient(
65+
CheckForNewReleaseClient(
6566
@NonNull FirebaseApp firebaseApp,
6667
@NonNull FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient,
6768
@NonNull FirebaseInstallationsApi firebaseInstallationsApi,
@@ -70,94 +71,94 @@ class CheckForUpdateClient {
7071
this.firebaseAppDistributionTesterApiClient = firebaseAppDistributionTesterApiClient;
7172
this.firebaseInstallationsApi = firebaseInstallationsApi;
7273
// TODO: verify if this is best way to use executorservice here
73-
this.checkForUpdateExecutor = executor;
74+
this.checkForNewReleaseExecutor = executor;
7475
this.releaseIdentifierStorage =
7576
new ReleaseIdentifierStorage(firebaseApp.getApplicationContext());
7677
}
7778

7879
@NonNull
79-
public synchronized Task<AppDistributionReleaseInternal> checkForUpdate() {
80+
public synchronized Task<AppDistributionReleaseInternal> checkForNewRelease() {
8081

81-
if (cachedCheckForUpdate != null && !cachedCheckForUpdate.isComplete()) {
82-
return cachedCheckForUpdate;
82+
if (cachedCheckForNewRelease != null && !cachedCheckForNewRelease.isComplete()) {
83+
return cachedCheckForNewRelease;
8384
}
8485

8586
Task<String> installationIdTask = firebaseInstallationsApi.getId();
8687
// forceRefresh is false to get locally cached token if available
8788
Task<InstallationTokenResult> installationAuthTokenTask =
8889
firebaseInstallationsApi.getToken(false);
8990

90-
this.cachedCheckForUpdate =
91+
this.cachedCheckForNewRelease =
9192
Tasks.whenAllSuccess(installationIdTask, installationAuthTokenTask)
9293
.onSuccessTask(
93-
checkForUpdateExecutor,
94+
checkForNewReleaseExecutor,
9495
tasks -> {
9596
String fid = installationIdTask.getResult();
9697
InstallationTokenResult installationTokenResult =
9798
installationAuthTokenTask.getResult();
9899
try {
99-
AppDistributionReleaseInternal latestRelease =
100-
getLatestReleaseFromClient(
100+
AppDistributionReleaseInternal newRelease =
101+
getNewReleaseFromClient(
101102
fid,
102103
firebaseApp.getOptions().getApplicationId(),
103104
firebaseApp.getOptions().getApiKey(),
104105
installationTokenResult.getToken());
105-
return Tasks.forResult(latestRelease);
106+
return Tasks.forResult(newRelease);
106107
} catch (FirebaseAppDistributionException ex) {
107108
return Tasks.forException(ex);
108109
}
109110
})
110111
.continueWithTask(
111-
checkForUpdateExecutor,
112+
checkForNewReleaseExecutor,
112113
task ->
113114
TaskUtils.handleTaskFailure(
114115
task,
115116
Constants.ErrorMessages.NETWORK_ERROR,
116117
FirebaseAppDistributionException.Status.NETWORK_FAILURE));
117118

118-
return cachedCheckForUpdate;
119+
return cachedCheckForNewRelease;
119120
}
120121

121122
@VisibleForTesting
122-
AppDistributionReleaseInternal getLatestReleaseFromClient(
123+
AppDistributionReleaseInternal getNewReleaseFromClient(
123124
String fid, String appId, String apiKey, String authToken)
124125
throws FirebaseAppDistributionException {
125126
try {
126-
AppDistributionReleaseInternal retrievedLatestRelease =
127-
firebaseAppDistributionTesterApiClient.fetchLatestRelease(fid, appId, apiKey, authToken);
127+
AppDistributionReleaseInternal retrievedNewRelease =
128+
firebaseAppDistributionTesterApiClient.fetchNewRelease(fid, appId, apiKey, authToken);
128129

129-
if (isNewerBuildVersion(retrievedLatestRelease)
130-
|| !isInstalledRelease(retrievedLatestRelease)) {
131-
return retrievedLatestRelease;
130+
if (isNewerBuildVersion(retrievedNewRelease) || !isInstalledRelease(retrievedNewRelease)) {
131+
return retrievedNewRelease;
132132
} else {
133-
// Return null if retrieved latest release is older or currently installed
133+
// Return null if retrieved new release is older or currently installed
134134
return null;
135135
}
136136
} catch (NumberFormatException e) {
137+
LogWrapper.getInstance().e(TAG + "Error parsing buildVersion.", e);
137138
throw new FirebaseAppDistributionException(
138139
Constants.ErrorMessages.NETWORK_ERROR,
139140
FirebaseAppDistributionException.Status.NETWORK_FAILURE,
140141
e);
141142
}
142143
}
143144

144-
private boolean isNewerBuildVersion(AppDistributionReleaseInternal latestRelease)
145+
private boolean isNewerBuildVersion(AppDistributionReleaseInternal newRelease)
145146
throws FirebaseAppDistributionException {
146-
return Long.parseLong(latestRelease.getBuildVersion())
147+
return Long.parseLong(newRelease.getBuildVersion())
147148
> getInstalledAppVersionCode(firebaseApp.getApplicationContext());
148149
}
149150

150151
@VisibleForTesting
151-
boolean isInstalledRelease(AppDistributionReleaseInternal latestRelease) {
152-
if (latestRelease.getBinaryType().equals(BinaryType.APK)) {
153-
return hasSameCodeHashAsInstallledRelease(latestRelease);
152+
boolean isInstalledRelease(AppDistributionReleaseInternal newRelease) {
153+
if (newRelease.getBinaryType().equals(BinaryType.APK)) {
154+
return hasSameCodeHashAsInstallledRelease(newRelease);
154155
}
155156

156-
if (latestRelease.getIasArtifactId() == null) {
157+
if (newRelease.getIasArtifactId() == null) {
157158
return false;
158159
}
159160
// AAB BinaryType
160-
return latestRelease
161+
return newRelease
161162
.getIasArtifactId()
162163
.equals(
163164
ReleaseIdentificationUtils.extractInternalAppSharingArtifactId(
@@ -169,6 +170,7 @@ private long getInstalledAppVersionCode(Context context) throws FirebaseAppDistr
169170
try {
170171
pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
171172
} catch (PackageManager.NameNotFoundException e) {
173+
LogWrapper.getInstance().e(TAG + "Unable to locate Firebase App.", e);
172174
throw new FirebaseAppDistributionException(
173175
Constants.ErrorMessages.UNKNOWN_ERROR,
174176
FirebaseAppDistributionException.Status.UNKNOWN,
@@ -190,7 +192,7 @@ String extractApkCodeHash(PackageInfo packageInfo) {
190192
return releaseIdentifierStorage.getExternalCodeHash(cachedCodeHashes.get(key));
191193
}
192194

193-
private boolean hasSameCodeHashAsInstallledRelease(AppDistributionReleaseInternal latestRelease) {
195+
private boolean hasSameCodeHashAsInstallledRelease(AppDistributionReleaseInternal newRelease) {
194196
try {
195197
Context context = firebaseApp.getApplicationContext();
196198
PackageInfo metadataPackageInfo =
@@ -204,10 +206,11 @@ private boolean hasSameCodeHashAsInstallledRelease(AppDistributionReleaseInterna
204206
return false;
205207
}
206208

207-
// If the codeHash for the retrieved latestRelease is equal to the stored codeHash
209+
// If the codeHash for the retrieved newRelease is equal to the stored codeHash
208210
// of the installed release, then they are the same release.
209-
return externalCodeHash.equals(latestRelease.getCodeHash());
211+
return externalCodeHash.equals(newRelease.getCodeHash());
210212
} catch (PackageManager.NameNotFoundException e) {
213+
LogWrapper.getInstance().e(TAG + "Unable to locate App.", e);
211214
return false;
212215
}
213216
}

0 commit comments

Comments
 (0)