Skip to content

Commit 4b0d0f8

Browse files
authored
Fix Android compatibility issues (#209)
* Use animalsniffer plugin to verify compatibility with Android * Use java.io.File instead of java.nio.files.Path * Mention Android API compatibility in README Closes #202
1 parent 8836876 commit 4b0d0f8

File tree

7 files changed

+35
-6
lines changed

7 files changed

+35
-6
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ Add the library to dependencies:
6969
</dependency>
7070
```
7171

72+
### Android
73+
74+
`kotlinx-io` is not tested on Android on a regular basis,
75+
but the library is compatible with Android 5.0+ (API level 21+).
76+
7277
## Contributing
7378

7479
Read the [Contributing Guidelines](CONTRIBUTING.md).

build-logic/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ repositories {
1313

1414
dependencies {
1515
implementation(libs.kotlin.gradle.plugin)
16+
implementation(libs.animalsniffer.gradle.plugin)
1617
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
4+
*/
5+
6+
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension
7+
8+
pluginManager.withPlugin("java") {
9+
apply(plugin = "ru.vyarus.animalsniffer")
10+
11+
configure<AnimalSnifferExtension> {
12+
sourceSets = listOf((project.extensions.getByName("sourceSets") as SourceSetContainer).getByName("main"))
13+
}
14+
val signature: Configuration by configurations
15+
dependencies {
16+
// Use the same API level as OkHttp
17+
signature("net.sf.androidscents.signature:android-api-level-21:5.0.1_r2@signature")
18+
}
19+
}

bytestring/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import org.jetbrains.dokka.gradle.DokkaTaskPartial
33
plugins {
44
id("kotlinx-io-multiplatform")
55
id("kotlinx-io-publish")
6+
id("kotlinx-io-android-compat")
67
alias(libs.plugins.kover)
78
alias(libs.plugins.dokka)
89
}

core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.jetbrains.dokka.gradle.DokkaTaskPartial
88
plugins {
99
id("kotlinx-io-multiplatform")
1010
id("kotlinx-io-publish")
11+
id("kotlinx-io-android-compat")
1112
alias(libs.plugins.kover)
1213
alias(libs.plugins.dokka)
1314
}

core/jvm/src/files/Paths.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
package kotlinx.io.files
77

88
import kotlinx.io.*
9+
import java.io.File
910
import java.io.FileInputStream
1011
import java.io.FileOutputStream
11-
import java.nio.file.*
12-
import java.nio.file.Path as NioPath
1312

14-
public actual class Path internal constructor(internal val nioPath: NioPath)
13+
public actual class Path internal constructor(internal val file: File)
1514

16-
public actual fun Path(path: String): Path = Path(Paths.get(path))
15+
public actual fun Path(path: String): Path = Path(File(path))
1716

18-
public actual fun Path.source(): Source = FileInputStream(nioPath.toFile()).asSource().buffered()
17+
public actual fun Path.source(): Source = FileInputStream(file).asSource().buffered()
1918

20-
public actual fun Path.sink(): Sink = FileOutputStream(nioPath.toFile()).asSink().buffered()
19+
public actual fun Path.sink(): Sink = FileOutputStream(file).asSink().buffered()

gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ bcv = "0.13.2"
77
benchmark = "0.4.9"
88
jmh = "1.36"
99
coroutines = "1.7.3"
10+
animalsniffer = "1.7.1"
1011

1112
[libraries]
1213

1314
kotlinx-benchmark-runtime = { group = "org.jetbrains.kotlinx", name = "kotlinx-benchmark-runtime", version.ref = "benchmark" }
1415
kotlin-gradle-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
1516
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }
17+
animalsniffer-gradle-plugin = { group = "ru.vyarus", name = "gradle-animalsniffer-plugin", version.ref = "animalsniffer" }
18+
1619
[plugins]
1720

1821
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }

0 commit comments

Comments
 (0)