Skip to content

Commit 41ad413

Browse files
authored
Upgrade robolectric and target api 29. (#1469)
* Upgrade robolectric and target api 29. * Fix tests. * Fix * Fixes * Fix groovy issues for jdk11 * Add missed android sdk versions
1 parent 8908ccf commit 41ad413

File tree

24 files changed

+93
-47
lines changed

24 files changed

+93
-47
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ext {
5050
errorproneVersion = '2.3.2'
5151
errorproneJavacVersion = '9+181-r4173-1'
5252
googleTruthVersion = '0.45'
53-
robolectricVersion = '4.1'
53+
robolectricVersion = '4.3.1'
5454
}
5555

5656
apply plugin: com.google.firebase.gradle.plugins.publish.PublishingPlugin
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2020 Google LLC
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+
package com.google.firebase.gradle.plugins;
16+
17+
import groovy.lang.Closure;
18+
import java.util.function.Consumer;
19+
20+
public final class ClosureUtil {
21+
22+
private static final Object FAKE_THIS = new Object();
23+
24+
private ClosureUtil() {}
25+
26+
/** Create a groovy closure backed by a lambda. */
27+
public static <T> Closure<T> closureOf(Consumer<T> action) {
28+
return new Closure<T>(FAKE_THIS) {
29+
void doCall(T t) {
30+
action.accept(t);
31+
}
32+
};
33+
}
34+
}

buildSrc/src/main/groovy/com/google/firebase/gradle/plugins/FirebaseLibraryPlugin.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.gradle.plugins;
1616

17+
import static com.google.firebase.gradle.plugins.ClosureUtil.closureOf;
18+
1719
import com.android.build.gradle.LibraryExtension;
1820
import com.android.build.gradle.api.AndroidSourceSet;
1921
import com.google.common.collect.ImmutableList;
@@ -51,6 +53,20 @@ public void apply(Project project) {
5153
.getByName("release")
5254
.setSigningConfig(types.getByName("debug").getSigningConfig()));
5355

56+
// see https://github.com/robolectric/robolectric/issues/5456
57+
android.testOptions(
58+
options ->
59+
options
60+
.getUnitTests()
61+
.all(
62+
closureOf(
63+
test -> {
64+
test.systemProperty("robolectric.dependency.repo.id", "central");
65+
test.systemProperty(
66+
"robolectric.dependency.repo.url", "https://repo1.maven.org/maven2");
67+
test.systemProperty("javax.net.ssl.trustStoreType", "JKS");
68+
})));
69+
5470
// skip debug tests in CI
5571
// TODO(vkryachko): provide ability for teams to control this if needed
5672
if (System.getenv().containsKey("FIREBASE_CI")) {

buildSrc/src/test/groovy/com/google/firebase/gradle/plugins/license/LicenseResolverPluginSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LicenseResolverPluginSpec extends Specification {
2929
@Rule TemporaryFolder testProjectDir = new TemporaryFolder()
3030
File buildFile
3131

32-
final String buildConfig = """
32+
String buildConfig = """
3333
buildscript {
3434
repositories {
3535
google()

buildSrc/src/test/groovy/com/google/firebase/gradle/plugins/publish/PublishingPluginSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class PublishingPluginSpec extends Specification {
8989

9090
List<Project> subprojects = []
9191

92-
final String rootProject = """
92+
String rootProject = """
9393
buildscript {
9494
repositories {
9595
google()

firebase-abt/firebase-abt.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ dependencies {
9191
testImplementation 'com.google.truth:truth:0.44'
9292
testImplementation 'junit:junit:4.13-beta-2'
9393
testImplementation 'androidx.test:runner:1.2.0'
94-
testImplementation 'org.robolectric:robolectric:4.2'
94+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
9595
testImplementation 'io.grpc:grpc-testing:1.12.0'
9696
testImplementation 'androidx.test.espresso:espresso-core:3.2.0'
9797

firebase-config/bandwagoner/bandwagoner.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ apply plugin: 'com.android.application'
1818
apply plugin: com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin
1919

2020
android {
21-
compileSdkVersion 28
21+
compileSdkVersion project.targetSdkVersion
2222
lintOptions {
2323
abortOnError false
2424
}
@@ -27,7 +27,7 @@ android {
2727
defaultConfig {
2828
applicationId "com.googletest.firebase.remoteconfig.bandwagoner"
2929
minSdkVersion 16
30-
targetSdkVersion 28
30+
targetSdkVersion project.targetSdkVersion
3131
versionCode 1
3232
versionName "1.0"
3333
multiDexEnabled true

firebase-config/firebase-config.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ dependencies {
9797
testImplementation 'org.mockito:mockito-core:2.25.0'
9898
testImplementation 'com.google.truth:truth:0.44'
9999
testImplementation 'junit:junit:4.12'
100-
testImplementation 'org.robolectric:robolectric:4.2'
100+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
101101
testImplementation "org.skyscreamer:jsonassert:1.5.0"
102102

103103
androidTestImplementation 'androidx.test:runner:1.2.0'

firebase-crashlytics-ndk/firebase-crashlytics-ndk.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@ firebaseLibrary {
2121
publishJavadoc = false
2222
}
2323

24-
def androidVersion = 28
25-
2624
android {
2725
adbOptions {
2826
timeOutInMs 60 * 1000
2927
}
3028

31-
compileSdkVersion androidVersion
29+
compileSdkVersion project.targetSdkVersion
3230
defaultConfig {
3331
minSdkVersion 16
34-
targetSdkVersion androidVersion
32+
targetSdkVersion project.targetSdkVersion
3533
versionName version
3634

3735
consumerProguardFiles 'firebase-crashlytics-ndk-proguard.txt'
@@ -63,7 +61,7 @@ dependencies {
6361
implementation 'com.google.android.gms:play-services-basement:17.0.0'
6462

6563
testImplementation 'androidx.test:runner:1.2.0'
66-
testImplementation 'org.robolectric:robolectric:4.2'
64+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
6765
testImplementation 'junit:junit:4.12'
6866
testImplementation 'org.mockito:mockito-core:1.10.19'
6967

firebase-crashlytics/firebase-crashlytics.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@ firebaseLibrary {
2020
testLab.enabled = true
2121
}
2222

23-
def androidVersion = 28
24-
2523
android {
2624
adbOptions {
2725
timeOutInMs 60 * 1000
2826
}
2927

30-
compileSdkVersion androidVersion
28+
compileSdkVersion project.targetSdkVersion
3129
defaultConfig {
3230
minSdkVersion 16
33-
targetSdkVersion androidVersion
31+
targetSdkVersion project.targetSdkVersion
3432
versionName version
3533

3634
multiDexEnabled true
@@ -72,7 +70,7 @@ dependencies {
7270
annotationProcessor 'com.google.auto.value:auto-value:1.6.5'
7371

7472
testImplementation 'androidx.test:runner:1.2.0'
75-
testImplementation 'org.robolectric:robolectric:4.2'
73+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
7674
testImplementation 'junit:junit:4.12'
7775
testImplementation 'org.mockito:mockito-core:1.10.19'
7876

firebase-database/src/main/java/com/google/firebase/database/tubesock/WebSocket.java

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

1515
package com.google.firebase.database.tubesock;
1616

17-
import android.net.SSLCertificateSocketFactory;
1817
import android.net.SSLSessionCache;
1918
import androidx.annotation.Nullable;
2019
import com.google.firebase.database.connection.ConnectionContext;
@@ -314,8 +313,10 @@ private Socket createSocket() {
314313
logger.debug("Failed to initialize SSL session cache", e);
315314
}
316315
try {
316+
@SuppressWarnings("deprecation")
317317
SocketFactory factory =
318-
SSLCertificateSocketFactory.getDefault(SSL_HANDSHAKE_TIMEOUT_MS, sessionCache);
318+
android.net.SSLCertificateSocketFactory.getDefault(
319+
SSL_HANDSHAKE_TIMEOUT_MS, sessionCache);
319320
SSLSocket sslSocket = (SSLSocket) factory.createSocket(host, port);
320321
// TODO: the default hostname verifier on the JVM always returns false.
321322
// For the JVM we will need a different solution.

firebase-firestore/firebase-firestore.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ dependencies {
140140
testImplementation 'junit:junit:4.12'
141141
testImplementation 'androidx.test:core:1.2.0'
142142
testImplementation 'org.mockito:mockito-core:2.25.0'
143-
testImplementation ('org.robolectric:robolectric:4.2') {
143+
testImplementation ("org.robolectric:robolectric:$robolectricVersion") {
144144
exclude group: 'com.google.protobuf', module: 'protobuf-java'
145145
}
146146
testImplementation "com.google.truth:truth:$googleTruthVersion"

firebase-firestore/ktx/ktx.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ firebaseLibrary {
2323
}
2424

2525
android {
26-
compileSdkVersion 28
26+
compileSdkVersion project.targetSdkVersion
2727
defaultConfig {
2828
minSdkVersion project.minSdkVersion
2929
multiDexEnabled true

firebase-firestore/src/main/java/com/google/firebase/firestore/remote/AndroidConnectivityMonitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import android.content.IntentFilter;
2424
import android.net.ConnectivityManager;
2525
import android.net.Network;
26-
import android.net.NetworkInfo;
2726
import android.os.Build;
2827
import androidx.annotation.Nullable;
2928
import com.google.firebase.firestore.util.Consumer;
@@ -124,10 +123,11 @@ private class NetworkReceiver extends BroadcastReceiver {
124123
private boolean isConnected = false;
125124

126125
@Override
126+
@SuppressWarnings("deprecation")
127127
public void onReceive(Context context, Intent intent) {
128128
ConnectivityManager conn =
129129
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
130-
NetworkInfo networkInfo = conn.getActiveNetworkInfo();
130+
android.net.NetworkInfo networkInfo = conn.getActiveNetworkInfo();
131131
boolean wasConnected = isConnected;
132132
isConnected = networkInfo != null && networkInfo.isConnected();
133133
if (isConnected && !wasConnected) {

firebase-inappmessaging-display/firebase-inappmessaging-display.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ dependencies {
8888
annotationProcessor 'com.google.auto.value:auto-value:1.6.5'
8989
annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.6'
9090

91-
testImplementation "org.robolectric:robolectric:4.2"
91+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
9292
testImplementation "junit:junit:4.12"
9393
testImplementation "org.mockito:mockito-core:2.25.0"
9494
testImplementation "com.google.truth:truth:1.0"

firebase-inappmessaging-display/ktx/ktx.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ android {
3838
srcDir 'src/test/kotlin'
3939
}
4040
}
41+
4142
testOptions.unitTests.includeAndroidResources = true
4243
}
4344

firebase-inappmessaging/firebase-inappmessaging.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ dependencies {
144144
testImplementation "com.google.truth:truth:$googleTruthVersion"
145145
testImplementation 'junit:junit:4.12'
146146
testImplementation 'androidx.test:runner:1.2.0'
147-
testImplementation ('org.robolectric:robolectric:4.2') {
147+
testImplementation ("org.robolectric:robolectric:$robolectricVersion") {
148148
exclude group: 'com.google.protobuf', module: 'protobuf-java'
149149
}
150150
testImplementation 'io.grpc:grpc-testing:1.21.0'

firebase-storage/src/main/java/com/google/firebase/storage/network/NetworkRequest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import android.content.pm.PackageInfo;
1919
import android.content.pm.PackageManager;
2020
import android.net.ConnectivityManager;
21-
import android.net.NetworkInfo;
2221
import android.net.Uri;
2322
import android.text.TextUtils;
2423
import android.util.Log;
@@ -224,6 +223,7 @@ public JSONObject getResultBody() {
224223
return resultBody;
225224
}
226225

226+
@SuppressWarnings("deprecation")
227227
public void performRequestStart(String token) {
228228
if (mException != null) {
229229
resultCode = INITIALIZATION_EXCEPTION;
@@ -235,7 +235,7 @@ public void performRequestStart(String token) {
235235
}
236236
ConnectivityManager connMgr =
237237
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
238-
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
238+
android.net.NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
239239
if (networkInfo == null || !networkInfo.isConnected()) {
240240
resultCode = NETWORK_UNAVAILABLE;
241241
mException = new SocketException("Network subsystem is unavailable");
@@ -286,10 +286,11 @@ public void performRequest(@Nullable String authToken, @NonNull Context applicat
286286
performRequest(authToken);
287287
}
288288

289+
@SuppressWarnings("deprecation")
289290
private boolean ensureNetworkAvailable(Context context) {
290291
ConnectivityManager connMgr =
291292
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
292-
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
293+
android.net.NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
293294
if (networkInfo == null || !networkInfo.isConnected()) {
294295
mException = new SocketException("Network subsystem is unavailable");
295296
resultCode = NETWORK_UNAVAILABLE;

sdkProperties.gradle

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

1515
ext {
16-
targetSdkVersion = 28
16+
targetSdkVersion = 29
1717
minSdkVersion = 14
1818
}

smoke-tests/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ buildscript {
3131
apply plugin: "com.android.application"
3232

3333
android {
34-
compileSdkVersion 28
34+
compileSdkVersion 29
3535

3636
defaultConfig {
3737
minSdkVersion 16

tools/errorprone/errorprone.gradle

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,5 @@ dependencies {
2222

2323
testImplementation 'junit:junit:4.12'
2424
testImplementation 'com.google.errorprone:error_prone_test_helpers:2.3.3'
25-
testCompile 'com.google.errorprone:javac:9+181-r4173-1'
26-
}
27-
28-
29-
test {
30-
jvmArgs "-Xbootclasspath/p:${-> project.configurations.testCompile.find { it.name.startsWith("javac-") }}"
25+
testImplementation 'com.google.errorprone:javac:9+181-r4173-1'
3126
}

transport/transport-api/transport-api.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ firebaseLibrary{
2121
}
2222

2323
android {
24-
compileSdkVersion 28
24+
compileSdkVersion project.targetSdkVersion
2525
defaultConfig {
2626
minSdkVersion 14
27-
targetSdkVersion 28
27+
targetSdkVersion project.targetSdkVersion
2828
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2929
}
3030

transport/transport-backend-cct/transport-backend-cct.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ protobuf {
3737
}
3838

3939
android {
40-
compileSdkVersion 28
40+
compileSdkVersion project.targetSdkVersion
4141
defaultConfig {
42-
minSdkVersion 14
43-
targetSdkVersion 28
42+
minSdkVersion project.minSdkVersion
43+
targetSdkVersion project.targetSdkVersion
4444
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
4545
versionName version
4646
}
@@ -70,7 +70,7 @@ dependencies {
7070
testImplementation 'com.github.tomakehurst:wiremock:2.26.3'
7171
//Android compatible version of Apache httpclient.
7272
testImplementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
73-
testImplementation 'org.robolectric:robolectric:4.3.1'
73+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
7474
testImplementation 'junit:junit:4.13-beta-2'
7575

7676
androidTestImplementation 'androidx.test:runner:1.2.0'

0 commit comments

Comments
 (0)