2Btainment commited on
Commit
e4aa3f8
·
1 Parent(s): 2e7f3ce

fix(android): unique applicationId per Space, label APK target, accurate debug-signing notes, download attr

Browse files

- applicationId now com.spaceforge.<owner>.<space> (was first word only: hello_world -> com.spaceforge.hello, collision-prone)
- target label 'Android APK (Capacitor)' and listed before disabled stubs
- artifact notes: debug-signed (v1+v2 Android Debug cert) instead of 'unsigned'
- frontend: download attribute on artifact link, poll every 1.5s

backend/app/converters/mobile/android.py CHANGED
@@ -51,9 +51,39 @@ def _e(s: str) -> str:
51
  )
52
 
53
 
54
- def _app_id(slug: str) -> str:
55
- seg = _java_package(slug.replace("-", ""))
56
- return f"com.spaceforge.{seg}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
 
59
  class AndroidConverter(Converter):
@@ -65,7 +95,7 @@ class AndroidConverter(Converter):
65
  """
66
 
67
  id = "android"
68
- label = "Android (Capacitor)"
69
  mode = "hosted_wrapper"
70
  available = True
71
  stub = False
@@ -73,7 +103,8 @@ class AndroidConverter(Converter):
73
  async def convert(self, ctx: BuildContext) -> ConverterResult:
74
  info = ctx.space_info
75
  name = _slug(info["name"])
76
- app_id = _app_id(name)
 
77
  pkg_path = app_id.replace(".", "/")
78
  title = info.get("title") or info["repo_id"]
79
  embed = info.get("embed_url") or ""
 
51
  )
52
 
53
 
54
+ _JAVA_KEYWORDS = {
55
+ "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const",
56
+ "continue", "default", "do", "double", "else", "enum", "extends", "final", "finally", "float",
57
+ "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native",
58
+ "new", "package", "private", "protected", "public", "return", "short", "static", "strictfp",
59
+ "super", "switch", "synchronized", "this", "throw", "throws", "transient", "try", "void",
60
+ "volatile", "while", "true", "false", "null", "var", "record", "yield",
61
+ }
62
+
63
+
64
+ def _pkg_segment(raw: str) -> str:
65
+ """One valid Android/Java package segment (keeps the full name, '_' as separator)."""
66
+ seg = re.sub(r"[^a-z0-9]+", "_", (raw or "").lower()).strip("_")
67
+ seg = re.sub(r"_+", "_", seg)[:40].strip("_")
68
+ if not seg:
69
+ return ""
70
+ if seg[0].isdigit():
71
+ seg = "a" + seg
72
+ if seg in _JAVA_KEYWORDS:
73
+ seg += "_app"
74
+ return seg
75
+
76
+
77
+ def _app_id(slug: str, owner: str | None = None) -> str:
78
+ """Unique-ish applicationId: com.spaceforge.<owner>.<space_name>.
79
+
80
+ Previously only the first word of the name was used (hello_world -> com.spaceforge.hello),
81
+ so different Spaces could share one applicationId and overwrite each other on a device.
82
+ """
83
+ parts = [p for p in (_pkg_segment(owner or ""), _pkg_segment(slug)) if p]
84
+ if not parts:
85
+ parts = ["app"]
86
+ return "com.spaceforge." + ".".join(parts)
87
 
88
 
89
  class AndroidConverter(Converter):
 
95
  """
96
 
97
  id = "android"
98
+ label = "Android APK (Capacitor)"
99
  mode = "hosted_wrapper"
100
  available = True
101
  stub = False
 
103
  async def convert(self, ctx: BuildContext) -> ConverterResult:
104
  info = ctx.space_info
105
  name = _slug(info["name"])
106
+ owner = info.get("owner") or (info.get("repo_id") or "").split("/")[0]
107
+ app_id = _app_id(info.get("name") or name, owner)
108
  pkg_path = app_id.replace(".", "/")
109
  title = info.get("title") or info["repo_id"]
110
  embed = info.get("embed_url") or ""
backend/app/converters/mobile/finalize.py CHANGED
@@ -166,13 +166,13 @@ async def finalize_android(
166
  },
167
  "labeling": {
168
  "never_claim": "Local APK",
169
- "shipped_as": "debug package (Hosted Wrapper)" if apk_ready else "Hosted Wrapper project zip",
170
  },
171
  }
172
  (out_dir / "spaceforge.json").write_text(json.dumps(meta, indent=2) + "\n", encoding="utf-8")
173
 
174
  if apk_ready:
175
- ctx.info("Android SDK detected — running gradle assembleDebug (Hosted Wrapper debug; unsigned)")
176
  apk_file = await asyncio.to_thread(assemble_debug_apk, out_dir, ctx.info)
177
  if apk_file and apk_file.is_file() and apk_file.stat().st_size > 0:
178
  dest = ctx.work_dir / ("%s-android-debug.apk" % name)
@@ -195,8 +195,9 @@ async def finalize_android(
195
  mode=mode,
196
  media_type="application/vnd.android.package-archive",
197
  notes=(
198
- "Debug APK (unsigned) — Capacitor Hosted Wrapper WebView loads the live Space. "
199
- "Not a Local offline package of the model/GPU runtime."
 
200
  ),
201
  binary_included=True,
202
  ),
 
