- buildDualScheduleConfig: set contentFetch timeout/retryAttempts/retryDelay (match capacitor DailyNotification networkConfig), userNotification.vibration, return type DualScheduleConfiguration - @timesafari/daily-notification-plugin 2.1.1 → 2.1.3 (package-lock) - doc: plugin feedback (contentFetch JSON, parseUserNotificationConfig optional fields) and Android DailyNotificationWorker duplicate scheduleId note
4.9 KiB
Plugin fix: Android compile error — duplicate scheduleId in handleDisplayNotification
Date: 2026-03-20
Target repo: @timesafari/daily-notification-plugin (daily-notification-plugin)
Consuming app: crowd-funder-for-time-pwa (TimeSafari)
Platform: Android (Java)
Summary
The Android module fails to compile with two javac errors: variable scheduleId is already defined in method handleDisplayNotification(String). The method already declares String scheduleId at the start of the try block; two nested blocks incorrectly redeclare String scheduleId, which Java forbids in the same method scope. Remove the redundant declarations and reuse the existing variable (or assign without String if you ever need to refresh it).
Problem
- File:
android/src/main/java/org/timesafari/dailynotification/DailyNotificationWorker.java - Method:
private Result handleDisplayNotification(String notificationId)
Compiler output (representative):
DailyNotificationWorker.java:162: error: variable scheduleId is already defined in method handleDisplayNotification(String)
String scheduleId = inputData.getString("schedule_id");
^
DailyNotificationWorker.java:193: error: variable scheduleId is already defined in method handleDisplayNotification(String)
String scheduleId = inputData.getString("schedule_id");
^
Root cause: At the top of the try block, the code already has:
Data inputData = getInputData();
String scheduleId = inputData.getString("schedule_id");
Later, inside:
- The
if (isStaticReminder) { ... }branch — a line likeString scheduleId = inputData.getString("schedule_id");(around line 162). - The
else { ... }branch — the same pattern (around line 193).
In Java, a local variable name cannot be declared again in nested blocks that share the enclosing method’s scope for that name. These inner String scheduleId lines are illegal and break :timesafari-daily-notification-plugin:compileDebugJavaWithJavac.
Functional note: Both inner reads use the same key ("schedule_id") as the outer declaration, so they add no new information; the fix is to delete those inner declarations and keep using scheduleId from the first assignment.
Required change
Option A (recommended): Delete the two redundant lines entirely:
- Remove the inner
String scheduleId = inputData.getString("schedule_id");in the static reminder branch (post-reboot/rollover comment block). - Remove the inner
String scheduleId = inputData.getString("schedule_id");in the regular notification branch (rollover/notify_* comment block).
All subsequent uses of scheduleId in those branches should continue to refer to the variable declared immediately after getInputData().
Option B (only if you must re-read input later): Replace redeclaration with assignment:
scheduleId = inputData.getString("schedule_id");
Do not prefix with String again inside the same method.
Verification
- Compile: From the plugin repo, run the Android Java compile for the library (or assemble debug). Expect zero errors for
DailyNotificationWorker.java. - Consuming app: Bump/publish the plugin version, update
package.jsonin TimeSafari,npm install,npx cap sync android, then run the usual Android debug build (e.g../scripts/build-android.sh --testorassembleDebug). The task:timesafari-daily-notification-plugin:compileDebugJavaWithJavacmust succeed. - Behavior: No intended behavior change:
schedule_idis still read once per worker run fromgetInputData()and used for dual-prefix checks, static reminder DB fallback, and canonical content byschedule_idin the non-static path.
Context (how this was found)
- Observed when running
npm run build:android:test:runon crowd-funder-for-time-pwa; Vite/TypeScript succeeded; Gradle failed on the plugin’s Java sources undernode_modules/.../DailyNotificationWorker.java. - Line numbers in published packages may drift slightly; search for
handleDisplayNotificationand duplicateString scheduleIdinside that method.
Cursor prompt (paste into plugin repo)
You can paste the block below into Cursor in the daily-notification-plugin workspace:
Fix Android compile errors in DailyNotificationWorker.java: in handleDisplayNotification(String notificationId), scheduleId is declared once after getInputData(). Remove the two illegal inner redeclarations "String scheduleId = inputData.getString(\"schedule_id\");" (static reminder branch and else branch). Reuse the outer scheduleId variable. Do not shadow or redeclare String scheduleId in the same method. Verify compileDebugJavaWithJavac passes.
After the fix
Release a new plugin version and update the consuming app’s dependency so node_modules is not hand-edited (edits there are lost on npm install).