Back to Browse

Use with your AI agent

  1. Install — run npx skills add Kali-Decoder/Midnight-skills --skill android-example-voting for this skill, or npx skills add Kali-Decoder/Midnight-skills for all
  2. Prompt — copy the example prompt and paste it into Cursor, Claude Code, or Codex
  3. Build — the agent loads this skill and scaffolds your Midnight work

Android Example Voting

Full-Fledged TemplatesIntermediateReviewedUpdated 3 days agov1.0.0

Agent picks this when: Build a voting/poll dApp on Midnight targeting Android

Build a voting/poll dApp on Midnight Network using the Kuira Android SDK — Compact smart contract with create/cast/close circuits, passkey-derived identity, embedded wallet, Compose UI, reactive ledger reads via observeLedger(), and on-device ZK proving.

Good for

  • Build a voting/poll dApp on Midnight using the Kuira Android SDK.
  • Compact smart contract, passkey-derived identity, embedded wallet, Compose UI, on-device ZK proving.

Preview in agent

Suggested prompts

Build a voting/poll dApp on Midnight targeting Android. Use the "android-example-voting" skill from MIDSKILLS. Follow Compact smart-contract best practices, wire wallet flows where needed, and explain each step as you implement. Target Midnight Preprod unless I specify otherwise.

Loaded skill android-example-voting

What the skill guides the agent to do:

  1. Build a voting/poll dApp on Midnight using the Kuira Android SDK.
  2. Compact smart contract, passkey-derived identity, embedded wallet, Compose UI, on-device ZK proving.

Illustrative — based on the skill's description, not recorded agent output.

Try it without installing: npx skills use Kali-Decoder/Midnight-skills@android-example-voting

What changed in v1.0.16

All registry changes

Updated since v1.0.14: +6 −1956 lines.

