Skip to content

Fix the Samsung Health+ build on Android 12 (#41) - #48

Merged
FacuM merged 4 commits into
mainfrom
fix/engine-api31-readnbytes
Nov 29, 2026
Merged

FacuM merged 4 commits into
mainfrom
fix/engine-api31-readnbytes

Conversation

@FacuM

@FacuM FacuM commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Building Samsung Health+ on Android 12 failed at "Apply patches" with NoSuchMethodError: No virtual method readNBytes(I)[B in class Ljava/io/InputStream.

  • Cause: ZipApkFiles.head (Patcher.kt:42) called InputStream.readNBytes(int), which Android only has from API 33; the app's minSdk is 31. Only the Samsung Health+ profiles reach it, through resXmlReplaceString.
  • Fix: a readUpTo helper in the engine (Streams.kt) replaces it; SigningKeyStore.readBounded now reuses it instead of its own copy.
  • Regression guard: :engine is a pure JVM module, and the app's lint does not apply NewApi to it (tried with com.android.lint + checkDependencies: no report for the module). An androidApiCheck compilation now builds the engine sources a second time against the API 31 android.jar instead of the JDK, so a JDK method that Android 12 lacks is an unresolved reference. :engine:test and check depend on it; CI installs platforms;android-31.
  • Version 0.11.4, README known issues entry for MIUI13.03CN Android12 cant use #41.

Fixes #41

What #41 reports

The issue only carries a screenshot. It shows the patcher on step 6 of 9 ("Building your app"), the "Apply 42 patches" item failed, and this error:

NoSuchMethodError: No virtual method readNBytes(I)[B in class Ljava/io/InputStream; or its super classes (declaration of 'java.io.InputStream' appears in /apex/com.android.art/javalib/core-oj.jar)

Device: Xiaomi with MIUI 13 (China ROM), Android 12. Acceptance: on Android 12 the build passes the "Apply patches" step and finishes. The engine run from origin/main on an Android 12 emulator reproduces this exact error (see Verification).

Verification

  • :engine:test and :app:testDebugUnitTest pass (JDK 17), including the new StreamsTest.
  • Guard: reintroducing readNBytes fails the build with Unresolved reference 'readNBytes' at Patcher.kt:42.
  • Android 12 (API 31) emulator, engine run under ART on the China Samsung Health 7.00.6.012 APK (profile shealth-cn):
    • engine from origin/main: the exact NoSuchMethodError from the issue, at ZipApkFiles.head ← ResXmlReplaceString.candidateBytes;
    • with this fix: the full pipeline passes (apply 12 patterns / 414 sites, rebuild-dex, write, sign, verify-anchors self-check) and the output APK installs.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an Android 12 compatibility issue that could stop Samsung Health+ patching with a NoSuchMethodError.
    • Improved compatibility when reading APK data and signing-key input, including streams that provide data in smaller chunks.
  • Release
    • Updated the app version to 0.11.4.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Walkthrough

The patch adds a bounded stream-reading helper and replaces readNBytes in engine code. It adds an Android API 31 compile check, updates release SDK setup, and changes the app version to 0.11.4.

Changes: Android 12 compatibility

Layer / File(s) Summary
Bounded stream reading
patcher-app/engine/src/main/kotlin/io/openshm/patcher/engine/Streams.kt, patcher-app/engine/src/main/kotlin/io/openshm/patcher/engine/Patcher.kt, patcher-app/app/src/main/kotlin/io/openshm/patcher/data/SigningKeyStore.kt, patcher-app/engine/src/test/kotlin/io/openshm/patcher/engine/StreamsTest.kt
The engine adds InputStream.readUpTo(n) and uses it for APK prefix reads. SigningKeyStore.readBounded(max) delegates to the helper. Tests cover requested lengths, end-of-stream, zero-length reads, short reads, and negative lengths.
API 31 build check and release setup
patcher-app/engine/build.gradle.kts, .github/workflows/patcher-release.yml, AGENTS.md, README.md, patcher-app/app/build.gradle.kts
The engine compiles its main Kotlin sources against API 31 as part of check and test. The release workflow checks for and installs the API 31 SDK package. The instructions and known-issues section are updated, and the app version changes to 0.11.4.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · previous review bcdf9

The change replaces an API 33-only stream call with a compatible helper so Samsung Health+ builds work on Android 12. It also adds a compile-time guard against similar regressions. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive [#41] The issue body contains only a title ("MIUI13.03CN Android12 cant use") and one screenshot link. It states no requested outcome, acceptance criteria, or error text. The screenshot cannot be read… Provide the text of the error or the failing build step shown in the #41 screenshot, or add written acceptance criteria to #41. With that evidence, the reported failure can be matched to the readNBytes crash and this assessment can be fin…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the Samsung Health+ build failure on Android 12, which is the main problem the PR fixes. The changeset replaces the API 33-only readNBytes call with a readUpTo helper, adds an API 31 c…
Out of Scope Changes check Passed The changes relate to the #41 fix or its verification. Patcher.kt replaces readNBytes with readUpTo. Streams.kt adds the helper, and StreamsTest.kt covers it. SigningKeyStore.kt reuses the…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the Samsung Health+ build failure on Android 12, which is the main problem the PR fixes. The changeset replaces the API 33-only readNBytes call with a readUpTo helper, adds an API 31 compile guard, and bumps the version to 0.11.4. The title does not mention the compile guard or version bump, which is expected for a title. The trailing (#41) reference is an issue number and does not add noise that changes the meaning. The objectives describe the PR as #48, so the number in the title does not match the PR number, but the title still reflects the change.

Full details: Out of Scope Changes check

Explanation

The changes relate to the #41 fix or its verification. Patcher.kt replaces readNBytes with readUpTo. Streams.kt adds the helper, and StreamsTest.kt covers it. SigningKeyStore.kt reuses the helper instead of a duplicate loop. patcher-app/engine/build.gradle.kts adds the API 31 androidApiCheck guard that prevents a repeat of the failure. Its SDK path resolution supports that guard. The CI workflow installs platforms;android-31 for the guard. AGENTS.md and README.md document the guard and the known issue. The versionName bump to 0.11.4 matches the release note in the PR. No change was found that is unrelated to #41 or the Android 12 build failure.

Full details: Linked Issues check

Explanation

[#41] The issue body contains only a title ("MIUI13.03CN Android12 cant use") and one screenshot link. It states no requested outcome, acceptance criteria, or error text. The screenshot cannot be read from the available evidence. The PR links #41 to a specific failure: ZipApkFiles.head called InputStream.readNBytes(int), which is absent on API 31. The reviewed head confirms the fix exists: Streams.kt defines InputStream.readUpTo(n) with the readNBytes contract, and the PR description reports the replacement in Patcher.kt:42, plus a reproduction on an API 31 emulator. The code evidence shows the call is removed. It does not show that the reported #41 failure is this failure, because the screenshot content is not available. Coding requirements in #41 cannot be set from the issue text alone.

Resolution

Provide the text of the error or the failing build step shown in the #41 screenshot, or add written acceptance criteria to #41. With that evidence, the reported failure can be matched to the readNBytes crash and this assessment can be finalized.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2210296a-06d2-4a9a-b211-81b2a93f5597
Commits

Reviewing files that changed from the base of the PR and between 3202672 and bcdf97d.

Files selected for processing: 9

  • .github/workflows/patcher-release.yml
  • AGENTS.md
  • README.md
  • patcher-app/app/build.gradle.kts
  • patcher-app/app/src/main/kotlin/io/openshm/patcher/data/SigningKeyStore.kt
  • patcher-app/engine/build.gradle.kts
  • patcher-app/engine/src/main/kotlin/io/openshm/patcher/engine/Patcher.kt
  • patcher-app/engine/src/main/kotlin/io/openshm/patcher/engine/Streams.kt
  • patcher-app/engine/src/test/kotlin/io/openshm/patcher/engine/StreamsTest.kt

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T09:24:50.052701Z 8c3b00d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e7950a2836

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread README.md Resolved
Comment thread patcher-app/engine/build.gradle.kts Resolved
@FacuM

FacuM commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: bcdf97d427

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@FacuM

FacuM commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

ZipApkFiles.head called InputStream.readNBytes(int), which Android only
has from API 33, while the app runs from API 31. Only the Samsung Health+
profiles reach it (resXmlReplaceString), so building Samsung Health+ on
Android 12 failed with NoSuchMethodError (#41). A readUpTo helper in the
engine replaces it, and SigningKeyStore.readBounded now reuses it.

The app's lint does not apply NewApi to :engine, a pure JVM module, so
:engine:test now also compiles the engine sources against the API 31
android.jar instead of the JDK: such a call fails the build. CI installs
platforms;android-31 for it.
An escaped sdk.dir (Android Studio writes Windows paths escaped) now decodes to the same directory the Android build uses, instead of a path that does not exist.
@FacuM
FacuM force-pushed the fix/engine-api31-readnbytes branch from bcdf97d to 8c3b00d Compare November 29, 2026 09:23
@FacuM
FacuM merged commit 11fad5f into main Nov 29, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MIUI13.03CN Android12 cant use

1 participant