166
  },
167
  "labeling": {
168
  "never_claim": "Local APK",
169
+ "shipped_as": "debug-signed APK (Hosted Wrapper)" if apk_ready else "Hosted Wrapper project zip",
170
  },
171
  }
172
  (out_dir / "spaceforge.json").write_text(json.dumps(meta, indent=2) + "\n", encoding="utf-8")
173
 
174
  if apk_ready:
175
+ ctx.info("Android SDK detected — running gradle assembleDebug (Hosted Wrapper; debug-signed v1+v2)")
176
  apk_file = await asyncio.to_thread(assemble_debug_apk, out_dir, ctx.info)
177
  if apk_file and apk_file.is_file() and apk_file.stat().st_size > 0:
178
  dest = ctx.work_dir / ("%s-android-debug.apk" % name)
 
195
  mode=mode,
196
  media_type="application/vnd.android.package-archive",
197
  notes=(
198
+ "Debug APK (signed with Android debug key, v1+v2 — installable via sideload, "
199
+ "not for Play Store) — package %s. Capacitor Hosted Wrapper WebView loads %s. "
200
+ "Not a Local offline package of the model/GPU runtime." % (app_id, embed)
201
  ),
202
  binary_included=True,
203
  ),
backend/app/providers/huggingface.py CHANGED
@@ -218,27 +218,9 @@ def classify_compatibility(info: dict[str, Any]) -> dict[str, Any]:
218
  "artifact": "project-zip",
219
  "reason": "Generated Tauri + webview project (build binaries on your machine — not inside HF CPU).",
220
  },
221
- {
222
- "id": "linux_appimage",
223
- "label": "Linux AppImage",
224
- "mode": "local",
225
- "available": False,
226
- "stub": True,
227
- "artifact": "project-only",
228
- "reason": "Binary AppImage build not available in HF Space CPU environment. Use Tauri project locally.",
229
- },
230
- {
231
- "id": "windows_portable",
232
- "label": "Windows Portable",
233
- "mode": "local",
234
- "available": False,
235
- "stub": True,
236
- "artifact": "project-only",
237
- "reason": "Windows binary packaging not available inside HF Space. Generate Tauri project instead.",
238
- },
239
  {
240
  "id": "android",
241
- "label": "Android (Capacitor)",
242
  "mode": "hosted_wrapper",
243
  "available": True,
244
  "stub": False,
@@ -261,6 +243,24 @@ def classify_compatibility(info: dict[str, Any]) -> dict[str, Any]:
261
  "gpu_local": "no" if info.get("needs_gpu") else "warn",
262
  },
263
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  ]
265
 
266
  if not local_full:
 
218
  "artifact": "project-zip",
219
  "reason": "Generated Tauri + webview project (build binaries on your machine — not inside HF CPU).",
220
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  {
222
  "id": "android",
223
+ "label": "Android APK (Capacitor)" if _apk_env else "Android (Capacitor project)",
224
  "mode": "hosted_wrapper",
225
  "available": True,
226
  "stub": False,
 
243
  "gpu_local": "no" if info.get("needs_gpu") else "warn",
244
  },
245
  },
246
+ {
247
+ "id": "linux_appimage",
248
+ "label": "Linux AppImage",
249
+ "mode": "local",
250
+ "available": False,
251
+ "stub": True,
252
+ "artifact": "project-only",
253
+ "reason": "Binary AppImage build not available in HF Space CPU environment. Use Tauri project locally.",
254
+ },
255
+ {
256
+ "id": "windows_portable",
257
+ "label": "Windows Portable",
258
+ "mode": "local",
259
+ "available": False,
260
+ "stub": True,
261
+ "artifact": "project-only",
262
+ "reason": "Windows binary packaging not available inside HF Space. Generate Tauri project instead.",
263
+ },
264
  ]
265
 
266
  if not local_full:
frontend/src/App.tsx CHANGED
@@ -60,7 +60,7 @@ export default function App() {
60
  let status = await getBuild(build_id);
61
  setBuild(status);
62
  while (status.status === "queued" || status.status === "running") {
63
- await new Promise((r) => setTimeout(r, 600));
64
  status = await getBuild(build_id);
65
  setBuild(status);
66
  }
@@ -195,7 +195,7 @@ export default function App() {
195
  {art.filename} · {(art.size / 1024).toFixed(1)} KB · {art.notes}
196
  </div>
197
  </div>
198
- <a className="secondary" href={downloadUrl(build.id, tid)} style={{
199
  display: "inline-block",
200
  padding: ".55rem .9rem",
201
  borderRadius: 10,
 
60
  let status = await getBuild(build_id);
61
  setBuild(status);
62
  while (status.status === "queued" || status.status === "running") {
63
+ await new Promise((r) => setTimeout(r, 1500));
64
  status = await getBuild(build_id);
65
  setBuild(status);
66
  }
 
195
  {art.filename} · {(art.size / 1024).toFixed(1)} KB · {art.notes}
196
  </div>
197
  </div>
198
+ <a className="secondary" href={downloadUrl(build.id, tid)} download={art.filename} data-testid={`download-${tid}`} style={{
199
  display: "inline-block",
200
  padding: ".55rem .9rem",
201
  borderRadius: 10,