Show diff
SKILL.md+6−1956
@@ -168,1987 +168,37 @@  ## 3) Gradle Configuration -### 3.1) `gradle.properties` — **REQUIRED**--Without this file, Gradle uses defaults that make the build extremely-slow or break the configuration cache:--```properties-android.useAndroidX=true-android.nonTransitiveRClass=true-kotlin.code.style=official--org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8-org.gradle.caching=true-org.gradle.parallel=true-org.gradle.configuration-cache=true-```--**Failure mode:** Without `android.useAndroidX=true`, the SDK's-`AppCompatActivity` dependency resolves to the old support library and-fails at runtime with `ClassNotFoundException`.--**Failure mode:** Without `org.gradle.jvmargs=-Xmx2048m`, KSP+Hilt-together can OOM on large-ish projects. Bump to `-Xmx4096m` if you see-`OutOfMemoryError: Metaspace`.--**Failure mode:** `org.gradle.configuration-cache=true` will break if-your `app/build.gradle.kts` accesses project files at configuration-time (e.g., `file("../contract")`). The Copy tasks below avoid this by-using `rootProject.file()` with `doFirst`, but if you add a plugin-that reads files during evaluation, disable configuration cache.--### 3.2) `settings.gradle.kts`--```kotlin-pluginManagement {-    repositories {-        google {-            content {-                includeGroupByRegex("com\\.android.*")-                includeGroupByRegex("com\\.google.*")-                includeGroupByRegex("androidx.*")-            }-        }-        mavenCentral()-        gradlePluginPortal()-    }-}--dependencyResolutionManagement {-    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)-    repositories {-        google()-        mavenCentral()-    }-}--rootProject.name = "kuira-starter-android"-include(":app")-```--**Gotcha:** `FAIL_ON_PROJECT_REPOS` means you CANNOT declare-`repositories { ... }` inside `app/build.gradle.kts`. If a library-isn't in google() or mavenCentral(), add it to-`dependencyResolutionManagement` here.--### 3.3) Root `build.gradle.kts`--```kotlin-plugins {-    alias(libs.plugins.android.application) apply false-    alias(libs.plugins.kotlin.android) apply false-    alias(libs.plugins.kotlin.compose) apply false-    alias(libs.plugins.ksp) apply false-    alias(libs.plugins.hilt) apply false-}-```--Note: The Kuira contract plugin (`io.github.kuiralabs.contract`) and-localnet plugin (`io.github.kuiralabs.localnet`) are applied by ID and-version directly in `app/build.gradle.kts`, not through the version-catalog. They do NOT appear here.--### 3.4) `gradle/libs.versions.toml`--```toml-[versions]-agp = "8.13.2"-kotlin = "2.3.20"-ksp = "2.3.6"-hilt = "2.58"-composeBom = "2026.03.01"--androidxAppcompat = "1.7.0"-androidxActivity = "1.10.1"-androidxFragment = "1.8.5"-androidxLifecycle = "2.8.7"-androidxHiltNavCompose = "1.1.0"-androidxSecurityCrypto = "1.1.0-alpha07"--kuira = "0.1.0-alpha04"--[libraries]-androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppcompat" }-androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidxActivity" }-androidx-fragment-ktx = { group = "androidx.fragment", name = "fragment-ktx", version.ref = "androidxFragment" }-androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "androidxLifecycle" }-androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" }-androidx-hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "androidxHiltNavCompose" }-androidx-security-crypto = { group = "androidx.security", name = "security-crypto", version.ref = "androidxSecurityCrypto" }--androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }-androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }-androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }-androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }-androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }--hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }-hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt" }--kuira-dapp-ui = { group = "io.github.kuiralabs", name = "dapp-ui", version.ref = "kuira" }--[plugins]-android-application = { id = "com.android.application", version.ref = "agp" }-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }-kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }-ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }-hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }-```--**Version pinning rules:**-- AGP and Gradle wrapper MUST match major.minor: AGP 8.13.x ↔ Gradle 8.13-- Kotlin and KSP MUST match exactly: Kotlin 2.3.20 ↔ KSP 2.3.6-- Compose BOM and Compose compiler plugin are coupled via-  `kotlin-compose` plugin — do NOT set a compose-compiler version manually-- Hilt and ksp-hilt must match the Hilt version (the ksp artifact-  resolves transitively, no explicit dep needed)--### 3.5) `app/build.gradle.kts`--```kotlin-import org.jetbrains.kotlin.gradle.dsl.JvmTarget--plugins {-    alias(libs.plugins.android.application)-    alias(libs.plugins.kotlin.android)-    alias(libs.plugins.kotlin.compose)-    alias(libs.plugins.ksp)-    alias(libs.plugins.hilt)-    id("io.github.kuiralabs.contract") version "0.1.0-alpha04"-    id("io.github.kuiralabs.localnet") version "0.1.0-alpha04"-}--android {-    namespace = "com.kuiralabs.starter.counter"-    compileSdk = 36--    defaultConfig {-        applicationId = "com.kuiralabs.starter.counter"-        minSdk = 30-        targetSdk = 36-        versionCode = 1-        versionName = "0.1.0"-    }--    buildTypes {-        debug { isMinifyEnabled = false }-        release { isMinifyEnabled = false }-    }--    compileOptions {-        sourceCompatibility = JavaVersion.VERSION_17-        targetCompatibility = JavaVersion.VERSION_17-    }--    buildFeatures { compose = true }-}--kotlin {-    compilerOptions { jvmTarget.set(JvmTarget.JVM_17) }-}--kuiraContract {-    source.set("../contract/src/managed/voting")-    bundleWalletKeys.set(true)-}--// Hand-rolled Copy to sync voting contract assets (the plugin handles-// the primary source; this is explicit for clarity and matches the-// starter codebase pattern):-tasks.register<Copy>("syncVotingAssets") {-    description = "Sync compiled Voting compact contract artifacts into app assets."-    group = "build"-    from("../contract/src/managed/voting/contract") {-        include("index.js")-        rename { "voting-contract.js" }-        into("runtime")-    }-    from("../contract/src/managed/voting/keys") {-        include("*.prover", "*.verifier")-        into("keys")-    }-    from("../contract/src/managed/voting/zkir") {-        include("*.bzkir")-        into("keys")-    }-    into("src/main/assets")-    doFirst {-        if (!file("../contract/src/managed/voting").exists()) {-            throw GradleException("Contract not compiled — run `npm run compile:voting` in contract/ first.")-        }-    }-}--tasks.named("preBuild") { dependsOn("syncVotingAssets") }--dependencies {-    implementation(libs.kuira.dapp.ui)--    val composeBom = platform(libs.androidx.compose.bom)-    implementation(composeBom)-    androidTestImplementation(composeBom)-    implementation(libs.androidx.compose.material3)-    implementation(libs.androidx.compose.ui)-    implementation(libs.androidx.compose.ui.tooling.preview)-    debugImplementation(libs.androidx.compose.ui.tooling)--    implementation(libs.androidx.appcompat)-    implementation(libs.androidx.activity.compose)-    implementation(libs.androidx.fragment.ktx)-    implementation(libs.androidx.lifecycle.runtime.ktx)-    implementation(libs.androidx.lifecycle.viewmodel.compose)-    implementation(libs.androidx.hilt.navigation.compose)-    implementation(libs.androidx.security.crypto)-    implementation(libs.hilt.android)-    ksp(libs.hilt.compiler)-}-```--**Plugin details:**--`io.github.kuiralabs.contract` — processes the `kuiraContract { ... }`-block. It:-1. Registers `validateKuiraContractSource` — fails the build with a-   clear message if `../contract/src/managed/voting` doesn't exist-2. Registers `syncContractAssets` — copies JS + keys into-   `src/main/assets/{runtime,keys}/`-3. Wires `syncContractAssets` into `preBuild`-4. The `bundleWalletKeys.set(true)` flag makes the plugin copy-   `.bzkir` bundle files into assets during the bundle task--`io.github.kuiralabs.localnet` — auto-runs `adb reverse` for the-localnet ports on physical devices during `installDebug`. No-op on-emulators (they use `10.0.2.2`).--**Why both plugin and Copy task?** The `kuiraContract` plugin handles-the primary source automatically (syncing JS + keys + bundleWalletKeys).-The hand-rolled `Copy` task exists in the starter codebase as an-explicit parallel sync. For this skill, the plugin alone is sufficient;-the Copy task is provided for clarity.--**Failure mode:** If `minSdk < 30`, the SDK fails at runtime because-it depends on `android.security.identity.IdentityCredential` (API 30+)-and `CredentialManager` (API 34+, with API 30+ fallback path).--**Failure mode:** If `compileSdk != 36` or `targetSdk != 36`, the-Kuira SDK's `WalletNotifications.PERMISSION` constant (`POST_NOTIFICATIONS`-added API 33, behavior change in API 34) may not resolve correctly.-Keep compileSdk = 36.+Full content: [references/gradle-configuration.md](references/gradle-configuration.md). It covers version catalog, root/app `build.gradle.kts`, settings, and the Kuira SDK dependency wiring. Open it when you reach this step.  ---  ## 4) Android Resources -### 4.1) `app/src/main/res/values/strings.xml`--```xml-<?xml version="1.0" encoding="utf-8"?>-<resources>-    <string name="app_name">Kuira Starter</string>-</resources>-```--### 4.2) `app/src/main/res/values/themes.xml`--```xml-<?xml version="1.0" encoding="utf-8"?>-<resources>-    <style name="Theme.KuiraStarter" parent="Theme.AppCompat.DayNight.NoActionBar">-        <item name="windowActionBar">false</item>-        <item name="windowNoTitle">true</item>-        <item name="android:windowBackground">@android:color/black</item>-    </style>-</resources>-```--**Why AppCompat parent?** `MainActivity` extends `AppCompatActivity`-(not `ComponentActivity`) because the SDK's `SigilStatusPanel` hosts-a biometric prompt internally. The prompt requires a `FragmentActivity`-— `AppCompatActivity` satisfies that; `ComponentActivity` does not.-The theme XML must have a compatible parent.--### 4.3) `app/src/main/res/xml/network_security_config.xml`--```xml-<?xml version="1.0" encoding="utf-8"?>-<network-security-config>-    <domain-config cleartextTrafficPermitted="true">-        <domain includeSubdomains="true">localhost</domain>-        <domain includeSubdomains="true">127.0.0.1</domain>-        <domain includeSubdomains="true">10.0.2.2</domain>-    </domain-config>-    <base-config cleartextTrafficPermitted="false" />-</network-security-config>-```--**Prefer this over `android:usesCleartextTraffic="true"`** in the-manifest. Both work on localnet, but this approach doesn't open-cleartext to the whole internet for the debug build. If you use the-debug manifest approach (see §4.5), it's enabled only for the `debug`-build type, so it's also safe.--### 4.4) Main `AndroidManifest.xml`--```xml-<?xml version="1.0" encoding="utf-8"?>-<manifest xmlns:android="http://schemas.android.com/apk/res/android">--    <uses-permission android:name="android.permission.INTERNET" />--    <application-        android:name=".KuiraStarterApp"-        android:allowBackup="false"-        android:icon="@mipmap/ic_launcher"-        android:label="@string/app_name"-        android:networkSecurityConfig="@xml/network_security_config"-        android:supportsRtl="true"-        android:theme="@style/Theme.KuiraStarter">--        <activity-            android:name=".MainActivity"-            android:exported="true"-            android:label="@string/app_name"-            android:theme="@style/Theme.KuiraStarter">-            <intent-filter>-                <action android:name="android.intent.action.MAIN" />-                <category android:name="android.intent.category.LAUNCHER" />-            </intent-filter>-        </activity>-    </application>-</manifest>-```--**Network config:** The `android:networkSecurityConfig` attribute-pointing to `@xml/network_security_config` allows cleartext to-localhost/emulator host for localnet without globally enabling it.--### 4.5) Debug manifest (alternative to network_security_config)--`app/src/debug/AndroidManifest.xml`:-```xml-<?xml version="1.0" encoding="utf-8"?>-<manifest xmlns:android="http://schemas.android.com/apk/res/android">-    <application android:usesCleartextTraffic="true" />-</manifest>-```--Merge rules: the debug manifest is merged into the main manifest for-debug builds only. It's simpler than the security config approach but-opens cleartext to ALL hosts, not just localnet.--**Failure mode:** If you use both `networkSecurityConfig` AND-`usesCleartextTraffic="true"`, the security config wins. If the-config doesn't include the right domain, cleartext still fails.+Full content: [references/android-resources.md](references/android-resources.md). It covers manifest, strings, themes, and other `res/` files. Open it when you reach this step.  ---  ## 5) Contract -### 5.1) `contract/package.json`--```json-{-  "name": "@yourapp/voting-contract",-  "version": "0.1.0",-  "private": true,-  "description": "Voting contract for the Kuira Voting dApp. Compiled artifacts under src/managed/voting/ are consumed by the Android app via the kuiraContract Gradle plugin.",-  "scripts": {-    "compile:voting": "compact compile +0.36.1 src/voting.compact src/managed/voting && node scripts/patch-voting.js",-    "inspect:voting": "mn contract inspect --managed src/managed/voting"-  },-  "dependencies": {-    "@midnight-ntwrk/compact-runtime": "0.21.0"-  },-  "engines": {-    "compactc": "0.36.1"

