question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting pure-java modules with ThreeTenBP to play nice with ThreeTenABP?

See original GitHub issue

Disclaimer: this is probably a gradle config issue rather than an issue with this library per-se. But hopefully this issue is relevant to android developers wanting to use JSR 310 in multi-module projects.

I have a pure java (non-android) gradle module called common with some utility functions for building ZonedDateTime objects. It depends on the standard jvm backport library (org.threeten:threetenbp).

What I’d like is to have the android app module depend on the common module to make use of these platform-independent utility functions, but depend on threetenABP instead for performance. Should this be possible? Attempting to do it naiively gives this build error:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDevelopDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK org/threeten/bp/format/ChronologyText.properties
  	File1: /Users/matthewcl/.gradle/caches/modules-2/files-2.1/org.threeten/threetenbp/1.3.1/5769e9c27cd5ba74cd3a73785dde0bbb5a2d3c0d/threetenbp-1.3.1.jar
  	File2: /Users/matthewcl/.gradle/caches/modules-2/files-2.1/org.threeten/threetenbp/1.3.1/fecd59cfa6acebf3d0f2f41f55a1cc3e24e59726/threetenbp-1.3.1-no-tzdb.jar

From what I understand, the same public classes and interfaces are in use in both modules (e.g. ZonedDateTime). It seems like something like gradle’s provided keyword to have compilation succeed and yet use ABP at runtime would work, but I haven’t had much success with it.

Any thoughts?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
tmtroncommented, Mar 26, 2018

I got it working like this:

  • In the Android application module “app” (which builds the apk): use ThreeTen Backport for Android (including timezone-info): implementation 'com.jakewharton.threetenabp:threetenabp:1.0.5'
  • In Android library modules and plain Java modules (e.g. “common”):
    • use ThreeTen Backport without time-zone info for compilation only: compileOnly 'org.threeten:threetenbp:1.3.6:no-tzdb'
    • and use the java ThreeTen Backport with time-zone info for testing: testImplementation 'org.threeten:threetenbp:1.3.6'

I think, the substitution that @JakeWharton mentions in this comment should only be required when you use an external library which uses 'org.threeten:threetenbp' to avoid the slow loading of the time-zone info.

5reactions
Byroniumcommented, Mar 7, 2018

@tmtron Correct me if I’m wrong, but the reason your solution works is the compileOnly declaration. compileOnly dependencies are not included on the runtime class-path and are non-transitive (meaning they will not be included in dependent projects). However, in most cases, wouldn’t you need the ThreeTen library to be accessible at runtime by the Java-only module common? Also, is there any particular reason you’re using the no-tzdb version of ThreeTen Backport?

Anyways, in my case, I needed the time-zone version of ThreeTenBackport in my Java-only module and I also couldn’t make it a compileOnly dependency, so I just excluded it in my Android module app where I define the common module as a dependency.

In my Java-only common module build.gradle:

implementation 'org.threeten:threetenbp:1.3.3'

In my Android app module build.gradle:

implementation (project(":common")) {
    // exclude the threetenbp dependency from the `common` module
    exclude group: 'org.threeten', module: 'threetenbp' 
}

implementation 'com.jakewharton.threetenabp:threetenabp:1.0.5'

(sidenote: I’m using the new implementation syntax instead of compile)

Just another solution in case it helps anyone!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gradle - Use other version of dependency in Unit Tests
In a pure Java module, I have a dependency to compile group: 'org.threeten', name: 'threetenbp', version: threeTenVersion, classifier: 'no-tzdb' ...
Read more >
An adaptation of the JSR-310 backport for Android.
Download. implementation 'com.jakewharton.threetenabp:threetenabp:1.3.0' ... Getting pure-java modules with ThreeTenBP to play nice with ThreeTenABP?
Read more >
Kotlin Testability – Part 1 - Styling Android
This looks to be pretty easy to unit test and we can write a JUnit 5 ... Firstly, for test builds we can...
Read more >
N Docs_net.sjava.docs_6000451_4.5.1_.apk - Hybrid Analysis
11Android library to handle jobs in the background. ... 11Insanely easy way to work with Android databases. ... 1994 Anthony Dekker NEUQUANT Neural- ......
Read more >
Android Cookbook - Description
pare your application for distribution via the Google Play Store, and to use that as well as other markets to get your application...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found