Skip to content

Commit bccfabc

Browse files
authored
Enable core library desugaring (#496)
1 parent 611ea81 commit bccfabc

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

buildSrc/src/main/kotlin/readium.library-conventions.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ android {
2323
compileOptions {
2424
sourceCompatibility = JavaVersion.VERSION_1_8
2525
targetCompatibility = JavaVersion.VERSION_1_8
26+
isCoreLibraryDesugaringEnabled = true
2627
}
2728

2829
kotlinOptions {
@@ -55,6 +56,10 @@ kotlin {
5556
explicitApi()
5657
}
5758

59+
dependencies {
60+
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
61+
}
62+
5863
mavenPublishing {
5964
coordinates(
6065
groupId = group.toString(),

docs/migration-guide.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All migration steps necessary in reading apps to upgrade to major versions of the Kotlin Readium toolkit will be documented in this file.
44

5+
## Unreleased
6+
7+
### Core library desugaring
8+
9+
If you target Android devices running below API 26, you now must enable [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) in your application module.
10+
11+
512
## 3.0.0-alpha.2
613

714
### Deprecation of `DownloadManager`

gradle/libs.versions.toml

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

33
kotlin = "1.9.22"
44
agp = "8.2.2"
5+
desugar_jdk_libs = "2.0.4"
56
gradle-maven-publish-plugin = "0.27.0"
67

78
accompanist = "0.34.0"
@@ -46,11 +47,7 @@ google-exoplayer = "2.19.1"
4647
google-material = "1.11.0"
4748

4849
joda-time = "2.12.6"
49-
# Jsoup 1.16.2 requires core library desugaring, otherwise it crashes on Android 7 devices when
50-
# opening the EPUB navigator.
51-
# Before enabling desugaring, we need to assess its impact on the toolkit.
52-
# See https://github.com/jhy/jsoup/issues/2022#issuecomment-1783931119
53-
jsoup = "1.16.1"
50+
jsoup = "1.17.2"
5451
junit = "4.13.2"
5552

5653
kotlinx-coroutines = "1.7.3"
@@ -123,6 +120,7 @@ androidx-webkit = { group = "androidx.webkit", name = "webkit", version.ref = "a
123120

124121
assertj = { group = "org.assertj", name = "assertj-core", version.ref = "assertj" }
125122

123+
desugar_jdk_libs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar_jdk_libs" }
126124
google-exoplayer-core = { group = "com.google.android.exoplayer", name = "exoplayer-core", version.ref = "google-exoplayer" }
127125
google-exoplayer-extension-media2 = { group = "com.google.android.exoplayer", name = "extension-media2", version.ref = "google-exoplayer" }
128126
google-exoplayer-mediasession = { group = "com.google.android.exoplayer", name = "extension-mediasession", version.ref = "google-exoplayer" }

readium/shared/src/test/java/org/readium/r2/shared/publication/services/content/iterators/HtmlResourceContentIteratorTest.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class HtmlResourceContentIteratorTest {
5454
TextElement(
5555
locator = locator(
5656
progression = 0.0,
57-
selector = "#pgepubid00498 > div.center",
57+
selector = "html > body > section > div.center",
5858
before = null,
5959
highlight = "171"
6060
),
@@ -63,7 +63,7 @@ class HtmlResourceContentIteratorTest {
6363
Segment(
6464
locator = locator(
6565
progression = 0.0,
66-
selector = "#pgepubid00498 > div.center",
66+
selector = "html > body > section > div.center",
6767
before = null,
6868
highlight = "171"
6969
),
@@ -75,7 +75,7 @@ class HtmlResourceContentIteratorTest {
7575
TextElement(
7676
locator = locator(
7777
progression = 0.2,
78-
selector = "#pgepubid00498 > h3",
78+
selector = "html > body > section > h3",
7979
before = "171",
8080
highlight = "INTRODUCTORY"
8181
),
@@ -84,7 +84,7 @@ class HtmlResourceContentIteratorTest {
8484
Segment(
8585
locator = locator(
8686
progression = 0.2,
87-
selector = "#pgepubid00498 > h3",
87+
selector = "html > body > section > h3",
8888
before = "171",
8989
highlight = "INTRODUCTORY"
9090
),
@@ -96,7 +96,7 @@ class HtmlResourceContentIteratorTest {
9696
TextElement(
9797
locator = locator(
9898
progression = 0.4,
99-
selector = "#pgepubid00498 > p:nth-child(3)",
99+
selector = "html > body > section > p:nth-child(3)",
100100
before = "171INTRODUCTORY",
101101
highlight = "The difficulties of classification are very apparent here, and once more it must be noted that illustrative and practical purposes rather than logical ones are served by the arrangement adopted. The modern fanciful story is here placed next to the real folk story instead of after all the groups of folk products. The Hebrew stories at the beginning belong quite as well, perhaps even better, in Section V, while the stories at the end of Section VI shade off into the more modern types of short tales."
102102
),
@@ -105,7 +105,7 @@ class HtmlResourceContentIteratorTest {
105105
Segment(
106106
locator = locator(
107107
progression = 0.4,
108-
selector = "#pgepubid00498 > p:nth-child(3)",
108+
selector = "html > body > section > p:nth-child(3)",
109109
before = "171INTRODUCTORY",
110110
highlight = "The difficulties of classification are very apparent here, and once more it must be noted that illustrative and practical purposes rather than logical ones are served by the arrangement adopted. The modern fanciful story is here placed next to the real folk story instead of after all the groups of folk products. The Hebrew stories at the beginning belong quite as well, perhaps even better, in Section V, while the stories at the end of Section VI shade off into the more modern types of short tales."
111111
),
@@ -117,7 +117,7 @@ class HtmlResourceContentIteratorTest {
117117
TextElement(
118118
locator = locator(
119119
progression = 0.6,
120-
selector = "#pgepubid00498 > p:nth-child(4)",
120+
selector = "html > body > section > p:nth-child(4)",
121121
before = "ade off into the more modern types of short tales.",
122122
highlight = "The child's natural literature. The world has lost certain secrets as the price of an advancing civilization."
123123
),
@@ -126,7 +126,7 @@ class HtmlResourceContentIteratorTest {
126126
Segment(
127127
locator = locator(
128128
progression = 0.6,
129-
selector = "#pgepubid00498 > p:nth-child(4)",
129+
selector = "html > body > section > p:nth-child(4)",
130130
before = "ade off into the more modern types of short tales.",
131131
highlight = "The child's natural literature. The world has lost certain secrets as the price of an advancing civilization."
132132
),
@@ -138,7 +138,7 @@ class HtmlResourceContentIteratorTest {
138138
TextElement(
139139
locator = locator(
140140
progression = 0.8,
141-
selector = "#pgepubid00498 > p:nth-child(5)",
141+
selector = "html > body > section > p:nth-child(5)",
142142
before = "secrets as the price of an advancing civilization.",
143143
highlight = "Without discussing the limits of the culture-epoch theory of human development as a complete guide in education, it is clear that the young child passes through a period when his mind looks out upon the world in a manner analogous to that of the folk as expressed in their literature."
144144
),
@@ -147,7 +147,7 @@ class HtmlResourceContentIteratorTest {
147147
Segment(
148148
locator = locator(
149149
progression = 0.8,
150-
selector = "#pgepubid00498 > p:nth-child(5)",
150+
selector = "html > body > section > p:nth-child(5)",
151151
before = "secrets as the price of an advancing civilization.",
152152
highlight = "Without discussing the limits of the culture-epoch theory of human development as a complete guide in education, it is clear that the young child passes through a period when his mind looks out upon the world in a manner analogous to that of the folk as expressed in their literature."
153153
),
@@ -271,13 +271,13 @@ class HtmlResourceContentIteratorTest {
271271

272272
@Test
273273
fun `starting from a CSS selector`() = runTest {
274-
val iter = iterator(html, locator(selector = "#pgepubid00498 > p:nth-child(3)"))
274+
val iter = iterator(html, locator(selector = "html > body > section > p:nth-child(3)"))
275275
assertEquals(elements.subList(2, elements.size), iter.elements())
276276
}
277277

278278
@Test
279279
fun `calling previous() when starting from a CSS selector`() = runTest {
280-
val iter = iterator(html, locator(selector = "#pgepubid00498 > p:nth-child(3)"))
280+
val iter = iterator(html, locator(selector = "html > body > section > p:nth-child(3)"))
281281
assertTrue(iter.hasPrevious())
282282
assertEquals(elements[1], iter.previous())
283283
}
@@ -557,7 +557,7 @@ class HtmlResourceContentIteratorTest {
557557
TextElement(
558558
locator = locator(
559559
progression = 2 / 3.0,
560-
selector = "#c06-li-0001 > aside",
560+
selector = "html > body > ol.decimal > li > aside",
561561
before = "e just described is very much a waterfall process.\n \n ",
562562
highlight = "Trailing text"
563563
),
@@ -566,7 +566,7 @@ class HtmlResourceContentIteratorTest {
566566
Segment(
567567
locator = locator(
568568
progression = 2 / 3.0,
569-
selector = "#c06-li-0001 > aside",
569+
selector = "html > body > ol.decimal > li > aside",
570570
before = "e just described is very much a waterfall process.\n ",
571571
highlight = "Trailing text"
572572
),

test-app/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ android {
3131
compileOptions {
3232
sourceCompatibility = JavaVersion.VERSION_1_8
3333
targetCompatibility = JavaVersion.VERSION_1_8
34+
isCoreLibraryDesugaringEnabled = true
3435
}
3536
kotlinOptions {
3637
jvmTarget = JavaVersion.VERSION_1_8.toString()
@@ -65,6 +66,8 @@ android {
6566
}
6667

6768
dependencies {
69+
coreLibraryDesugaring(libs.desugar.jdk.libs)
70+
6871
implementation(libs.kotlin.stdlib)
6972
implementation(libs.androidx.legacy.v4)
7073

0 commit comments

Comments
 (0)