Diff truncated — view the full change in the registry repository.

On this page · 30 sections
SKILL.md

Kuira Voting dApp

This skill generates a runnable voting dApp for Midnight Network using the Kuira Android SDK. Every snippet below is taken directly from the working starter-android codebase. If the build fails, read the Failure Modes sections — they cover the three most common things that go wrong.

Primary references:

  • https://kuiralabs.github.io/kuira-sdk-android/ — Kuira SDK docs
  • https://kuiralabs.github.io/kuira-sdk-android/api/ — Dokka API reference
  • https://github.com/kuiralabs/kuira-starter-android — official starter
  • https://central.sonatype.com/namespace/io.github.kuiralabs — Maven Central

What this builds

CapabilityHow
Forge sigilPanelBar — one biometric creates passkey-DID + wallet
Deploy contractDeploy the Compact contract to Midnight
Create pollOrganizer-only via SHA-256 admin key match
Cast voteSelect one of 4 options, ZK-proved on-device
Close pollOnly the admin key holder can close
Live resultsobserveLedger() streams state changes reactively

Pinned Versions

Ledger 9 status (21 Nov 2026) — NEEDS CHECK against Kuira. The contract side below is updated to the Ledger 9.1 toolchain: voting.compact compiles with Compact 0.36.1 (language 0.28.0) for runtime 0.21.0. The Kuira SDK is not. Its newest release is 0.1.0-alpha05 (Maven Central, July 2026), which predates the Ledger 9 upgrade. Kuira's embedded wallet, on-device prover and localnet are Ledger 8-era until Kuira ships a Ledger 9 build. Mainnet stopped decoding Ledger 8 transactions on 6 Nov 2026, and Preview relaunched as a new Ledger 9 chain on 7 Nov 2026. Until then, this app cannot transact on public networks, and its runtime pin must match whatever runtime the Kuira build embeds (see §9). Check the Kuira release notes before relying on it.

