Skip to content

Commit

Permalink
Bump libraries to the latest version, this fixes a binary incompatibi…
Browse files Browse the repository at this point in the history
…lity with `WorkManager`, see #591
  • Loading branch information
vRallev committed Oct 9, 2019
1 parent 3437936 commit 754db63
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.4.2 (2019-10-09)
* Bump libraries to the latest version, this fixes a binary incompatibility with `WorkManager`, see #591

## 1.4.1 (2019-09-30)
* Remove appcompat as dependency, which was accidentally added in 1.4.0.

Expand Down
27 changes: 23 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.25.0'
}
}
Expand All @@ -28,16 +28,35 @@ ext {

buildToolsVersion = '29.0.2'

androidXLibVersion = '1.0.1'
playServicesVersion = '16.1.0'
workVersion = '2.0.1'
androidXLibVersion = '1.1.0'
playServicesVersion = '17.0.0'
workVersion = '2.2.0'
stethoVersion = '1.5.0'
junitVersion = '4.12'
assertjVersion = '3.6.2'
mockitoVersion = '2.7.22'
robolectricVersion = '4.3'
}

allprojects {
configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'androidx.arch.core'
&& details.requested.name.contains('core-common')) {
details.useVersion '2.0.1'
}
if (details.requested.group == 'androidx.collection'
&& details.requested.name.contains('collection')) {
details.useVersion '1.0.0'
}
if (details.requested.group == 'androidx.lifecycle'
&& details.requested.name.contains('lifecycle-runtime')) {
details.useVersion '2.0.0'
}
}
}
}

task updateWrapper(type: Wrapper) {
gradleVersion = '5.6.2'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies {
testImplementation "org.mockito:mockito-core:$mockitoVersion"
testImplementation "org.assertj:assertj-core:$assertjVersion"
testImplementation "org.robolectric:robolectric:$robolectricVersion"
testImplementation 'androidx.test:core:1.0.0'
testImplementation 'androidx.test:core:1.2.0'
}

android {
Expand Down
1 change: 1 addition & 0 deletions library/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
</issue>
<issue id="GradleDependency" severity="ignore"/>
<issue id="GradleCompatible" severity="ignore"/>
<issue id="IgnoreWithoutReason" severity="ignore"/>
</lint>
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.evernote.android.job;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.test.core.app.ApplicationProvider;
import androidx.work.Configuration;
import androidx.work.WorkInfo;
import androidx.work.WorkManager;
import androidx.work.testing.SynchronousExecutor;
import androidx.work.testing.TestDriver;
import androidx.work.testing.WorkManagerTestInitHelper;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import org.junit.rules.ExternalResource;
Expand All @@ -21,16 +23,13 @@ public class PlatformWorkManagerRule extends ExternalResource {

@Override
protected void before() {
Context context = ApplicationProvider.getApplicationContext();
Context context = getContext();

Executor executor = new Executor() {
@Override
public void execute(@NonNull Runnable command) {
command.run();
}
};

WorkManagerTestInitHelper.initializeTestWorkManager(context, new Configuration.Builder().setExecutor(executor).build());
Executor executor = new SynchronousExecutor();
WorkManagerTestInitHelper.initializeTestWorkManager(context, new Configuration.Builder()
.setTaskExecutor(executor)
.setExecutor(executor)
.build());

JobConfig.setJobReschedulePause(0, TimeUnit.MILLISECONDS);
JobConfig.setSkipJobReschedule(true);
Expand All @@ -46,22 +45,31 @@ protected void after() {
mManager.destroy();

JobConfig.reset();
WorkManager.getInstance().cancelAllWork();
WorkManager.getInstance(getContext()).cancelAllWork();
}

public JobManager getManager() {
return mManager;
}

@SuppressWarnings("ConstantConditions")
public void runJob(String tag) {
WorkManagerTestInitHelper.getTestDriver().setInitialDelayMet(getWorkStatus(tag).get(0).getId());
TestDriver testDriver = WorkManagerTestInitHelper.getTestDriver(getContext());

UUID id = getWorkStatus(tag).get(0).getId();
testDriver.setAllConstraintsMet(id);
testDriver.setInitialDelayMet(id);
}

public List<WorkInfo> getWorkStatus(String tag) {
try {
return WorkManager.getInstance().getWorkInfosByTag(tag).get();
return WorkManager.getInstance(getContext()).getWorkInfosByTag(tag).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private Context getContext() {
return ApplicationProvider.getApplicationContext();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void testConstraintsPeriodic() {
}

@Test
@SuppressWarnings("ConstantConditions")
public void testCancel() {
int jobId = new JobRequest.Builder(TAG)
.setExecutionWindow(TimeUnit.HOURS.toMillis(4), TimeUnit.HOURS.toMillis(5))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ private WorkManager getWorkManager() {
// don't cache the instance, it could change under the hood, e.g. during tests
WorkManager workManager;
try {
workManager = WorkManager.getInstance();
workManager = WorkManager.getInstance(mContext);
} catch (Throwable t) {
workManager = null;
}
if (workManager == null) {
try {
WorkManager.initialize(mContext, new Configuration.Builder().build());
workManager = WorkManager.getInstance();
workManager = WorkManager.getInstance(mContext);
} catch (Throwable ignored) {
}
CAT.w("WorkManager getInstance() returned null, now: %s", workManager);
Expand Down

0 comments on commit 754db63

Please sign in to comment.