From 39aa29ba19409ec3b6fd8bfb7863852df1d2d9dc Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Tue, 3 Sep 2024 23:37:49 +0200 Subject: [PATCH 01/10] run test across a range of JDKs --- .github/workflows/test.yml | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 97b4d17..f5eb701 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,23 +1,33 @@ name: Test on: - push: - branches: [ master ] + workflow_dispatch: pull_request: - branches: [ master ] + branches: [master] jobs: test: - runs-on: macos-12 + name: Test on Java ${{ matrix.java-version }} + runs-on: macos-latest timeout-minutes: 15 + + strategy: + fail-fast: false + matrix: + java-version: [8, 11, 17, 21] + steps: - - name: checkout - uses: actions/checkout@v3 - - - name: Gradle cache - uses: gradle/gradle-build-action@v2 + - name: Clone repository + uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: ${{ matrix.java-version }} + cache: gradle - - name: create AVD and generate snapshot for caching + - name: Create AVD and generate snapshot for caching if: steps.avd-cache.outputs.cache-hit != 'true' uses: reactivecircus/android-emulator-runner@v2.29.0 with: @@ -27,7 +37,7 @@ jobs: disable-animations: false script: echo "Generated AVD snapshot for caching." - - name: run tests + - name: Run tests uses: reactivecircus/android-emulator-runner@v2.29.0 with: api-level: 29 From f4adf5e5253fcdffd1d1b9fcb0845696d65987b9 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Fri, 6 Sep 2024 01:12:45 +0200 Subject: [PATCH 02/10] mostly copy config from maestro --- .github/workflows/test.yml | 101 ++++++++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 18 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f5eb701..f46d652 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,15 +8,35 @@ on: jobs: test: name: Test on Java ${{ matrix.java-version }} - runs-on: macos-latest + runs-on: ubuntu-latest timeout-minutes: 15 strategy: fail-fast: false matrix: - java-version: [8, 11, 17, 21] + # Android Command-line Tools versions depend on Java versions, so we need + # to specify exact versions. + # Learn more: https://stackoverflow.com/a/78890086/7009800 + include: + - java-version: 8 + android-clt-version: 9123335 + - java-version: 11 + android-clt-version: 9862592 + - java-version: 17 + android-clt-version: 11479570 + + env: + ANDROID_HOME: /home/runner/androidsdk + ANDROID_SDK_ROOT: /home/runner/androidsdk + ANDROID_OS_IMAGE: system-images;android-29;google_apis;x86_64 steps: + - name: Enable KVM group perms + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + - name: Clone repository uses: actions/checkout@v4 @@ -27,21 +47,66 @@ jobs: java-version: ${{ matrix.java-version }} cache: gradle - - name: Create AVD and generate snapshot for caching - if: steps.avd-cache.outputs.cache-hit != 'true' - uses: reactivecircus/android-emulator-runner@v2.29.0 - with: - api-level: 29 - force-avd-creation: false - emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - disable-animations: false - script: echo "Generated AVD snapshot for caching." + - name: Set up bartekpacia/scripts (for install_android_sdk script) + run: | + git clone https://github.com/bartekpacia/scripts.git $HOME/scripts + echo "$HOME/scripts/bin" >> $GITHUB_PATH + + - name: Set up android-wait-for-emulator script + run: | + curl -fsSl -O https://raw.githubusercontent.com/travis-ci/travis-cookbooks/master/community-cookbooks/android-sdk/files/default/android-wait-for-emulator + chmod +x ./android-wait-for-emulator + mv ./android-wait-for-emulator $HOME/scripts/bin + + - name: Set up Android Command-line Tools + run: | + install_android_sdk https://dl.google.com/android/repository/commandlinetools-linux-${{ matrix.android-clt-version }}_latest.zip + echo "$ANDROID_HOME/cmdline-tools/latest/bin:$PATH" >> $GITHUB_PATH + + - name: Set up Android SDK components + run: | + yes | sdkmanager --install emulator + echo "$ANDROID_HOME/emulator" >> $GITHUB_PATH + yes | sdkmanager --install "platform-tools" + echo "$ANDROID_HOME/platform-tools" >> $GITHUB_PATH + yes | sdkmanager --install "platforms;android-29" + yes | sdkmanager --install "$ANDROID_OS_IMAGE" + + - name: Create AVD + run: | + avdmanager -s create avd \ + --package "$ANDROID_OS_IMAGE" \ + --name "MyAVD" + + cat << EOF >> ~/.android/avd/MyAVD.avd/config.ini + hw.cpu.ncore=2 + hw.gpu.enabled=yes + hw.gpu.mode=swiftshader_indirect + hw.ramSize=3072 + disk.dataPartition.size=4G + vm.heapSize=576 + hw.lcd.density=440 + hw.lcd.height=2220 + hw.lcd.width=1080 + EOF + + - name: Run AVD + run: | + emulator @MyAVD \ + -verbose -no-snapshot-save -no-window -noaudio -no-boot-anim -accel on -camera-back none -gpu swiftshader_indirect \ + >~/emulator_stdout.log \ + 2>~/emulator_stderr.log & + + - name: Wait for AVD to start up + run: | + android-wait-for-emulator + + # This is also a prerequiste + while true; do + adb shell service list | grep 'package' && echo 'service "package" is active!' && break + echo 'waiting for service "package" to start' + sleep 1 + done - name: Run tests - uses: reactivecircus/android-emulator-runner@v2.29.0 - with: - api-level: 29 - force-avd-creation: false - emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - disable-animations: true - script: ./gradlew nativeTest + run: ./gradlew nativeTest From 3dd68aa0213d925f21d766068c92bfffad5c4669 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Fri, 6 Sep 2024 12:24:32 +0200 Subject: [PATCH 03/10] clean up and upgrade Gradle files --- build.gradle.kts | 61 ++++--------------------------------------- dadb/build.gradle.kts | 47 ++++++++++++++++++++++++++++----- settings.gradle.kts | 16 ++++++++++++ 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b5efc16..b56c484 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,58 +1,7 @@ -import com.adarshr.gradle.testlogger.TestLoggerExtension -import com.adarshr.gradle.testlogger.theme.ThemeType.STANDARD -import com.vanniktech.maven.publish.MavenPublishPluginExtension -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import com.vanniktech.maven.publish.SonatypeHost - -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath(kotlin("gradle-plugin", "1.5.30")) - classpath("com.vanniktech:gradle-maven-publish-plugin:0.17.0") - } -} - plugins { - id("com.adarshr.test-logger") version("3.2.0") apply(true) -} - -allprojects { - tasks.withType(JavaCompile::class.java) { - sourceCompatibility = "1.8" - targetCompatibility = "1.8" - } - tasks.withType(KotlinCompile::class.java) { - kotlinOptions { - jvmTarget = "1.8" - freeCompilerArgs += "-Xopt-in=kotlin.ExperimentalUnsignedTypes" - } - } - tasks.withType(Task::class) { - project.apply(plugin = "com.adarshr.test-logger") - project.configure { - theme = STANDARD - showExceptions = true - showStackTraces = false - showFullStackTraces = false - showCauses = true - slowThreshold = 5000 - showSummary = true - showSimpleNames = false - showPassed = true - showSkipped = true - showFailed = true - showOnlySlow = false - showStandardStreams = false - showPassedStandardStreams = false - showSkippedStandardStreams = false - showFailedStandardStreams = true - } - } - pluginManager.withPlugin("com.vanniktech.maven.publish") { - extensions.getByType(MavenPublishPluginExtension::class.java).apply { - sonatypeHost = SonatypeHost.S01 - } - } + id("com.adarshr.test-logger") version ("3.2.0") + id("org.jetbrains.kotlin.jvm") version ("1.8.22") apply false + id("com.palantir.graal") version "0.9.0" apply false + id("org.graalvm.buildtools.native") version "0.9.5" apply false + id("com.vanniktech.maven.publish") version ("0.17.0") apply false } diff --git a/dadb/build.gradle.kts b/dadb/build.gradle.kts index 29e025a..80a3041 100644 --- a/dadb/build.gradle.kts +++ b/dadb/build.gradle.kts @@ -1,20 +1,20 @@ +import com.adarshr.gradle.testlogger.theme.ThemeType.STANDARD +import com.vanniktech.maven.publish.SonatypeHost import org.gradle.internal.jvm.inspection.DefaultJvmMetadataDetector import org.gradle.internal.os.OperatingSystem import org.gradle.jvm.toolchain.internal.DefaultToolchainSpec import org.gradle.jvm.toolchain.internal.JavaToolchainFactory import org.gradle.jvm.toolchain.internal.JavaToolchainInput +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { `maven-publish` id("org.jetbrains.kotlin.jvm") id("com.vanniktech.maven.publish") `java-library` - id("com.palantir.graal") version "0.9.0" - id("org.graalvm.buildtools.native") version "0.9.5" -} - -repositories { - mavenCentral() + id("com.palantir.graal") + id("org.graalvm.buildtools.native") + id("com.adarshr.test-logger") } dependencies { @@ -61,3 +61,38 @@ graalvmNative { } } } + +tasks.withType(JavaCompile::class.java).configureEach { + options.release.set(8) +} + +tasks.withType(KotlinCompile::class.java).configureEach { + kotlinOptions { + jvmTarget = "1.8" + freeCompilerArgs += "-Xjdk-release=1.8" + freeCompilerArgs += "-opt-in=kotlin.ExperimentalUnsignedTypes" + } +} + +testlogger { + theme = STANDARD + showExceptions = true + showStackTraces = false + showFullStackTraces = false + showCauses = true + slowThreshold = 5000 + showSummary = true + showSimpleNames = false + showPassed = true + showSkipped = true + showFailed = true + showOnlySlow = false + showStandardStreams = false + showPassedStandardStreams = false + showSkippedStandardStreams = false + showFailedStandardStreams = true +} + +mavenPublishing { + publishToMavenCentral(SonatypeHost.S01) +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 10dfcb6..928adc5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,2 +1,18 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + rootProject.name = "dadb" include("dadb") From 8410d5a1b5c300a7ea109fa9f0ffcef6ce55ec19 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Fri, 6 Sep 2024 13:57:50 +0200 Subject: [PATCH 04/10] Revert "clean up and upgrade Gradle files" This reverts commit 3dd68aa0213d925f21d766068c92bfffad5c4669. --- build.gradle.kts | 61 +++++++++++++++++++++++++++++++++++++++---- dadb/build.gradle.kts | 47 +++++---------------------------- settings.gradle.kts | 16 ------------ 3 files changed, 62 insertions(+), 62 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b56c484..b5efc16 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,58 @@ +import com.adarshr.gradle.testlogger.TestLoggerExtension +import com.adarshr.gradle.testlogger.theme.ThemeType.STANDARD +import com.vanniktech.maven.publish.MavenPublishPluginExtension +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import com.vanniktech.maven.publish.SonatypeHost + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath(kotlin("gradle-plugin", "1.5.30")) + classpath("com.vanniktech:gradle-maven-publish-plugin:0.17.0") + } +} + plugins { - id("com.adarshr.test-logger") version ("3.2.0") - id("org.jetbrains.kotlin.jvm") version ("1.8.22") apply false - id("com.palantir.graal") version "0.9.0" apply false - id("org.graalvm.buildtools.native") version "0.9.5" apply false - id("com.vanniktech.maven.publish") version ("0.17.0") apply false + id("com.adarshr.test-logger") version("3.2.0") apply(true) +} + +allprojects { + tasks.withType(JavaCompile::class.java) { + sourceCompatibility = "1.8" + targetCompatibility = "1.8" + } + tasks.withType(KotlinCompile::class.java) { + kotlinOptions { + jvmTarget = "1.8" + freeCompilerArgs += "-Xopt-in=kotlin.ExperimentalUnsignedTypes" + } + } + tasks.withType(Task::class) { + project.apply(plugin = "com.adarshr.test-logger") + project.configure { + theme = STANDARD + showExceptions = true + showStackTraces = false + showFullStackTraces = false + showCauses = true + slowThreshold = 5000 + showSummary = true + showSimpleNames = false + showPassed = true + showSkipped = true + showFailed = true + showOnlySlow = false + showStandardStreams = false + showPassedStandardStreams = false + showSkippedStandardStreams = false + showFailedStandardStreams = true + } + } + pluginManager.withPlugin("com.vanniktech.maven.publish") { + extensions.getByType(MavenPublishPluginExtension::class.java).apply { + sonatypeHost = SonatypeHost.S01 + } + } } diff --git a/dadb/build.gradle.kts b/dadb/build.gradle.kts index 80a3041..29e025a 100644 --- a/dadb/build.gradle.kts +++ b/dadb/build.gradle.kts @@ -1,20 +1,20 @@ -import com.adarshr.gradle.testlogger.theme.ThemeType.STANDARD -import com.vanniktech.maven.publish.SonatypeHost import org.gradle.internal.jvm.inspection.DefaultJvmMetadataDetector import org.gradle.internal.os.OperatingSystem import org.gradle.jvm.toolchain.internal.DefaultToolchainSpec import org.gradle.jvm.toolchain.internal.JavaToolchainFactory import org.gradle.jvm.toolchain.internal.JavaToolchainInput -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { `maven-publish` id("org.jetbrains.kotlin.jvm") id("com.vanniktech.maven.publish") `java-library` - id("com.palantir.graal") - id("org.graalvm.buildtools.native") - id("com.adarshr.test-logger") + id("com.palantir.graal") version "0.9.0" + id("org.graalvm.buildtools.native") version "0.9.5" +} + +repositories { + mavenCentral() } dependencies { @@ -61,38 +61,3 @@ graalvmNative { } } } - -tasks.withType(JavaCompile::class.java).configureEach { - options.release.set(8) -} - -tasks.withType(KotlinCompile::class.java).configureEach { - kotlinOptions { - jvmTarget = "1.8" - freeCompilerArgs += "-Xjdk-release=1.8" - freeCompilerArgs += "-opt-in=kotlin.ExperimentalUnsignedTypes" - } -} - -testlogger { - theme = STANDARD - showExceptions = true - showStackTraces = false - showFullStackTraces = false - showCauses = true - slowThreshold = 5000 - showSummary = true - showSimpleNames = false - showPassed = true - showSkipped = true - showFailed = true - showOnlySlow = false - showStandardStreams = false - showPassedStandardStreams = false - showSkippedStandardStreams = false - showFailedStandardStreams = true -} - -mavenPublishing { - publishToMavenCentral(SonatypeHost.S01) -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 928adc5..10dfcb6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,18 +1,2 @@ -pluginManagement { - repositories { - google() - mavenCentral() - gradlePluginPortal() - } -} - -dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) - repositories { - google() - mavenCentral() - } -} - rootProject.name = "dadb" include("dadb") From d7bf9706b21f2e82e0c09c30904a90cdce871598 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Fri, 6 Sep 2024 14:06:44 +0200 Subject: [PATCH 05/10] set -relase=8 for java, bump Kotlin to 1.7.21 --- build.gradle.kts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index b5efc16..a8fa6eb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ buildscript { mavenCentral() } dependencies { - classpath(kotlin("gradle-plugin", "1.5.30")) + classpath(kotlin("gradle-plugin", "1.7.21")) classpath("com.vanniktech:gradle-maven-publish-plugin:0.17.0") } } @@ -22,11 +22,13 @@ allprojects { tasks.withType(JavaCompile::class.java) { sourceCompatibility = "1.8" targetCompatibility = "1.8" + options.release.set(8) } tasks.withType(KotlinCompile::class.java) { kotlinOptions { jvmTarget = "1.8" freeCompilerArgs += "-Xopt-in=kotlin.ExperimentalUnsignedTypes" + freeCompilerArgs += "-Xjdk-release=1.8" } } tasks.withType(Task::class) { From 244f6ba6ff6e93e76618f7cbfc2969ac80862c5a Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Fri, 6 Sep 2024 14:21:49 +0200 Subject: [PATCH 06/10] Revert "set -relase=8 for java, bump Kotlin to 1.7.21" This reverts commit d7bf9706b21f2e82e0c09c30904a90cdce871598. --- build.gradle.kts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index a8fa6eb..b5efc16 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ buildscript { mavenCentral() } dependencies { - classpath(kotlin("gradle-plugin", "1.7.21")) + classpath(kotlin("gradle-plugin", "1.5.30")) classpath("com.vanniktech:gradle-maven-publish-plugin:0.17.0") } } @@ -22,13 +22,11 @@ allprojects { tasks.withType(JavaCompile::class.java) { sourceCompatibility = "1.8" targetCompatibility = "1.8" - options.release.set(8) } tasks.withType(KotlinCompile::class.java) { kotlinOptions { jvmTarget = "1.8" freeCompilerArgs += "-Xopt-in=kotlin.ExperimentalUnsignedTypes" - freeCompilerArgs += "-Xjdk-release=1.8" } } tasks.withType(Task::class) { From 37ec3e444cd74fea266382fa690183993e2f4a9e Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Fri, 6 Sep 2024 14:24:10 +0200 Subject: [PATCH 07/10] apply simple fix --- dadb/src/main/kotlin/dadb/AdbStream.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dadb/src/main/kotlin/dadb/AdbStream.kt b/dadb/src/main/kotlin/dadb/AdbStream.kt index db2abf4..218c7c9 100644 --- a/dadb/src/main/kotlin/dadb/AdbStream.kt +++ b/dadb/src/main/kotlin/dadb/AdbStream.kt @@ -93,7 +93,9 @@ internal class AdbStreamImpl internal constructor( val bytesToWrite = min(buffer.remaining(), byteCount.toInt()) val bytesWritten = source.read(buffer.array(), buffer.position(), bytesToWrite) - buffer.position(buffer.position() + bytesWritten) + // Cast to prevent NoSuchMethodError when mixing Java versions + // Learn more: https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror/ + (buffer as java.nio.Buffer).position(buffer.position() + bytesWritten) if (buffer.remaining() == 0) flush() return bytesWritten From 053dc3421df31421513c6d31a867785f47a41040 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Fri, 6 Sep 2024 14:50:57 +0200 Subject: [PATCH 08/10] attempt to fix rror: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: java.nio.ByteBuffer.clear() --- dadb/src/main/kotlin/dadb/AdbStream.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dadb/src/main/kotlin/dadb/AdbStream.kt b/dadb/src/main/kotlin/dadb/AdbStream.kt index 218c7c9..f9742e3 100644 --- a/dadb/src/main/kotlin/dadb/AdbStream.kt +++ b/dadb/src/main/kotlin/dadb/AdbStream.kt @@ -103,7 +103,7 @@ internal class AdbStreamImpl internal constructor( override fun flush() { adbWriter.writeWrite(localId, remoteId, buffer.array(), 0, buffer.position()) - buffer.clear() + (buffer as java.nio.Buffer).clear() } override fun close() {} From 36bdb1a11656afb577b6ea4ee3a88fb27ab8545f Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Fri, 6 Sep 2024 16:56:47 +0200 Subject: [PATCH 09/10] split writing into config.ini from AVD creation --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f46d652..c4c0585 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -78,6 +78,8 @@ jobs: --package "$ANDROID_OS_IMAGE" \ --name "MyAVD" + - name: Configure AVD + run: | cat << EOF >> ~/.android/avd/MyAVD.avd/config.ini hw.cpu.ncore=2 hw.gpu.enabled=yes From b2be6d63daae6d1d24d3c150ef73e0ba2f40a16c Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Fri, 6 Sep 2024 17:00:49 +0200 Subject: [PATCH 10/10] fix --- .github/workflows/test.yml | 3 +-- dadb/src/main/kotlin/dadb/AdbStream.kt | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c4c0585..18c7dff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,6 +28,7 @@ jobs: env: ANDROID_HOME: /home/runner/androidsdk ANDROID_SDK_ROOT: /home/runner/androidsdk + ANDROID_USER_HOME: /home/runner/.android ANDROID_OS_IMAGE: system-images;android-29;google_apis;x86_64 steps: @@ -78,8 +79,6 @@ jobs: --package "$ANDROID_OS_IMAGE" \ --name "MyAVD" - - name: Configure AVD - run: | cat << EOF >> ~/.android/avd/MyAVD.avd/config.ini hw.cpu.ncore=2 hw.gpu.enabled=yes diff --git a/dadb/src/main/kotlin/dadb/AdbStream.kt b/dadb/src/main/kotlin/dadb/AdbStream.kt index f9742e3..dfec53c 100644 --- a/dadb/src/main/kotlin/dadb/AdbStream.kt +++ b/dadb/src/main/kotlin/dadb/AdbStream.kt @@ -94,7 +94,7 @@ internal class AdbStreamImpl internal constructor( val bytesWritten = source.read(buffer.array(), buffer.position(), bytesToWrite) // Cast to prevent NoSuchMethodError when mixing Java versions - // Learn more: https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror/ + // Learn more: https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror (buffer as java.nio.Buffer).position(buffer.position() + bytesWritten) if (buffer.remaining() == 0) flush() @@ -103,6 +103,9 @@ internal class AdbStreamImpl internal constructor( override fun flush() { adbWriter.writeWrite(localId, remoteId, buffer.array(), 0, buffer.position()) + + // Cast to prevent NoSuchMethodError when mixing Java versions + // Learn more: https://www.morling.dev/blog/bytebuffer-and-the-dreaded-nosuchmethoderror (buffer as java.nio.Buffer).clear() }