These are the versions from the working codebase, with the contract toolchain moved to Ledger 9. Deviating on the Gradle side causes dependency resolution failures (see §9).

LayerVersion
Kuira SDK (io.github.kuiralabs:dapp-ui)0.1.0-alpha04
Kuira Contract plugin0.1.0-alpha04
Kuira Localnet plugin0.1.0-alpha04
AGP8.13.2
Kotlin2.3.20
KSP2.3.6
Hilt2.58
Compose BOM2026.03.01
Gradle8.13
JDK17
compileSdk / targetSdk36
minSdk30
appcompat1.7.0
activity-compose1.10.1
fragment-ktx1.8.5
hilt-navigation-compose1.1.0
security-crypto1.1.0-alpha07
@midnight-ntwrk/compact-runtime@midnight-ntwrk/[email protected] (from references/versions.json)
Compact compilercompact compile +0.36.1 (from references/versions.json)
Compact language pragmapragma language_version >= 0.28.0

1) Project Structure

kuira-starter-android/
├── settings.gradle.kts
├── build.gradle.kts               # Root (plugin declarations only)
├── gradle.properties               # MUST exist — jvmargs, caching
├── gradle/
│   ├── libs.versions.toml
│   └── wrapper/
│       └── gradle-wrapper.properties  # Gradle 8.13
├── local.properties                # sdk.dir — NOT committed
├── contract/
│   ├── package.json
│   ├── scripts/
│   │   └── patch-voting.js
│   └── src/
│       ├── voting.compact
│       └── managed/voting/         # Compiled artifacts (gitignored)
├── app/
│   ├── build.gradle.kts
│   └── src/
│       ├── main/
│       │   ├── AndroidManifest.xml
│       │   ├── res/
│       │   │   ├── values/
│       │   │   │   ├── strings.xml
│       │   │   │   └── themes.xml
│       │   │   ├── xml/
│       │   │   │   └── network_security_config.xml
│       │   │   ├── drawable/
│       │   │   │   ├── ic_launcher_foreground.xml
│       │   │   │   └── ic_launcher_background.xml
│       │   │   └── mipmap-anydpi-v26/
│       │   │       └── ic_launcher.xml
│       │   └── java/com/kuiralabs/starter/counter/
│       │       ├── KuiraStarterApp.kt
│       │       ├── MainActivity.kt
│       │       ├── di/PasskeyConfigModule.kt
│       │       ├── data/
│       │       │   ├── VotingContract.kt
│       │       │   └── ContractAddressStore.kt
│       │       └── ui/
│       │           ├── theme/{Color,Type,Theme}.kt
│       │           ├── VotingScreen.kt
│       │           ├── VotingCard.kt
│       │           ├── VotingViewModel.kt
│       │           └── VotingUiState.kt
│       └── debug/AndroidManifest.xml   # Cleartext for localnet

