Skip to content

Commit dc91211

Browse files
committed
Ensure Codename One stub activity manifest coverage
1 parent 9cd5bd8 commit dc91211

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

scripts/build-android-app.sh

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,13 @@ fi
312312

313313
MANIFEST_FILE="$APP_MODULE_DIR/src/main/AndroidManifest.xml"
314314
if [ ! -f "$MANIFEST_FILE" ]; then
315-
ba_log "AndroidManifest.xml not found at $MANIFEST_FILE" >&2
316-
exit 1
315+
mkdir -p "$(dirname "$MANIFEST_FILE")"
316+
cat >"$MANIFEST_FILE" <<'EOF'
317+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
318+
<application/>
319+
</manifest>
320+
EOF
321+
ba_log "Created minimal Android manifest at $MANIFEST_FILE"
317322
fi
318323

319324
ensure_manifest_stub() {
@@ -329,9 +334,12 @@ ns_android = "http://schemas.android.com/apk/res/android"
329334
ET.register_namespace('android', ns_android)
330335
tree = ET.parse(manifest_path)
331336
root = tree.getroot()
337+
changed = False
338+
332339
app = root.find('application')
333340
if app is None:
334-
sys.exit("Application element missing in AndroidManifest.xml")
341+
app = ET.SubElement(root, 'application')
342+
changed = True
335343
336344
target = f".{main_name}Stub"
337345
android_name = f"{{{ns_android}}}name"
@@ -346,6 +354,9 @@ else:
346354
activity.set(android_name, target)
347355
activity.set(android_exported, 'false')
348356
app.append(activity)
357+
changed = True
358+
359+
if changed:
349360
tree.write(manifest_path, encoding='utf-8', xml_declaration=True)
350361
PY
351362
}
@@ -376,6 +387,21 @@ if ! grep -q "android[[:space:]]*{" "$APP_BUILD_GRADLE"; then
376387
exit 1
377388
fi
378389

390+
chmod +x "$GRADLE_PROJECT_DIR/gradlew"
391+
392+
ba_log "Inspecting Gradle application identifiers"
393+
if APP_PROPERTIES_RAW=$(cd "$GRADLE_PROJECT_DIR" && ./gradlew -q :app:properties 2>/dev/null); then
394+
printf '%s\n' "$APP_PROPERTIES_RAW" | grep -E '^(applicationId|testApplicationId|namespace):' | \
395+
sed 's/^/[build-android-app] props: /'
396+
APP_ID=$(printf '%s\n' "$APP_PROPERTIES_RAW" | awk -F': ' '/^applicationId:/{print $2; exit}')
397+
if [ -n "$APP_ID" ] && [ "$APP_ID" != "$PACKAGE_NAME" ]; then
398+
ba_log "ERROR: applicationId=$APP_ID does not match Codename One package $PACKAGE_NAME" >&2
399+
exit 1
400+
fi
401+
else
402+
ba_log "Warning: unable to query :app:properties via Gradle" >&2
403+
fi
404+
379405
GRADLE_UPDATE_OUTPUT="$("$SCRIPT_DIR/update_android_ui_test_gradle.py" "$APP_BUILD_GRADLE")"
380406
if [ -n "$GRADLE_UPDATE_OUTPUT" ]; then
381407
while IFS= read -r line; do
@@ -394,7 +420,6 @@ if [ -n "${GITHUB_ENV:-}" ]; then
394420
fi
395421

396422
ba_log "Invoking Gradle build in $GRADLE_PROJECT_DIR"
397-
chmod +x "$GRADLE_PROJECT_DIR/gradlew"
398423
ORIGINAL_JAVA_HOME="$JAVA_HOME"
399424
export JAVA_HOME="$JAVA17_HOME"
400425
export PATH="$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/emulator:$PATH"
@@ -928,7 +953,14 @@ fi
928953

929954
MERGED_MANIFEST="$APP_MODULE_DIR/build/intermediates/packaged_manifests/debug/AndroidManifest.xml"
930955
if [ -f "$MERGED_MANIFEST" ]; then
931-
grep -n "${MAIN_NAME}Stub" "$MERGED_MANIFEST" | sed 's/^/[build-android-app] merged-manifest: /' || true
956+
if grep -q "${MAIN_NAME}Stub" "$MERGED_MANIFEST"; then
957+
grep -n "${MAIN_NAME}Stub" "$MERGED_MANIFEST" | sed 's/^/[build-android-app] merged-manifest: /' || true
958+
else
959+
ba_log "ERROR: merged manifest missing ${MAIN_NAME}Stub declaration"
960+
sed -n '1,200p' "$MERGED_MANIFEST" | sed 's/^/[build-android-app] merged-manifest: /'
961+
stop_emulator
962+
exit 1
963+
fi
932964
else
933965
ba_log "Merged manifest not found at $MERGED_MANIFEST"
934966
fi
@@ -1011,6 +1043,12 @@ if [ -n "$STUB_RESOLVE_OUTPUT" ]; then
10111043
else
10121044
ba_log "Unable to resolve stub activity $STUB_ACTIVITY_FQCN on device"
10131045
fi
1046+
if [[ "$STUB_RESOLVE_OUTPUT" == *"No activity found"* ]] || [ -z "$STUB_RESOLVE_OUTPUT" ]; then
1047+
ba_log "Stub activity $STUB_ACTIVITY_FQCN is not resolvable on the device"
1048+
dump_emulator_diagnostics
1049+
stop_emulator
1050+
exit 1
1051+
fi
10141052

10151053
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell am force-stop "$PACKAGE_NAME" >/dev/null 2>&1 || true
10161054
"$ADB_BIN" -s "$EMULATOR_SERIAL" shell am force-stop "${PACKAGE_NAME}.test" >/dev/null 2>&1 || true

0 commit comments

Comments
 (0)