diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 00000000..81bae9ac --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,7 @@ +version: 2 + +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000..0b1c97d9 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,30 @@ +name: build + +on: + pull_request: {} + push: + branches: + - '**' + tags-ignore: + - '**' + +jobs: + build: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v3 + - uses: gradle/wrapper-validation-action@v1.0.5 + + - uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 8 + + - run: ./gradlew build + + - run: ./gradlew publish + if: ${{ github.ref == 'refs/heads/3.x' && github.repository == 'ReactiveX/RxAndroid' }} + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USER }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }} diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml deleted file mode 100644 index 405a2b30..00000000 --- a/.github/workflows/gradle-wrapper-validation.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: "Validate Gradle Wrapper" -on: [push, pull_request] - -jobs: - validation: - name: "Validation" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: gradle/wrapper-validation-action@v1 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..ec930f17 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,26 @@ +name: release + +on: + push: + tags: + - '**' + +jobs: + release: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v3 + - uses: gradle/wrapper-validation-action@v1.0.5 + + - uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 8 + + - run: ./gradlew publish + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USER }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }} + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_PRIVATE_KEY }} + ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }} diff --git a/.gitignore b/.gitignore index bf530e2d..e287a917 100644 --- a/.gitignore +++ b/.gitignore @@ -1,70 +1,10 @@ -# Compiled source # -################### -*.class - -# Packages # -############ -# it's better to unpack these files and commit the raw source -# git has its own built in compression methods -*.7z -*.dmg -*.gz -*.iso -*.rar -*.tar -*.zip - -# Logs and databases # -###################### -*.log - -# OS generated files # -###################### -.DS_Store* -ehthumbs.db -Icon? -Thumbs.db - -# Editor Files # -################ -*~ -*.swp - -# Gradle Files # -################ +# Gradle .gradle -.gradletasknamecache -.m2 - -# Build output directies -target/ -build/ +build +reports -# IntelliJ specific files/directories -out +# IntelliJ .idea -*.ipr -*.iws -*.iml -atlassian-ide-plugin.xml - -# AndroidStudio specific files/directories -local.properties - -# Eclipse specific files/directories -.classpath -.project -.settings -.metadata -bin/ - -# NetBeans specific files/directories -.nbattrs -/.nb-gradle/profiles/private/ -.nb-gradle-properties # Android local.properties - -# jEnv -.java-version diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0e9bea9d..00000000 --- a/.travis.yml +++ /dev/null @@ -1,39 +0,0 @@ -language: android - -android: - components: - - tools - - platform-tools - -jdk: - - oraclejdk8 - -# as per http://blog.travis-ci.com/2014-12-17-faster-builds-with-container-based-infrastructure/ -sudo: false - -before_install: - # Install SDK license so Android Gradle plugin can install deps. - - mkdir "$ANDROID_HOME/licenses" || true - - echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license" - - echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> "$ANDROID_HOME/licenses/android-sdk-license" - - echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" >> "$ANDROID_HOME/licenses/android-sdk-license" - -# script for build and release via Travis to Bintray -script: gradle/buildViaTravis.sh - -notifications: - email: false - -# cache between builds -cache: - directories: - - $HOME/.m2 - - $HOME/.gradle - -# credential for release -env: - global: - - secure: mQwFIdOIooeZ1KkDhkhXdSORA3Tn713C7SYYaF/ZWhhhINHvwMjPAOT+R7zSyGGqjhpqklRbKmZXDJHGPdus1q5CvZLYvldeQXsEfzvav95aukHjNbOIa3y/5h1rZWXwTLR13aMv/o87SrTT2xiyE6XgxFxN3eSsu/zavrQGQkM= - - secure: hKrGR9YZ2At9vktZRhmkwPK82u8wDHgHPWoxbIE629/oY7WbbRvsmVnXp5ontLd4RJJwnN1ujf2hlr/H7ZioUoIbln0qqX3e399IWLg5OhUdTJVpeAVCenVoNa53p/YCMeo/aE9JWK1oM4AXvIBt8vgZUpCPTfVgsbzF2BACfoY= - - secure: GJc0t6x9GdPO2EfMTCQP+UU1P9nvxsGkbrtvaNWocHP5BU/X3pcC1CEN6iiXsaYUrhYngOw7jMi3uPgKA8c+FRbnyqhkNubWY0WkChK4vrymjIkTPDMbLELVJoYLsJFZXY8+8wJLJa3D11ShcHAC3K68KGVBVlRqBBv2UidtFjY= - - secure: lC5Z9+kBmU3MWhmdjIJqQ8vS5QnTm7vepzDRAJH0K3apwaAUx/iZwrLa8XveA05XBim4jga+VHMHAVILilacvxK8T1L01JkYhhMC8ii3ye/HP5Pwy66dPdvl8VaS0vnC3DkB1i7JGv5h0Vx8RcWyJ77qpLjUFsW6db7/3x8pKpo= diff --git a/build.gradle b/build.gradle index d94b3aad..0b9d27f8 100644 --- a/build.gradle +++ b/build.gradle @@ -2,13 +2,10 @@ buildscript { repositories { google() mavenCentral() - jcenter() } dependencies { classpath 'com.android.tools.build:gradle:4.2.2' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5' - classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.7.5' + classpath 'com.vanniktech:gradle-maven-publish-plugin:0.18.0' } } @@ -16,7 +13,15 @@ allprojects { repositories { google() mavenCentral() - jcenter() + } + + tasks.withType(Test).configureEach { + testLogging { + if (System.getenv("CI") == "true") { + events = ["failed", "skipped", "passed"] + } + exceptionFormat "full" + } } } diff --git a/gradle.properties b/gradle.properties index 03331281..a0e28a15 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,17 @@ -android.enableJetifier=false -android.useAndroidX=true org.gradle.jvmargs=-Xmx2048m +android.useAndroidX=true +android.enableJetifier=false +android.defaults.buildfeatures.buildconfig=false +android.defaults.buildfeatures.aidl=false +android.defaults.buildfeatures.renderscript=false +android.defaults.buildfeatures.resvalues=false +android.defaults.buildfeatures.shaders=false + GROUP=io.reactivex.rxjava3 -VERSION_NAME=3.0.1 +VERSION_NAME=3.0.1-SNAPSHOT + POM_NAME=RxAndroid -POM_PACKAGING=aar POM_DESCRIPTION=RxAndroid POM_URL=https://github.com/ReactiveX/RxAndroid @@ -14,5 +20,9 @@ POM_SCM_CONNECTION=scm:git:https://github.com/ReactiveX/RxAndroid.git POM_SCM_DEV_CONNECTION=scm:git:git@github.com:ReactiveX/RxAndroid.git POM_LICENCE_NAME=The Apache Software License, Version 2.0 -POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt +POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt POM_LICENCE_DIST=repo + +POM_DEVELOPER_ID=reactivex +POM_DEVELOPER_NAME=ReactiveX +POM_DEVELOPER_URL=https://github.com/ReactiveX diff --git a/gradle/artifacts.gradle b/gradle/artifacts.gradle deleted file mode 100644 index 6848549a..00000000 --- a/gradle/artifacts.gradle +++ /dev/null @@ -1,68 +0,0 @@ -if (project.plugins.hasPlugin('com.android.library')) { - android.libraryVariants.all { variant -> - Task javadocTask = task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) { - group = 'artifact' - description "Generates Javadoc for $variant.name" - - // Source files from the variant - source = variant.javaCompiler.source - - // Classpath from the variant + android.jar - String androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar" - classpath = variant.javaCompiler.classpath + files(androidJar) - - // The Android online reference doesn't include package-list, so we have to use the local one - String packageListRef = "${android.sdkDirectory}/docs/reference/" - options.linksOffline 'http://d.android.com/reference/', packageListRef - - // Additional links for any RxJava references - options.links 'http://reactivex.io/RxJava/javadoc/' - - // Exclude generated files - exclude '**/BuildConfig.java' - exclude '**/R.java' - - // Output to a unique javadoc folder per variant - destinationDir = new File(project.docsDir, "javadoc-$variant.name") - - if (JavaVersion.current().isJava8Compatible()) { - options.addStringOption('Xdoclint:none', '-quiet') - } - } - - // For official releases, don't prefix the name so the artifact is published correctly - // (Can't seem to modify it for publishing, for whatever reason...) - String classifierPrefix = (variant.name == 'release') ? '' : "$variant.name-" - - Task javadocJarTask = task("generate${variant.name.capitalize()}JavadocJar", type: Jar, dependsOn: javadocTask) { - group = 'artifact' - description = "Generates Javadoc jar for $variant.name" - - classifier = "${classifierPrefix}javadoc" - from javadocTask.destinationDir - } - - Task sourcesJarTask = task("generate${variant.name.capitalize()}SourcesJar", type: Jar) { - group = 'artifact' - description = "Generates sources jar for $variant.name" - - classifier = "${classifierPrefix}sources" - from variant.javaCompiler.source - } - - if (variant.name == 'release') { - // There's a lot of "magic" around the archives configuration; easier - // just to embrace it rather than try to configure around it - artifacts { - archives javadocJarTask, sourcesJarTask - } - } - else { - // Create a configuration we can publish from for each variant - String configurationName = "archives${variant.name.capitalize()}" - configurations.create(configurationName) - artifacts.add configurationName, javadocJarTask - artifacts.add configurationName, sourcesJarTask - } - } -} diff --git a/gradle/buildViaTravis.sh b/gradle/buildViaTravis.sh deleted file mode 100755 index bdd380cf..00000000 --- a/gradle/buildViaTravis.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -# This script will build the project. - -if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then - echo -e "Build Pull Request #$TRAVIS_PULL_REQUEST => Branch [$TRAVIS_BRANCH]" - ./gradlew build -elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" == "" ]; then - echo -e 'Build Branch with Snapshot => Branch ['$TRAVIS_BRANCH']' - ./gradlew -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" build artifactoryPublish --stacktrace --info -elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then - echo -e 'Build Branch for Release => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG']' - ./gradlew -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" build bintrayUpload --stacktrace --info -else - echo -e 'WARN: Should not be here => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG'] Pull Request ['$TRAVIS_PULL_REQUEST']' - ./gradlew build -fi diff --git a/gradlew.bat b/gradlew.bat index ac1b06f9..107acd32 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,89 +1,89 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/rxandroid/build.gradle b/rxandroid/build.gradle index e8bbfa90..d7315d44 100644 --- a/rxandroid/build.gradle +++ b/rxandroid/build.gradle @@ -1,21 +1,5 @@ apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' -apply plugin: 'com.jfrog.bintray' -apply plugin: 'com.jfrog.artifactory' - -group = GROUP - -// Both the artifactory and bintray plugins depend on this singular -// global `version` variable. As such, we need to configure it based -// on which task we're running. -// -// The solution here is brittle; it just checks whether 'bintrayUpload' -// was called for execution, otherwise it assumes SNAPSHOT. If we -// were to wait until the task graph was built, we'd be too late -// (the plugins would already have used `version`). -boolean isReleaseBuild = gradle.startParameter.taskNames.contains('bintrayUpload') -version = isReleaseBuild ? VERSION_NAME : "$VERSION_NAME-SNAPSHOT" -logger.info("RxAndroid using version=$project.version") +apply plugin: 'com.vanniktech.maven.publish' android { compileSdkVersion rootProject.ext.compileSdkVersion @@ -28,11 +12,6 @@ android { sourceCompatibility rootProject.ext.sourceCompatibility targetCompatibility rootProject.ext.sourceCompatibility } - - // TODO replace with https://issuetracker.google.com/issues/72050365 once released. - libraryVariants.all { - it.generateBuildConfig.enabled = false - } } dependencies { @@ -42,96 +21,8 @@ dependencies { testImplementation 'org.robolectric:robolectric:4.2.1' } -// Create source/javadoc artifacts for publishing -apply from: "$rootDir/gradle/artifacts.gradle" - -// Configure android-maven-gradle-plugin -install { - repositories.mavenInstaller.pom.project { - name POM_NAME - description POM_DESCRIPTION - packaging POM_PACKAGING - url POM_URL - - licenses { - license { - name POM_LICENCE_NAME - url POM_LICENCE_URL - distribution POM_LICENCE_DIST - } - } - - scm { - url POM_SCM_URL - connection POM_SCM_CONNECTION - developerConnection POM_SCM_DEV_CONNECTION - } - - developers { - developer { - id 'JakeWharton' - name 'Jake Wharton' - } - developer { - id 'mttkay' - name 'Matthias Käppler' - } - developer { - id 'dlew' - name 'Dan Lew' - } - } - } -} - -// Configure artifactory (for publishing snapshots) -// -// Based on NebulaOJOPublishingPlugin (from nebula-bintray-plugin) -artifactory { - contextUrl = 'https://oss.jfrog.org' - - publish { - repository { - repoKey = 'oss-snapshot-local' - - if (project.hasProperty('bintrayUser')) { - username = project.property('bintrayUser') - password = project.property('bintrayKey') - } - } - - defaults { - publishConfigs('archives') - } - } -} - -// Configure gradle-bintray-plugin (for publishing releases) -bintray { - configurations = ['archives'] - - publish = true - - pkg { - repo = 'RxJava' - name = 'RxAndroid' - userOrg = 'reactivex' - licenses = ['Apache-2.0'] - labels = ['rxjava', 'reactivex'] - websiteUrl = 'https://github.com/ReactiveX/RxAndroid/' - issueTrackerUrl = 'https://github.com/ReactiveX/RxAndroid/issues' - vcsUrl = 'https://github.com/ReactiveX/RxAndroid.git' - } -} - -if (project.hasProperty('bintrayUser') && project.hasProperty('bintrayKey')) { - bintray.user = project.bintrayUser - bintray.key = project.bintrayKey -} - -if (project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')) { - def sync = bintray.pkg.version.mavenCentralSync - sync.sync = true - sync.user = project.sonatypeUsername - sync.password = project.sonatypePassword +signing { + def signingKey = findProperty('signingKey') + def signingPassword = findProperty('signingPassword') + useInMemoryPgpKeys(signingKey, signingPassword) } diff --git a/rxandroid/src/test/java/io/reactivex/rxjava3/android/schedulers/AndroidSchedulersTest.java b/rxandroid/src/test/java/io/reactivex/rxjava3/android/schedulers/AndroidSchedulersTest.java index ce0af5f1..73cd0b3a 100644 --- a/rxandroid/src/test/java/io/reactivex/rxjava3/android/schedulers/AndroidSchedulersTest.java +++ b/rxandroid/src/test/java/io/reactivex/rxjava3/android/schedulers/AndroidSchedulersTest.java @@ -127,19 +127,23 @@ public void fromAsyncMessagesByDefault() { @Test public void asyncIgnoredPre16() { + int oldValue = Build.VERSION.SDK_INT; ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 14); - - ShadowLooper mainLooper = shadowOf(Looper.getMainLooper()); - mainLooper.pause(); - ShadowMessageQueue mainMessageQueue = shadowOf(Looper.getMainLooper().getQueue()); - - Scheduler main = AndroidSchedulers.from(Looper.getMainLooper(), true); - main.scheduleDirect(new Runnable() { - @Override public void run() { - } - }); - - Message message = mainMessageQueue.getHead(); - assertFalse(message.isAsynchronous()); + try { + ShadowLooper mainLooper = shadowOf(Looper.getMainLooper()); + mainLooper.pause(); + ShadowMessageQueue mainMessageQueue = shadowOf(Looper.getMainLooper().getQueue()); + + Scheduler main = AndroidSchedulers.from(Looper.getMainLooper(), true); + main.scheduleDirect(new Runnable() { + @Override public void run() { + } + }); + + Message message = mainMessageQueue.getHead(); + assertFalse(message.isAsynchronous()); + } finally { + ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", oldValue); + } } }