Warning: local.properties must exist with sdk.dir=... or the AGP android block can't resolve compileSdk. Android Studio creates it; in CI you must create it manually or use an env var.


2) Prerequisites

2.1) Toolchain

java --version               # JDK 17+
node --version                # Node.js 18+
compact update 0.36.1         # Install Compact compiler
compact list                  # Verify 0.36.1 is installed (the compile script pins +0.36.1)

2.2) Android Setup

  • Android Studio Ladybug+
  • Device/emulator Android 13+ (API 33+) with screen lock set
  • Domain for passkey rpId (or use GitHub Pages)
  • Google Password Manager (GMS Core 23.40.13+)

2.3) Gradle wrapper

The wrapper at gradle/wrapper/gradle-wrapper.properties must specify Gradle 8.13 (matching AGP 8.13.2):

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

3) Gradle Configuration

Full content: references/gradle-configuration.md. It covers version catalog, root/app build.gradle.kts, settings, and the Kuira SDK dependency wiring. Open it when you reach this step.


4) Android Resources

Full content: references/android-resources.md. It covers manifest, strings, themes, and other res/ files. Open it when you reach this step.


5) Contract

Full content: references/contract.md. It covers the voting Compact contract (create/cast/close circuits) and how it is compiled and bundled into the app. Open it when you reach this step.


