Skip to content

Upgrade robolectric and target api 29. #1469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ext {
errorproneVersion = '2.3.2'
errorproneJavacVersion = '9+181-r4173-1'
googleTruthVersion = '0.45'
robolectricVersion = '4.1'
robolectricVersion = '4.3.1'
}

apply plugin: com.google.firebase.gradle.plugins.publish.PublishingPlugin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.firebase.gradle.plugins;

import groovy.lang.Closure;
import java.util.function.Consumer;

public final class ClosureUtil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can You help understand what this does?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to express the following in java(this api is not java-friendly):

android.testOptions.unitTests.all {
 // this is a groovy closure that is hard to implement in java, hence this util class
}


private static final Object FAKE_THIS = new Object();

private ClosureUtil() {}

/** Create a groovy closure backed by a lambda. */
public static <T> Closure<T> closureOf(Consumer<T> action) {
return new Closure<T>(FAKE_THIS) {
void doCall(T t) {
action.accept(t);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.google.firebase.gradle.plugins;

import static com.google.firebase.gradle.plugins.ClosureUtil.closureOf;

import com.android.build.gradle.LibraryExtension;
import com.android.build.gradle.api.AndroidSourceSet;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -51,6 +53,20 @@ public void apply(Project project) {
.getByName("release")
.setSigningConfig(types.getByName("debug").getSigningConfig()));

// see https://github.com/robolectric/robolectric/issues/5456
android.testOptions(
options ->
options
.getUnitTests()
.all(
closureOf(
test -> {
test.systemProperty("robolectric.dependency.repo.id", "central");
test.systemProperty(
"robolectric.dependency.repo.url", "https://repo1.maven.org/maven2");
test.systemProperty("javax.net.ssl.trustStoreType", "JKS");
})));

// skip debug tests in CI
// TODO(vkryachko): provide ability for teams to control this if needed
if (System.getenv().containsKey("FIREBASE_CI")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LicenseResolverPluginSpec extends Specification {
@Rule TemporaryFolder testProjectDir = new TemporaryFolder()
File buildFile

final String buildConfig = """
String buildConfig = """
buildscript {
repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class PublishingPluginSpec extends Specification {

List<Project> subprojects = []

final String rootProject = """
String rootProject = """
buildscript {
repositories {
google()
Expand Down
2 changes: 1 addition & 1 deletion firebase-abt/firebase-abt.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ dependencies {
testImplementation 'com.google.truth:truth:0.44'
testImplementation 'junit:junit:4.13-beta-2'
testImplementation 'androidx.test:runner:1.2.0'
testImplementation 'org.robolectric:robolectric:4.2'
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation 'io.grpc:grpc-testing:1.12.0'
testImplementation 'androidx.test.espresso:espresso-core:3.2.0'

Expand Down
4 changes: 2 additions & 2 deletions firebase-config/bandwagoner/bandwagoner.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ apply plugin: 'com.android.application'
apply plugin: com.google.firebase.gradle.plugins.ci.device.FirebaseTestLabPlugin

android {
compileSdkVersion 28
compileSdkVersion project.targetSdkVersion
lintOptions {
abortOnError false
}
Expand All @@ -27,7 +27,7 @@ android {
defaultConfig {
applicationId "com.googletest.firebase.remoteconfig.bandwagoner"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion project.targetSdkVersion
versionCode 1
versionName "1.0"
multiDexEnabled true
Expand Down
2 changes: 1 addition & 1 deletion firebase-config/firebase-config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ dependencies {
testImplementation 'org.mockito:mockito-core:2.25.0'
testImplementation 'com.google.truth:truth:0.44'
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.2'
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation "org.skyscreamer:jsonassert:1.5.0"

androidTestImplementation 'androidx.test:runner:1.2.0'
Expand Down
8 changes: 3 additions & 5 deletions firebase-crashlytics-ndk/firebase-crashlytics-ndk.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ firebaseLibrary {
publishJavadoc = false
}

def androidVersion = 28

android {
adbOptions {
timeOutInMs 60 * 1000
}

compileSdkVersion androidVersion
compileSdkVersion project.targetSdkVersion
defaultConfig {
minSdkVersion 16
targetSdkVersion androidVersion
targetSdkVersion project.targetSdkVersion
versionName version

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

testImplementation 'androidx.test:runner:1.2.0'
testImplementation 'org.robolectric:robolectric:4.2'
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'

Expand Down
8 changes: 3 additions & 5 deletions firebase-crashlytics/firebase-crashlytics.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ firebaseLibrary {
testLab.enabled = true
}

def androidVersion = 28

android {
adbOptions {
timeOutInMs 60 * 1000
}

compileSdkVersion androidVersion
compileSdkVersion project.targetSdkVersion
defaultConfig {
minSdkVersion 16
targetSdkVersion androidVersion
targetSdkVersion project.targetSdkVersion
versionName version

multiDexEnabled true
Expand Down Expand Up @@ -72,7 +70,7 @@ dependencies {
annotationProcessor 'com.google.auto.value:auto-value:1.6.5'

testImplementation 'androidx.test:runner:1.2.0'
testImplementation 'org.robolectric:robolectric:4.2'
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.google.firebase.database.tubesock;

import android.net.SSLCertificateSocketFactory;
import android.net.SSLSessionCache;
import androidx.annotation.Nullable;
import com.google.firebase.database.connection.ConnectionContext;
Expand Down Expand Up @@ -314,8 +313,10 @@ private Socket createSocket() {
logger.debug("Failed to initialize SSL session cache", e);
}
try {
@SuppressWarnings("deprecation")
SocketFactory factory =
SSLCertificateSocketFactory.getDefault(SSL_HANDSHAKE_TIMEOUT_MS, sessionCache);
android.net.SSLCertificateSocketFactory.getDefault(
SSL_HANDSHAKE_TIMEOUT_MS, sessionCache);
SSLSocket sslSocket = (SSLSocket) factory.createSocket(host, port);
// TODO: the default hostname verifier on the JVM always returns false.
// For the JVM we will need a different solution.
Expand Down
2 changes: 1 addition & 1 deletion firebase-firestore/firebase-firestore.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test:core:1.2.0'
testImplementation 'org.mockito:mockito-core:2.25.0'
testImplementation ('org.robolectric:robolectric:4.2') {
testImplementation ("org.robolectric:robolectric:$robolectricVersion") {
exclude group: 'com.google.protobuf', module: 'protobuf-java'
}
testImplementation "com.google.truth:truth:$googleTruthVersion"
Expand Down
2 changes: 1 addition & 1 deletion firebase-firestore/ktx/ktx.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ firebaseLibrary {
}

android {
compileSdkVersion 28
compileSdkVersion project.targetSdkVersion
defaultConfig {
minSdkVersion project.minSdkVersion
multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkInfo;
import android.os.Build;
import androidx.annotation.Nullable;
import com.google.firebase.firestore.util.Consumer;
Expand Down Expand Up @@ -124,10 +123,11 @@ private class NetworkReceiver extends BroadcastReceiver {
private boolean isConnected = false;

@Override
@SuppressWarnings("deprecation")
public void onReceive(Context context, Intent intent) {
ConnectivityManager conn =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = conn.getActiveNetworkInfo();
android.net.NetworkInfo networkInfo = conn.getActiveNetworkInfo();
boolean wasConnected = isConnected;
isConnected = networkInfo != null && networkInfo.isConnected();
if (isConnected && !wasConnected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ dependencies {
annotationProcessor 'com.google.auto.value:auto-value:1.6.5'
annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.6'

testImplementation "org.robolectric:robolectric:4.2"
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation "junit:junit:4.12"
testImplementation "org.mockito:mockito-core:2.25.0"
testImplementation "com.google.truth:truth:1.0"
Expand Down
1 change: 1 addition & 0 deletions firebase-inappmessaging-display/ktx/ktx.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ android {
srcDir 'src/test/kotlin'
}
}

testOptions.unitTests.includeAndroidResources = true
}

Expand Down
2 changes: 1 addition & 1 deletion firebase-inappmessaging/firebase-inappmessaging.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ dependencies {
testImplementation "com.google.truth:truth:$googleTruthVersion"
testImplementation 'junit:junit:4.12'
testImplementation 'androidx.test:runner:1.2.0'
testImplementation ('org.robolectric:robolectric:4.2') {
testImplementation ("org.robolectric:robolectric:$robolectricVersion") {
exclude group: 'com.google.protobuf', module: 'protobuf-java'
}
testImplementation 'io.grpc:grpc-testing:1.21.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
Expand Down Expand Up @@ -224,6 +223,7 @@ public JSONObject getResultBody() {
return resultBody;
}

@SuppressWarnings("deprecation")
public void performRequestStart(String token) {
if (mException != null) {
resultCode = INITIALIZATION_EXCEPTION;
Expand All @@ -235,7 +235,7 @@ public void performRequestStart(String token) {
}
ConnectivityManager connMgr =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
android.net.NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isConnected()) {
resultCode = NETWORK_UNAVAILABLE;
mException = new SocketException("Network subsystem is unavailable");
Expand Down Expand Up @@ -286,10 +286,11 @@ public void performRequest(@Nullable String authToken, @NonNull Context applicat
performRequest(authToken);
}

@SuppressWarnings("deprecation")
private boolean ensureNetworkAvailable(Context context) {
ConnectivityManager connMgr =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
android.net.NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isConnected()) {
mException = new SocketException("Network subsystem is unavailable");
resultCode = NETWORK_UNAVAILABLE;
Expand Down
2 changes: 1 addition & 1 deletion sdkProperties.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
// limitations under the License.

ext {
targetSdkVersion = 28
targetSdkVersion = 29
minSdkVersion = 14
}
2 changes: 1 addition & 1 deletion smoke-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ buildscript {
apply plugin: "com.android.application"

android {
compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
minSdkVersion 16
Expand Down
7 changes: 1 addition & 6 deletions tools/errorprone/errorprone.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,5 @@ dependencies {

testImplementation 'junit:junit:4.12'
testImplementation 'com.google.errorprone:error_prone_test_helpers:2.3.3'
testCompile 'com.google.errorprone:javac:9+181-r4173-1'
}


test {
jvmArgs "-Xbootclasspath/p:${-> project.configurations.testCompile.find { it.name.startsWith("javac-") }}"
testImplementation 'com.google.errorprone:javac:9+181-r4173-1'
}
4 changes: 2 additions & 2 deletions transport/transport-api/transport-api.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ firebaseLibrary{
}

android {
compileSdkVersion 28
compileSdkVersion project.targetSdkVersion
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
targetSdkVersion project.targetSdkVersion
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
8 changes: 4 additions & 4 deletions transport/transport-backend-cct/transport-backend-cct.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ protobuf {
}

android {
compileSdkVersion 28
compileSdkVersion project.targetSdkVersion
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
minSdkVersion project.minSdkVersion
targetSdkVersion project.targetSdkVersion
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
versionName version
}
Expand Down Expand Up @@ -70,7 +70,7 @@ dependencies {
testImplementation 'com.github.tomakehurst:wiremock:2.26.3'
//Android compatible version of Apache httpclient.
testImplementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
testImplementation 'org.robolectric:robolectric:4.3.1'
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation 'junit:junit:4.13-beta-2'

androidTestImplementation 'androidx.test:runner:1.2.0'
Expand Down
Loading