Skip to content

Commit

Permalink
Fix Android compatibility issues (#209)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fzhinkin authored Aug 14, 2023
1 parent 8836876 commit 4b0d0f8
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ Add the library to dependencies:
</dependency>
```

### Android

`kotlinx-io` is not tested on Android on a regular basis,
but the library is compatible with Android 5.0+ (API level 21+).

## Contributing

Read the [Contributing Guidelines](CONTRIBUTING.md).
Expand Down
1 change: 1 addition & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ repositories {

dependencies {
implementation(libs.kotlin.gradle.plugin)
implementation(libs.animalsniffer.gradle.plugin)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/

import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension

pluginManager.withPlugin("java") {
apply(plugin = "ru.vyarus.animalsniffer")

configure<AnimalSnifferExtension> {
sourceSets = listOf((project.extensions.getByName("sourceSets") as SourceSetContainer).getByName("main"))
}
val signature: Configuration by configurations
dependencies {
// Use the same API level as OkHttp
signature("net.sf.androidscents.signature:android-api-level-21:5.0.1_r2@signature")
}
}
1 change: 1 addition & 0 deletions bytestring/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.jetbrains.dokka.gradle.DokkaTaskPartial
plugins {
id("kotlinx-io-multiplatform")
id("kotlinx-io-publish")
id("kotlinx-io-android-compat")
alias(libs.plugins.kover)
alias(libs.plugins.dokka)
}
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.jetbrains.dokka.gradle.DokkaTaskPartial
plugins {
id("kotlinx-io-multiplatform")
id("kotlinx-io-publish")
id("kotlinx-io-android-compat")
alias(libs.plugins.kover)
alias(libs.plugins.dokka)
}
Expand Down
11 changes: 5 additions & 6 deletions core/jvm/src/files/Paths.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
package kotlinx.io.files

import kotlinx.io.*
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.nio.file.*
import java.nio.file.Path as NioPath

public actual class Path internal constructor(internal val nioPath: NioPath)
public actual class Path internal constructor(internal val file: File)

public actual fun Path(path: String): Path = Path(Paths.get(path))
public actual fun Path(path: String): Path = Path(File(path))

public actual fun Path.source(): Source = FileInputStream(nioPath.toFile()).asSource().buffered()
public actual fun Path.source(): Source = FileInputStream(file).asSource().buffered()

public actual fun Path.sink(): Sink = FileOutputStream(nioPath.toFile()).asSink().buffered()
public actual fun Path.sink(): Sink = FileOutputStream(file).asSink().buffered()
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ bcv = "0.13.2"
benchmark = "0.4.9"
jmh = "1.36"
coroutines = "1.7.3"
animalsniffer = "1.7.1"

[libraries]

kotlinx-benchmark-runtime = { group = "org.jetbrains.kotlinx", name = "kotlinx-benchmark-runtime", version.ref = "benchmark" }
kotlin-gradle-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }
animalsniffer-gradle-plugin = { group = "ru.vyarus", name = "gradle-animalsniffer-plugin", version.ref = "animalsniffer" }

[plugins]

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

0 comments on commit 4b0d0f8

Please sign in to comment.