6) Application & DI

Full content: references/application-di.md. It covers the Application class and dependency-injection setup. Open it when you reach this step.


7) Data Layer

Full content: references/data-layer.md. It covers repositories, wallet/identity plumbing, and reactive ledger reads via observeLedger(). Open it when you reach this step.


8) UI Layer

Full content: references/ui-layer.md. It covers every Compose screen, view model, and navigation file. Open it when you reach this step.


9) Failure Modes & Troubleshooting

9.1) Build failures

SymptomCauseFix
Could not find method kuiraContract()io.github.kuiralabs.contract plugin not appliedCheck the plugin ID and version in app/build.gradle.kts
Cannot access class 'com.midnight.kuira.*'Kuira dep not resolvedCheck mavenCentral() in settings.gradle.kts, verify kuira version in catalog
[Dagger/MissingBinding] PasskeyConfigNo PasskeyConfigModuleCreate the module (§6.2)
OutOfMemoryError: MetaspaceNot enough JVM heapBump org.gradle.jvmargs to -Xmx4096m
Configuration cache state found but cache is disabledChanged config cache setting mid-projectDelete ~/.gradle/configuration-cache/ and rebuild
Could not find required SDK platform API 36SDK platform not installedInstall Android SDK Platform 36
java.lang.RuntimeException: Cannot load contract JSAsset not syncedRun ./gradlew :app:assembleDebug to trigger kuiraContract sync
IllegalStateException: Contract not compiled at .../managed/votingkuiraContract.validateKuiraContractSource failingRun npm run compile:voting in contract/

9.2) Runtime failures

SymptomCauseFix
"Could not find module '@midnight-ntwrk/compact-runtime'"Runtime version mismatchCheck contract-info.json vs package.json (§5.1)
CircuitExecutionException: Only admin can close pollWrong witness valueThe hardcoded ADMIN_SECRET matches or it doesn't. No recovery from a different device.
CircuitExecutionException: Poll is closedAlready closedWait for next poll — no reopen circuit exists
TypeError: optionIdx_0 is not a functionBigInt patch failedCheck patch-voting.js matches the generated JS (§5.2)
SessionLock attach failedCalled from wrong lifecycleCall in Application.onCreate(), not Activity.onCreate()
WalletNotifications.shouldRequest crash on API < 33Runtime check not guardedThe SDK handles this internally; if it crashes, you may have minSdk < 30
NullPointerException on readLedger before createPolladminKeyHash is undefinedHandle VotingLedger.adminKeyHash being all-zeros or null in UI
App shows "Forge a sigil" but user already has oneSDK state resetClear app data and re-forge, or check logcat for SigilStateProvider errors

