@tokamakdev/platform-android-arm64 0.1.1-beta.54 → 0.1.1-beta.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,31 @@ if [[ -n "$dev_endpoint" && -z "$dev_session_token" ]] || [[ -z "$dev_endpoint"
29
29
  echo "development endpoint and session token must be provided together" >&2
30
30
  exit 1
31
31
  fi
32
+ # Development builds are debug builds. Other builds are release builds,
33
+ # which R8 shrinks and a configured keystore signs; without one, the debug
34
+ # key signs them so they install for testing. Gradle reads the keystore
35
+ # settings from the environment.
36
+ variant=release
37
+ task=Release
38
+ if [[ -n "$dev_endpoint" ]]; then
39
+ variant=debug
40
+ task=Debug
41
+ fi
42
+ signing=debug
43
+ if [[ "$variant" == release && -n "${TOKAMAK_ANDROID_KEYSTORE:-}" ]]; then
44
+ if [[ ! -f "$TOKAMAK_ANDROID_KEYSTORE" ]]; then
45
+ echo "Android keystore is missing: $TOKAMAK_ANDROID_KEYSTORE" >&2
46
+ exit 1
47
+ fi
48
+ if [[ -z "${TOKAMAK_ANDROID_KEY_ALIAS:-}" || -z "${TOKAMAK_ANDROID_KEYSTORE_PASSWORD:-}" ]]; then
49
+ echo "an Android keystore needs key-alias and keystore-password" >&2
50
+ exit 1
51
+ fi
52
+ signing=release
53
+ elif [[ "$variant" == release && -n "${TOKAMAK_ANDROID_KEY_ALIAS:-}${TOKAMAK_ANDROID_KEYSTORE_PASSWORD:-}${TOKAMAK_ANDROID_KEY_PASSWORD:-}" ]]; then
54
+ echo "Android key-alias and passwords need a keystore" >&2
55
+ exit 1
56
+ fi
32
57
  user_manifest=
33
58
  if [[ -n "${TOKAMAK_ANDROID_MANIFEST:-}" ]]; then
34
59
  user_manifest=$TOKAMAK_ANDROID_MANIFEST
@@ -45,6 +70,68 @@ kotlin=$app/src/main/kotlin/com/tokamak/runtime
45
70
  plugin_api=$project/tokamak-plugin
46
71
  plugin_modules=$project/plugins
47
72
  icons=$input/icons/$platform
73
+ # The oldest Android API level the app supports.
74
+ min_sdk=31
75
+
76
+ # The Android NDK's compiler, which links the runtime into the app.
77
+ android_linker() {
78
+ local ndk=${ANDROID_NDK_HOME:-}
79
+ local sdk_root=${ANDROID_HOME:-${ANDROID_SDK_ROOT:-}}
80
+ if [[ ! -d "$ndk" && -n "$sdk_root" && -d "$sdk_root/ndk" ]]; then
81
+ ndk=$(find "$sdk_root/ndk" -mindepth 1 -maxdepth 1 -type d -print | sort | tail -n 1)
82
+ fi
83
+ local compiler
84
+ for compiler in "$ndk"/toolchains/llvm/prebuilt/*/bin/aarch64-linux-android"$min_sdk"-clang; do
85
+ if [[ -x "$compiler" ]]; then
86
+ printf '%s' "$compiler"
87
+ return
88
+ fi
89
+ done
90
+ echo "Android builds link the tokamak runtime with the Android NDK, which is not installed." >&2
91
+ echo "Install it with Android Studio's SDK Manager (SDK Tools > NDK) or \`sdkmanager \"ndk;29.0.14206865\"\`, or set ANDROID_NDK_HOME." >&2
92
+ exit 1
93
+ }
94
+
95
+ # Link the runtime into libtokamak.so, exporting the JNI functions and the
96
+ # entry points of the runtime parts the app links.
97
+ link_runtime() {
98
+ local runtime=$input/runtime/TokamakRuntime
99
+ local exports=$project/tokamak-exports.map
100
+ local compiler libraries
101
+ compiler=$(android_linker)
102
+ {
103
+ printf '{\n global:\n Java_*;\n'
104
+ sed 's/.*/ &;/' "$metadata/exported-symbols"
105
+ printf ' local:\n *;\n};\n'
106
+ } > "$exports"
107
+ read -r -a libraries <<< "$(< "$runtime/link-libraries")"
108
+ "$compiler" -shared -o "$native/libtokamak.so" \
109
+ -Wl,-soname,libtokamak.so \
110
+ -Wl,--whole-archive "$runtime/libtokamak.a" -Wl,--no-whole-archive \
111
+ -Wl,--version-script="$exports" \
112
+ -Wl,--gc-sections -Wl,--as-needed -Wl,--eh-frame-hdr \
113
+ -Wl,-z,noexecstack -Wl,-z,relro,-z,now -Wl,-z,max-page-size=16384 \
114
+ -Wl,--strip-all \
115
+ "${libraries[@]}"
116
+ }
117
+
118
+ # The signing configuration for a keystore that signs release builds.
119
+ release_signing() {
120
+ if [[ "$signing" != release ]]; then
121
+ return
122
+ fi
123
+ cat <<'EOF'
124
+ signingConfigs {
125
+ release {
126
+ storeFile file(System.getenv('TOKAMAK_ANDROID_KEYSTORE'))
127
+ storePassword System.getenv('TOKAMAK_ANDROID_KEYSTORE_PASSWORD')
128
+ keyAlias System.getenv('TOKAMAK_ANDROID_KEY_ALIAS')
129
+ keyPassword System.getenv('TOKAMAK_ANDROID_KEY_PASSWORD') ?: System.getenv('TOKAMAK_ANDROID_KEYSTORE_PASSWORD')
130
+ }
131
+ }
132
+
133
+ EOF
134
+ }
48
135
 
49
136
  xml_escape() {
50
137
  printf '%s' "$1" |
@@ -58,7 +145,7 @@ xml_escape() {
58
145
  rm -rf "$app/src/main/assets" "$app/src/main/jniLibs" "$app/src/main/kotlin" "$app/src/main/res" "$app/user" "$plugin_api" "$plugin_modules" "$output"
59
146
  mkdir -p "$native" "$assets" "$kotlin" "$app/src/main/res" "$plugin_api/src/main/kotlin"
60
147
  cp -R "$input/app/." "$assets/"
61
- cp "$input/runtime/libtokamak.so" "$native/libtokamak.so"
148
+ link_runtime
62
149
  cp -R "$input/native-shell/app/." "$kotlin/"
63
150
  cp -R "$input/native-shell/plugin/." "$plugin_api/src/main/kotlin/"
64
151
  cat > "$plugin_api/build.gradle" <<'EOF'
@@ -107,15 +194,12 @@ for plugin in "$input/plugins"/*/; do
107
194
  cp "$plugin/AndroidManifest.xml" "$module/src/main/AndroidManifest.xml"
108
195
  fi
109
196
  {
110
- printf '%s\n' 'plugins {'
111
- printf '%s\n' " id 'com.android.library'"
112
- printf '%s\n' " id 'org.jetbrains.kotlin.android'"
197
+ printf '%s\n' 'plugins {' " id 'com.android.library'" " id 'org.jetbrains.kotlin.android'"
113
198
  printf '%s\n\n' '}'
114
199
  printf '%s\n' 'android {'
115
200
  printf " namespace 'tokamak.plugins.%s'\n" "${plugin_id//-/_}"
116
201
  printf '%s\n\n' '}'
117
- printf '%s\n' 'dependencies {'
118
- printf '%s\n' " implementation project(':tokamak-plugin')"
202
+ printf '%s\n' 'dependencies {' " implementation project(':tokamak-plugin')"
119
203
  for dependency in "$plugin/dependencies"/*; do
120
204
  printf " implementation '%s'\n" "$(cat "$dependency")"
121
205
  done
@@ -146,7 +230,7 @@ for plugin in "$input/plugins"/*/; do
146
230
  printf "include ':plugins:%s'\n" "$(basename "$plugin")" >> "$project/settings.gradle"
147
231
  done
148
232
 
149
- cat > "$project/build.gradle" <<'EOF'
233
+ cat > "$project/build.gradle" <<EOF
150
234
  plugins {
151
235
  id 'com.android.application' version '8.7.3' apply false
152
236
  id 'com.android.library' version '8.7.3' apply false
@@ -158,7 +242,7 @@ subprojects {
158
242
  android {
159
243
  compileSdk 35
160
244
  defaultConfig {
161
- minSdk 31
245
+ minSdk $min_sdk
162
246
  }
163
247
  sourceSets {
164
248
  main {
@@ -192,7 +276,7 @@ android {
192
276
 
193
277
  defaultConfig {
194
278
  applicationId '$identifier'
195
- minSdk 31
279
+ minSdk $min_sdk
196
280
  targetSdk 35
197
281
  versionCode 1
198
282
  versionName '$version'
@@ -218,6 +302,15 @@ android {
218
302
  abortOnError true
219
303
  checkDependencies true
220
304
  }
305
+
306
+ $(release_signing)
307
+ buildTypes {
308
+ release {
309
+ minifyEnabled true
310
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'tokamak-rules.pro'
311
+ signingConfig signingConfigs.$signing
312
+ }
313
+ }
221
314
  }
222
315
 
223
316
  dependencies {
@@ -245,8 +338,7 @@ fi
245
338
  registry=$kotlin/TokamakPluginRegistry.kt
246
339
  {
247
340
  printf '%s\n\n' 'package com.tokamak.runtime'
248
- printf '%s\n' 'internal fun tokamakPlugins(host: TokamakHost): List<TokamakPlugin> ='
249
- printf '%s\n' ' listOf('
341
+ printf '%s\n' 'internal fun tokamakPlugins(host: TokamakHost): List<TokamakPlugin> =' ' listOf('
250
342
  for plugin in "$input/plugins"/*/; do
251
343
  printf ' %s(host),\n' "$(cat "$plugin/class")"
252
344
  done
@@ -274,16 +366,20 @@ manifest=$app/src/main/AndroidManifest.xml
274
366
  printf ' <meta-data android:name="tokamak.dev.endpoint" android:value="%s" />\n' "$dev_endpoint"
275
367
  printf ' <meta-data android:name="tokamak.dev.session-token" android:value="%s" />\n' "$dev_session_token"
276
368
  fi
277
- printf '%s\n' ' <activity android:name=".TokamakActivity" android:exported="true" android:launchMode="singleTask" android:theme="@android:style/Theme.Material.NoActionBar" android:configChanges="colorMode|density|fontScale|keyboard|keyboardHidden|layoutDirection|locale|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode">'
278
- printf '%s\n' ' <intent-filter>'
279
- printf '%s\n' ' <action android:name="android.intent.action.MAIN" />'
280
- printf '%s\n' ' <category android:name="android.intent.category.LAUNCHER" />'
281
- printf '%s\n' ' </intent-filter>'
282
- printf '%s\n' ' </activity>'
283
- printf '%s\n' ' </application>'
284
- printf '%s\n' '</manifest>'
369
+ printf '%s\n' \
370
+ ' <activity android:name=".TokamakActivity" android:exported="true" android:launchMode="singleTask" android:theme="@android:style/Theme.Material.NoActionBar" android:configChanges="colorMode|density|fontScale|keyboard|keyboardHidden|layoutDirection|locale|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode">' \
371
+ ' <intent-filter>' \
372
+ ' <action android:name="android.intent.action.MAIN" />' \
373
+ ' <category android:name="android.intent.category.LAUNCHER" />' \
374
+ ' </intent-filter>' \
375
+ ' </activity>' \
376
+ ' </application>' \
377
+ '</manifest>'
285
378
  } > "$manifest"
286
379
 
287
- gradle --no-daemon :app:lintDebug :app:assembleDebug --project-dir "$project"
380
+ # R8 keeps every name, so class names in errors and stack traces stay real.
381
+ printf '%s\n' '-dontobfuscate' > "$app/tokamak-rules.pro"
382
+
383
+ gradle --no-daemon ":app:lint$task" ":app:assemble$task" --project-dir "$project"
288
384
  mkdir -p "$(dirname "$output")"
289
- cp "$app/build/outputs/apk/debug/app-debug.apk" "$output"
385
+ cp "$app/build/outputs/apk/$variant/app-$variant.apk" "$output"
@@ -0,0 +1,4 @@
1
+ [diffend] Oversized file quarantined before diffing.
2
+ name: package/android-arm64/lib/TokamakRuntime/libtokamak.a
3
+ size: 35040056 bytes
4
+ sha256: 2f5fc8703d5ea3594a52ae423c1ac3a89c5be4dd95d0dc6ac963b2a69e183946
@@ -0,0 +1 @@
1
+ -ldl -llog -lunwind -ldl -lm -lc -llog
@@ -122,8 +122,7 @@ class TokamakActivity : Activity() {
122
122
  ) return@runOnUiThread
123
123
  result
124
124
  .onSuccess { port ->
125
- if (port != runtime.port) return@onSuccess
126
- if (port != proxyPort) {
125
+ if (port == runtime.port && port != proxyPort) {
127
126
  proxyPort = port
128
127
  TokamakProxy.acquire(this, tokamak.appHost, port)
129
128
  }
@@ -46,7 +46,8 @@ internal class TokamakPluginBridge(
46
46
  val request = runCatching { JSONObject(message.data ?: return) }.getOrNull() ?: return
47
47
  val session = request.optString("session")
48
48
  if (session.isEmpty()) return
49
- if (request.optString("type") == "reset") {
49
+ val type = request.optString("type")
50
+ if (type == "reset") {
50
51
  close()
51
52
  activeSession = session
52
53
  return
@@ -54,49 +55,40 @@ internal class TokamakPluginBridge(
54
55
  val id = request.optInt("id", -1)
55
56
  if (id < 0) return
56
57
  val key = RequestKey(session, id)
57
- when (request.optString("type")) {
58
+ when (type) {
58
59
  "cancel" -> cancellations.remove(key)?.invoke()
59
- "call", "subscribe" -> dispatch(request, key, replyProxy)
60
- else ->
61
- send(
62
- replyProxy,
63
- key,
64
- Result.failure(
65
- TokamakPluginError.notSupported("Plugin operation is not supported"),
66
- ),
67
- true,
68
- )
60
+ "call", "subscribe" -> dispatch(request, type == "call", key, replyProxy)
61
+ else -> sendNotSupported(replyProxy, key, "Plugin operation is not supported")
69
62
  }
70
63
  }
71
64
 
72
65
  private fun dispatch(
73
66
  request: JSONObject,
67
+ isCall: Boolean,
74
68
  key: RequestKey,
75
69
  replyProxy: JavaScriptReplyProxy,
76
70
  ) {
77
71
  val plugin = plugins[request.optString("plugin")]
78
72
  val method = request.optString("method")
79
73
  if (plugin == null || method.isEmpty()) {
80
- send(
81
- replyProxy,
82
- key,
83
- Result.failure(TokamakPluginError.notSupported("Plugin is not supported")),
84
- true,
85
- )
74
+ sendNotSupported(replyProxy, key, "Plugin is not supported")
86
75
  return
87
76
  }
88
77
  val arguments = request.opt("arguments")
89
- val reply: TokamakPluginReply = { result ->
90
- send(replyProxy, key, result, request.optString("type") == "call")
91
- }
92
- if (request.optString("type") == "call") {
78
+ val reply: TokamakPluginReply = { result -> send(replyProxy, key, result, isCall) }
79
+ if (isCall) {
93
80
  plugin.call(method, arguments, reply)
94
81
  } else {
95
- val cancellation = plugin.subscribe(method, arguments, reply)
96
- cancellations[key] = cancellation
82
+ cancellations[key] = plugin.subscribe(method, arguments, reply)
97
83
  }
98
84
  }
99
85
 
86
+ private fun sendNotSupported(
87
+ replyProxy: JavaScriptReplyProxy,
88
+ key: RequestKey,
89
+ message: String,
90
+ ) = send(replyProxy, key, Result.failure(TokamakPluginError.notSupported(message)), true)
91
+
100
92
  private fun send(
101
93
  replyProxy: JavaScriptReplyProxy,
102
94
  key: RequestKey,
@@ -4,7 +4,7 @@
4
4
  "artifacts": [
5
5
  {
6
6
  "kind": "runtimeLibrary",
7
- "path": "bin/libtokamak.so"
7
+ "path": "lib/TokamakRuntime"
8
8
  },
9
9
  {
10
10
  "kind": "nativeShellDirectory",
@@ -19,6 +19,22 @@
19
19
  "gradle"
20
20
  ],
21
21
  "variables": {
22
+ "key-alias": {
23
+ "kind": "string",
24
+ "description": "Alias of the signing key in the keystore"
25
+ },
26
+ "key-password": {
27
+ "kind": "string",
28
+ "description": "Password of the signing key; defaults to the keystore password"
29
+ },
30
+ "keystore": {
31
+ "kind": "path",
32
+ "description": "Keystore that signs release builds; without one, the debug key signs them"
33
+ },
34
+ "keystore-password": {
35
+ "kind": "string",
36
+ "description": "Password of the keystore"
37
+ },
22
38
  "manifest": {
23
39
  "kind": "path",
24
40
  "description": "Partial AndroidManifest.xml merged over the generated manifest"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/platform-android-arm64",
3
- "version": "0.1.1-beta.54",
3
+ "version": "0.1.1-beta.56",
4
4
  "description": "The tokamak platform pack for android-arm64",
5
5
  "repository": {
6
6
  "type": "git",
Binary file