@tokamakdev/platform-android-arm64 0.1.1-beta.55 → 0.1.1-beta.57

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
@@ -90,6 +115,24 @@ link_runtime() {
90
115
  "${libraries[@]}"
91
116
  }
92
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
+ }
135
+
93
136
  xml_escape() {
94
137
  printf '%s' "$1" |
95
138
  sed -e 's/&/\&amp;/g' \
@@ -151,15 +194,12 @@ for plugin in "$input/plugins"/*/; do
151
194
  cp "$plugin/AndroidManifest.xml" "$module/src/main/AndroidManifest.xml"
152
195
  fi
153
196
  {
154
- printf '%s\n' 'plugins {'
155
- printf '%s\n' " id 'com.android.library'"
156
- printf '%s\n' " id 'org.jetbrains.kotlin.android'"
197
+ printf '%s\n' 'plugins {' " id 'com.android.library'" " id 'org.jetbrains.kotlin.android'"
157
198
  printf '%s\n\n' '}'
158
199
  printf '%s\n' 'android {'
159
200
  printf " namespace 'tokamak.plugins.%s'\n" "${plugin_id//-/_}"
160
201
  printf '%s\n\n' '}'
161
- printf '%s\n' 'dependencies {'
162
- printf '%s\n' " implementation project(':tokamak-plugin')"
202
+ printf '%s\n' 'dependencies {' " implementation project(':tokamak-plugin')"
163
203
  for dependency in "$plugin/dependencies"/*; do
164
204
  printf " implementation '%s'\n" "$(cat "$dependency")"
165
205
  done
@@ -262,6 +302,15 @@ android {
262
302
  abortOnError true
263
303
  checkDependencies true
264
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
+ }
265
314
  }
266
315
 
267
316
  dependencies {
@@ -289,8 +338,7 @@ fi
289
338
  registry=$kotlin/TokamakPluginRegistry.kt
290
339
  {
291
340
  printf '%s\n\n' 'package com.tokamak.runtime'
292
- printf '%s\n' 'internal fun tokamakPlugins(host: TokamakHost): List<TokamakPlugin> ='
293
- printf '%s\n' ' listOf('
341
+ printf '%s\n' 'internal fun tokamakPlugins(host: TokamakHost): List<TokamakPlugin> =' ' listOf('
294
342
  for plugin in "$input/plugins"/*/; do
295
343
  printf ' %s(host),\n' "$(cat "$plugin/class")"
296
344
  done
@@ -318,16 +366,20 @@ manifest=$app/src/main/AndroidManifest.xml
318
366
  printf ' <meta-data android:name="tokamak.dev.endpoint" android:value="%s" />\n' "$dev_endpoint"
319
367
  printf ' <meta-data android:name="tokamak.dev.session-token" android:value="%s" />\n' "$dev_session_token"
320
368
  fi
321
- 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">'
322
- printf '%s\n' ' <intent-filter>'
323
- printf '%s\n' ' <action android:name="android.intent.action.MAIN" />'
324
- printf '%s\n' ' <category android:name="android.intent.category.LAUNCHER" />'
325
- printf '%s\n' ' </intent-filter>'
326
- printf '%s\n' ' </activity>'
327
- printf '%s\n' ' </application>'
328
- 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>'
329
378
  } > "$manifest"
330
379
 
331
- 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"
332
384
  mkdir -p "$(dirname "$output")"
333
- cp "$app/build/outputs/apk/debug/app-debug.apk" "$output"
385
+ cp "$app/build/outputs/apk/$variant/app-$variant.apk" "$output"
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/android-arm64/lib/TokamakRuntime/libtokamak.a
3
- size: 39086104 bytes
4
- sha256: 642a7fcdb133ba4e0d8f465e45e36027b187e39fd95b3a6b1166273885f55e44
3
+ size: 35040056 bytes
4
+ sha256: 2f5fc8703d5ea3594a52ae423c1ac3a89c5be4dd95d0dc6ac963b2a69e183946
@@ -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,
@@ -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.55",
3
+ "version": "0.1.1-beta.57",
4
4
  "description": "The tokamak platform pack for android-arm64",
5
5
  "repository": {
6
6
  "type": "git",