9.3) Network failures

SymptomCauseFix
java.net.ConnectException: Connection refusedLocalnet not runningRun mn localnet up
javax.net.ssl.SSLHandshakeExceptionCleartext blocked on localnetAdd 10.0.2.2 to network_security_config.xml (§4.3) or use debug manifest (§4.5)
RP_ID_MISMATCHPasskey domain changedDelete credential in Google Password Manager, re-forge
INSUFFICIENT_DUSTWallet not fundedAirdrop NIGHT and register dust (§10.2)
Transaction pending foreverIndexer not syncedWait for observeLedger() to emit or check indexer health

9.4) Contract compilation failures

SymptomCauseFix
Error: Unknown compiler version +0.36.1compactc not installed at that versioncompact update 0.36.1
Could not find package '@midnight-ntwrk/compact-runtime'npm deps not installedcd contract && npm install
Syntax error: expected ';'Language version mismatchCheck pragma language_version matches toolchain
The compiler cannot find moduleImport path issueEnsure contract-info.json paths are relative

9.5) Gradle version catalog gotchas

  • Kotlin ↔ KSP version coupling: Kotlin 2.3.20 requires KSP 2.3.6. If you upgrade Kotlin to 2.3.21, you MUST also find and upgrade KSP to the matching version. The KSP version format is <kotlin-version>-<ksp-release>.

  • AppCompat 1.7.x requires fragment-ktx 1.8.x — mixing a newer appcompat with an older fragment causes NoSuchMethodError: Fragment.getParentFragmentManager().

  • AGP ↔ Gradle coupling: AGP 8.13 requires Gradle 8.13. If you change the wrapper distribution URL, the buildscript classpath will fail.

  • Compose BOM and compiler: The kotlin-compose plugin in Kotlin 2.0+ replaces the old composeOptions { kotlinCompilerExtensionVersion } block. Do NOT set a compose compiler version manually — the BOM and plugin coordinate automatically.


10) Wallet & Deploy Flow

10.1) Prerequisite: Passkey domain

  1. Pick a domain you control (e.g., yourname.github.io)
  2. Upload assetlinks.json to https://<domain>/.well-known/
  3. Set PASSKEY_RP_ID in PasskeyConfigModule.kt

10.2) Wallet funding (localnet)

  1. Open app, tap Forge sigil in the wallet panel
  2. Copy wallet address from the wallet panel
  3. Airdrop NIGHT:
    mn airdrop 1000 --wallet <addr> --network undeployed
    
  4. In app, tap Register dust in the wallet panel
  5. Wait ~30 seconds for dust sync
  6. Tap Deploy contract

10.3) Using the app

  1. Create poll: Enter question + options (comma-separated), tap "Create poll". Wait for the transaction to confirm.
  2. Cast vote: Tap an option card. The ContractCallProgressBar shows ZK proving progress. After success, the "You Voted" badge appears and tallies update.
  3. Close poll: Tap "Close poll" (only works on the device that deployed). After close, the "Closed" badge appears and voting is disabled.
  4. Switch network: Use the network selector in PanelBar. Each network has its own deployed contract address.
  5. Disconnect: Clears the persisted address, returns to deploy screen.

11) Testing & Verification

Localnet flow

# Start localnet (Docker stack)
mn localnet up

# Compile contract
cd contract && npm install && npm run compile:voting

# Install + run
cd .. && ./gradlew :app:installDebug

Verify APK assets

