From b1863c4eff0e0921ce0e9f046477f79eb45eac61 Mon Sep 17 00:00:00 2001 From: Robin Genz Date: Mon, 2 Nov 2026 07:53:34 +0100 Subject: [PATCH 1/2] feat: the Android core comes from its release asset, pinned by version and checksum The Android module took com.hotcodepush:core-android by full sha from core-android's maven branch, which every customer build read from raw.githubusercontent.com. It now takes the Maven-layout zip of the 0.1.0 release: package.json pins its version and SHA-256 under hotcodepush.coreAndroid, and scripts/download-core-android.mjs checks the checksum and unpacks it into an ignored local Maven repository that ships in the npm package. The script refuses a Gradle file that names another version than the pin, and the maven branch stays the development pin only. Co-Authored-By: Claude Fable 5.1 --- .gitignore | 3 +- CLAUDE.md | 21 +++++----- README.md | 2 +- android/build.gradle | 6 +-- android/hotcodepush.gradle | 4 +- package.json | 10 ++++- scripts/download-core-android.mjs | 67 +++++++++++++++++++++++++++++++ 7 files changed, 94 insertions(+), 19 deletions(-) create mode 100644 scripts/download-core-android.mjs diff --git a/.gitignore b/.gitignore index e5a4e4f..a2bd792 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,8 @@ node_modules android/src/main/java/com/hotcodepush/reactnative/SdkVersion.kt ios/SdkVersion.swift -# The core's XCFramework, downloaded by every build +# The cores, downloaded by every build: the Maven repository of the Android core and the XCFramework +android/libs ios/Frameworks # iOS diff --git a/CLAUDE.md b/CLAUDE.md index c0f6ea3..c71f3e3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -15,13 +15,14 @@ ios/ the Turbo Module (Objective-C android/src/main/java/com/hotcodepush/reactnative the Turbo Module, the runtime, the first-render listener, the bundle loader, the reader of the embedded bundle and the React host over com.hotcodepush:core-android android/src/test/java/com/hotcodepush/reactnative the Robolectric tests of the Android runtime and the Turbo Module, which verify:android runs android/settings.gradle the library's own build, which takes React Native's Gradle plugin and react-android's version from node_modules -android/hotcodepush.gradle the task that runs binary create for every variant, and core-android's maven branch among `:app`'s repositories; applied by the app's build.gradle +android/hotcodepush.gradle the task that runs binary create for every variant, and the package's local Maven repository among `:app`'s repositories; applied by the app's build.gradle scripts/binary-create-xcode.sh binary create as the app's Xcode phase runs it +scripts/download-core-android.mjs the core's Maven-layout zip into the ignored android/libs/m2, which both Gradle scripts read scripts/download-core-ios.mjs the core's XCFramework into the ignored ios/Frameworks, which the pod vendors benchmarks/ the size and cold-start baseline, measured on the demo ``` -The native cores live in `core-ios` and `core-android`. `core-ios` is the XCFramework of a release: `package.json` pins its URL and checksum under `hotcodepush.coreIos`, and `scripts/download-core-ios.mjs` unpacks it into the ignored `ios/Frameworks` for the pod's `vendored_frameworks`, so the app's Podfile names no core. The Android library comes from core-android's `maven` branch by full sha in `android/build.gradle`; a core change lands there first and arrives here as a bump of both pins. +The native cores live in `core-ios` and `core-android`. `core-ios` is the XCFramework of a release: `package.json` pins its URL and checksum under `hotcodepush.coreIos`, and `scripts/download-core-ios.mjs` unpacks it into the ignored `ios/Frameworks` for the pod's `vendored_frameworks`, so the app's Podfile names no core. The Android module is the Maven-layout zip of a release, `core-android--maven.zip`: `package.json` pins its version and the zip's SHA-256 under `hotcodepush.coreAndroid`, and `scripts/download-core-android.mjs` unpacks it into the ignored `android/libs/m2`, the local Maven repository that `android/build.gradle` and the app's `android/hotcodepush.gradle` read. A bump of the core is a new version in `package.json` and in `android/build.gradle`, which the script checks against each other, and the checksum from the summary of core-android's release job. core-android's `maven` branch, pinned by full sha, is the development pin only, for trying a core change before its release; a published build never names it. This package keeps what is React Native's: which bundle the host loads, the reload, the readiness signal and the bridge. Nothing of the protocol lives here. ## How the SDK meets React Native @@ -37,14 +38,14 @@ This package keeps what is React Native's: which bundle the host loads, the relo ## Commands -| Command | Does | -| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `npm run lint` | ESLint, Prettier and SwiftLint | -| `npm run typecheck` | TypeScript | -| `npm test` | Vitest over the JavaScript | -| `npm run build` | the TypeScript into `dist/`; writes the SDK version from `package.json` into `SdkVersion.swift` and `SdkVersion.kt` and downloads the core's XCFramework, all ignored, so a fresh checkout runs it before opening the native projects | -| `npm run verify` | lint, typecheck, the Vitest tests and the build | -| `npm run verify:android` | Gradle builds, lints and unit-tests the Android library on its own, Robolectric; needs a JDK and the Android SDK | +| Command | Does | +| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `npm run lint` | ESLint, Prettier and SwiftLint | +| `npm run typecheck` | TypeScript | +| `npm test` | Vitest over the JavaScript | +| `npm run build` | the TypeScript into `dist/`; writes the SDK version from `package.json` into `SdkVersion.swift` and `SdkVersion.kt` and downloads the cores, the XCFramework and the Android Maven repository, all ignored, so a fresh checkout runs it before opening the native projects | +| `npm run verify` | lint, typecheck, the Vitest tests and the build | +| `npm run verify:android` | Gradle builds, lints and unit-tests the Android library on its own, Robolectric; needs a JDK and the Android SDK | Run `npm run fmt` before every commit. The iOS code compiles only inside an app: `ci.yml` builds the demo with the package from the commit, packed after `npm run build` so the pod carries the core; `benchmarks/prepare-demo.mjs` drops a core pod line the demo's Podfile still pins. The Android library also builds on its own: `android/settings.gradle` resolves React Native from the devDependency, so Codegen runs on the host, and `verify:android` runs its Robolectric tests in their own `ci.yml` job. diff --git a/README.md b/README.md index 1d59c16..b75ccd6 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ See [hotcodepush.com/docs/sdks/react-native](https://hotcodepush.com/docs/sdks/r ```sh nvm use npm ci -npm run build # the TypeScript into dist/ and the iOS core into ios/Frameworks; run it before opening the native projects +npm run build # the TypeScript into dist/ and the cores into ios/Frameworks and android/libs; run it before opening the native projects npm test npm run lint && npm run typecheck npm run verify:android # the Android library's build and Robolectric tests diff --git a/android/build.gradle b/android/build.gradle index 75717d9..8cee83a 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -35,19 +35,19 @@ kotlin { } } -// The core comes from core-android's maven branch at a pinned commit until the library is on Maven Central. +// The core comes from its release asset, which scripts/download-core-android.mjs unpacks into libs/m2, until the library is on Maven Central. repositories { google() mavenCentral() maven { - url 'https://raw.githubusercontent.com/hotcodepush-team/core-android/maven/' + url = file('libs/m2') content { includeGroup 'com.hotcodepush' } } } dependencies { implementation 'com.facebook.react:react-android' - implementation 'com.hotcodepush:core-android:a5bfc4aeede98739302f49510766a6f5decb9299' + implementation 'com.hotcodepush:core-android:0.1.0' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2' testImplementation 'junit:junit:4.13.2' testImplementation 'org.mockito:mockito-core:5.20.0' diff --git a/android/hotcodepush.gradle b/android/hotcodepush.gradle index 66b6b6e..d27fd0e 100644 --- a/android/hotcodepush.gradle +++ b/android/hotcodepush.gradle @@ -5,10 +5,10 @@ import javax.inject.Inject import org.apache.tools.ant.taskdefs.condition.Os import org.gradle.api.tasks.Optional -// The app resolves the core from core-android's maven branch until the library is on Maven Central. +// The app resolves the core from the package's local Maven repository beside this file until the library is on Maven Central. repositories { maven { - url 'https://raw.githubusercontent.com/hotcodepush-team/core-android/maven/' + url = new File(buildscript.sourceFile.parentFile, 'libs/m2') content { includeGroup 'com.hotcodepush' } } } diff --git a/package.json b/package.json index cc941a1..8a1fb1b 100644 --- a/package.json +++ b/package.json @@ -28,12 +28,14 @@ "files": [ "android/build.gradle", "android/hotcodepush.gradle", + "android/libs/m2/", "android/src/main/", "dist/", "ios/", "!ios/Frameworks/HotCodePushCore.checksum", "scripts/", "!scripts/*.test.ts", + "!scripts/download-core-android.mjs", "!scripts/download-core-ios.mjs", "!scripts/write-sdk-version.mjs", "src/", @@ -42,14 +44,14 @@ "HotcodepushReactNativeCodePush.podspec" ], "scripts": { - "build": "npm run clean && node scripts/write-sdk-version.mjs && node scripts/download-core-ios.mjs && tsc --project tsconfig.build.json", + "build": "npm run clean && node scripts/write-sdk-version.mjs && node scripts/download-core-android.mjs && node scripts/download-core-ios.mjs && tsc --project tsconfig.build.json", "clean": "rimraf ./dist", "fmt": "eslint . --fix && prettier --write . && swiftlint --fix --quiet ios", "lint": "eslint . && prettier --check . && swiftlint lint --quiet --strict ios", "test": "vitest run", "typecheck": "tsc --noEmit", "verify": "npm run lint && npm run typecheck && npm test && npm run build", - "verify:android": "node scripts/write-sdk-version.mjs && cd android && ./gradlew build --console=plain" + "verify:android": "node scripts/write-sdk-version.mjs && node scripts/download-core-android.mjs && cd android && ./gradlew build --console=plain" }, "codegenConfig": { "name": "HotCodePushSpec", @@ -65,6 +67,10 @@ } }, "hotcodepush": { + "coreAndroid": { + "version": "0.1.0", + "checksum": "7c9b91381c5c99bf9e2592fd14e912972f0bb8f3df1b0a3c340a75ca5ef3a65b" + }, "coreIos": { "url": "https://github.com/hotcodepush-team/core-ios/releases/download/0.3.0/HotCodePushCore.xcframework.zip", "checksum": "6d12e0613ce25748963f0ff492a6e33687a25bf291d94e2950d5b1867bbc3685" diff --git a/scripts/download-core-android.mjs b/scripts/download-core-android.mjs new file mode 100644 index 0000000..ff910e7 --- /dev/null +++ b/scripts/download-core-android.mjs @@ -0,0 +1,67 @@ +import { execFileSync } from 'node:child_process'; +import { createHash } from 'node:crypto'; +import { + existsSync, + mkdirSync, + readFileSync, + rmSync, + writeFileSync, +} from 'node:fs'; +import { tmpdir } from 'node:os'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +// Gradle cannot check a release asset's checksum before it resolves the core from it. +// So every build fetches the release asset that package.json pins under hotcodepush.coreAndroid, checks its checksum and unpacks it into the ignored local Maven repository that android/build.gradle and android/hotcodepush.gradle name. + +const packageDirectory = join(dirname(fileURLToPath(import.meta.url)), '..'); +const libsDirectory = join(packageDirectory, 'android/libs'); +const mavenDirectory = join(libsDirectory, 'm2'); +const checksumFile = join(libsDirectory, 'core-android.checksum'); + +const { version, checksum } = + JSON.parse(readFileSync(join(packageDirectory, 'package.json'), 'utf8')) + .hotcodepush?.coreAndroid ?? {}; +if (!version || !/^[0-9a-f]{64}$/.test(checksum ?? '')) { + throw new Error( + 'package.json names no hotcodepush.coreAndroid with a version and a checksum', + ); +} + +const [, gradleVersion] = + readFileSync(join(packageDirectory, 'android/build.gradle'), 'utf8').match( + /'com\.hotcodepush:core-android:([^']+)'/, + ) ?? []; +if (gradleVersion !== version) { + throw new Error( + `android/build.gradle names core-android ${gradleVersion}, package.json pins ${version}`, + ); +} + +if ( + existsSync(checksumFile) && + readFileSync(checksumFile, 'utf8') === checksum +) { + process.exit(0); +} + +const url = `https://github.com/hotcodepush-team/core-android/releases/download/${version}/core-android-${version}-maven.zip`; +const response = await fetch(url); +if (!response.ok) { + throw new Error(`${url} answered ${response.status}`); +} +const archive = Buffer.from(await response.arrayBuffer()); +const actualChecksum = createHash('sha256').update(archive).digest('hex'); +if (actualChecksum !== checksum) { + throw new Error( + `${url} has the checksum ${actualChecksum}, package.json pins ${checksum}`, + ); +} + +const archiveFile = join(tmpdir(), `core-android-${checksum}.zip`); +writeFileSync(archiveFile, archive); +rmSync(libsDirectory, { recursive: true, force: true }); +mkdirSync(mavenDirectory, { recursive: true }); +execFileSync('unzip', ['-q', archiveFile, '-d', mavenDirectory]); +rmSync(archiveFile); +writeFileSync(checksumFile, checksum); From 7c7e9ac69275a7579257343934876867da974ffd Mon Sep 17 00:00:00 2001 From: Robin Genz Date: Mon, 2 Nov 2026 07:54:46 +0100 Subject: [PATCH 2/2] docs: the release asset is the path, not a stop on the way to Maven Central Co-Authored-By: Claude Fable 5.1 --- android/build.gradle | 2 +- android/hotcodepush.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 8cee83a..4723534 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -35,7 +35,7 @@ kotlin { } } -// The core comes from its release asset, which scripts/download-core-android.mjs unpacks into libs/m2, until the library is on Maven Central. +// The core comes from its release asset, which scripts/download-core-android.mjs unpacks into libs/m2. repositories { google() mavenCentral() diff --git a/android/hotcodepush.gradle b/android/hotcodepush.gradle index d27fd0e..cd9c731 100644 --- a/android/hotcodepush.gradle +++ b/android/hotcodepush.gradle @@ -5,7 +5,7 @@ import javax.inject.Inject import org.apache.tools.ant.taskdefs.condition.Os import org.gradle.api.tasks.Optional -// The app resolves the core from the package's local Maven repository beside this file until the library is on Maven Central. +// The app resolves the core from the package's local Maven repository beside this file. repositories { maven { url = new File(buildscript.sourceFile.parentFile, 'libs/m2')