Skip to content

React Native

React Native apps (which contain android/ and ios/ sub-projects).

For a React Native project, alphyn-cli integrate:

  1. Declares the SDK dependency from the registry. It resolves the latest published version and pins @alphyn/react-native-sdk to it in package.json, and writes the authenticated .npmrc (the @alphyn scope plus a _authToken that reads ALPHYN_REGISTRY_KEY from the environment). No tarball is vendored. Run your package manager afterward (npm install / yarn / pnpm), then cd ios && pod install to link the SDK’s native pod into the iOS workspace.
  2. Adds initialization to your JS entry point (index.js) on a bare React Native project: a marker-bounded import and an AlphynSDK.initialize() call. (A managed Expo project is wired through the config plugin instead; see Expo.)
  3. Wires the iOS layer when an ios/ directory is present: it merges the required Info.plist keys (including the attestation-host ATS exception), adds the launch hook to the iOS AppDelegate, and installs the archive post-action into the app’s shared Xcode scheme, creating that scheme when the project has none, so archive builds always auto-register.
  4. Wires the Android layer when an android/ directory is present: it installs a Gradle build hook into android/app so every Android build auto-registers its app hash (the exact same hook a native Android project gets, so the platforms never drift), and registers the authenticated Alphyn package registry as a Maven repository in the android root build script’s allprojects.repositories. That repo registration is required: React Native’s Gradle plugin uses project-level repositories, so Gradle’s default repository mode ignores the SDK module’s own repo and :app cannot resolve the SDK AAR without it. (No native MainActivity init is added, since React Native starts the SDK from JavaScript.)
  5. Records the result in alphyn.json.

The SDK’s native binaries are no longer bundled in the npm package: the com.byterialab:alphyn-sdk AAR resolves from the Alphyn package registry through the Gradle repository above, and the iOS framework is fetched from the registry during pod install. Your build must supply your app API key as ALPHYN_REGISTRY_KEY. See SDK Registry Access:

Terminal window
export ALPHYN_REGISTRY_KEY=<YOUR_APP_API_KEY>

alphyn-cli new react-native scaffolds a starter by delegating to the React Native community CLI (npx @react-native-community/cli init), so Node and npx must be available.

Nothing to run manually. The iOS build registers at archive time via the post-action, and the Android build registers at build time via the Gradle hook, both installed by integrate; run alphyn-cli doctor to confirm they are wired. Pass --apk only to register a specific Android APK by hand (a split or App Bundle output the hook skips, or a CI step).

A React Native project enrolls under one portal app per platform, each with its own API key (see How to Register Your App). Give integrate both: --android-api-key (or --android-api-key-file) is the Android app’s key and --ios-api-key (or --ios-api-key-file) is the iOS app’s key; the generic --api-key is not accepted on a React Native project, so a build can never register under the other platform’s key. integrate writes each into a gitignored .alphyn/ key file that the Gradle hook and the Xcode archive post-action read automatically, so every build registers with no further setup. To override per build, point alphyn.api.key.file (Gradle) or ALPHYN_IOS_API_KEY_FILE (the Xcode archive environment) at a key file; for a manual register --apk, pass --android-api-key / --android-api-key-file. The backend accepts a registration only from the matching platform’s key.

During development an iOS app’s hash changes on every build and is never registered (iOS registration happens at archive time). Pin your app’s development debug hash from the dashboard (App Details) so npm run ios builds initialize the SDK:

Terminal window
alphyn-cli integrate --android-api-key <key> --ios-api-key <key> --ios-debug-hash <64-hex>

The hash is rendered into a __DEV__-guarded branch of the JS initialization, so a release bundle never carries it, and it is recorded in alphyn.json across re-runs. integrate also enrolls a development build signature with the backend (this uses the iOS app’s key), which a dev build needs before its first archive; SDK init in the dev loop then succeeds when the pinned hash matches the app’s dashboard debug hash. --android-debug-hash exists for the deliberate Android cases (a build environment without the hook, or pinning one specific registered build); normally the Gradle hook already registers every Android build.

The enrollment needs no build and no archive: it is a pure CLI call, and the development build signature appears in the dashboard as soon as it runs. register performs the same enrollment, so once the hash is pinned you can re-ensure it at any time without a full re-integrate (the pinned hash is recorded, so later runs need no flag; the iOS key comes from --ios-api-key or the provisioned .alphyn/ios-api.key):

Terminal window
alphyn-cli register --android-api-key <key>

The enrollment is idempotent, and alphyn-cli doctor reports the development build signature as enrolled. A real archive-time signature does not require the Xcode UI either: xcodebuild runs the same scheme post-action, so a terminal or CI archive registers itself (the usual signing requirements apply; a simulator build is not an archive):

Terminal window
cd ios
xcodebuild -workspace <App>.xcworkspace -scheme <AppScheme> -configuration Release \
-destination 'generic/platform=iOS' archive -archivePath build/App.xcarchive

The iOS launch hook requires a Swift AppDelegate. If your app still uses an Objective-C AppDelegate, doctor reports it clearly rather than installing a hook that would not run.

Confirms the package.json dependency and the authenticated .npmrc that resolves it, the JS initialization is present as real code, the iOS layer, the Android build hook and registry Maven repository (each when present), and the minSdk advisory. When a development debug hash is pinned, it also reports whether the development build signature is enrolled on the backend (advisory; it never fails the run).

Removes the package.json dependency and the managed .npmrc, the JS initialization, the iOS edits, the Android layer (build hook + registry Maven repository), any tarball it vendored, and alphyn.json.