./gradlew :app:assembleDebug
unzip -l app/build/outputs/apk/debug/app-debug.apk | grep voting
# Expected:
#   assets/runtime/voting-contract.js
#   assets/keys/createPoll.verifier
#   assets/keys/castVote.verifier
#   assets/keys/closePoll.verifier
#   assets/keys/createPoll.prover
#   assets/keys/castVote.prover
#   assets/keys/closePoll.prover
#   assets/keys/*.bzkir    (if bundleWalletKeys is enabled)

Pre-release check

./gradlew kuiraDoctor

Catches: missing PasskeyConfig binding, unhosted assetlinks.json, stale contract artifacts, missing assets.


12) Toolchain Bump Procedure

When compactc, the language version, or @midnight-ntwrk/compact-runtime updates:

  1. compact update <new-version> and compact list to confirm
  2. Bump engines.compactc in contract/package.json
  3. Bump @midnight-ntwrk/compact-runtime in contract/package.json
  4. CRITICAL: Update the +<version> pin in compile:voting script
  5. Check scripts/patch-voting.js against newly generated JS — variable names may have changed
  6. rm -rf src/managed/voting && npm run compile:voting
  7. Verify runtime version in contract-info.json matches package.json
  8. ./gradlew :app:assembleDebug to trigger asset resync
  9. Run the localnet flow to verify deploy + createPoll + castVote + closePoll all work
  10. ./gradlew kuiraDoctor
  11. Commit regenerated artifacts

13) SDK APIs Used

APIPurpose
MidnightSdkProviderInjected singleton providing MidnightSdk + network selection
MidnightContract.create(config) { }Build contract handle with name, JS, address, verifier keys, witnesses
.deploy(onProgress)Deploy contract, returns DeployResult (.contractAddress)
.call(circuit, vararg args, onProgress)Call a circuit — circuit assert failure throws CircuitExecutionException
.ledger()Read current on-chain state, returns typed MidnightLedger
.observeLedger()Reactive Flow<MidnightLedger> — emits current state then each change
MidnightLedger.getBoolean/getString/getStringOrNull/getUint64/getBytes(n, size)Typed ledger field accessors
ProvingKeyManager.installCircuitKeysFromAssets()Stage proving keys from assets for on-device proving
PanelBar(floating = true, network, onNetworkChange)Drop-in floating sigil + wallet pills
WalletAppShell { }Root wrapper — SessionLockGate + WalletOverlayHost
ContractCallProgressBar(stage, accent)Built-in progress for deploy/call stages
WalletForegroundService.attach(this)Background wallet ops survive app backgrounding
SessionLock.attach(this) / .onUserActivity()App-wide auto-lock + idle-timer reset
WalletNotifications.shouldRequest(this) / PERMISSIONPOST_NOTIFICATIONS gating for API 33+
MidnightSdk.coinPublicKeyThe wallet's public key needed for write handles
WitnessResult(null, bytes)Witness provider returning a static byte array

14) References

Start in 2 steps

  1. 1. Install — one skill or the full set
  2. 2. Prompt — paste the example into your agent

Install all skills (recommended)

npx skills add Kali-Decoder/Midnight-skills

One command adds every Midnight skill to Cursor, Claude Code, and similar agents.

Install this skill only

npx skills add Kali-Decoder/Midnight-skills --skill android-example-voting

Installs only "android-example-voting" into every detected agent (Cursor, Claude Code, Codex, …).

Example agent prompt

Build a voting/poll dApp on Midnight targeting Android. Use the "android-example-voting" skill from MIDSKILLS. Follow Compact smart-contract best practices, wire wallet flows where needed, and explain each step as you implement. Target Midnight Preprod unless I specify otherwise.

Paste into Cursor, Claude Code, or Codex after installing.

Author
Tusharpamnani
Category
Full-Fledged Templates
Difficulty
intermediate
Version
v1.0.0

Tags

AndroidVotingKuira

Files included

SKILL.md
Create Social CardLive HackathonsGallery
Mock Demo
Android Example Voting