{"record":{"id":"7fcc8977f4523b30","repo":"MuntashirAkon/AppManager","slug":"error-s-could-not-be-found-or-copied-n","errorCode":null,"errorMessage":"Error! %s could not be found or copied.\\n","messagePattern":"Error! (.+?) could not be found or copied\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"app/src/main/cpp/run_server.c","lineNumber":158,"sourceCode":"             main_jar_name);\n    snprintf(main_jar_fallbacks[3], sizeof(main_jar_fallbacks[3]), \"/storage/emulated/%s/AppManager/%s\",\n             user_id,\n             main_jar_name);\n\n    uid_t uid = getuid();\n    gid_t gid = getgid();\n    printf(\"Starting %s as %d:%d...\\n\", SERVER_NAME, uid, gid);\n\n    // Copy am.jar as /data/local/tmp/am.jar\n    const char *resolved_am_jar_path = NULL;\n    for (int i = 0; i < 4; i++) {\n        if (copy_file(am_jar_fallbacks[i], exec_jar_path) == 0) {\n            resolved_am_jar_path = am_jar_fallbacks[i];\n            break;\n        }\n    }\n    if (resolved_am_jar_path == NULL) {\n        fprintf(stderr, \"Error! %s could not be found or copied.\\n\", am_jar_name);\n        return 1;\n    }\n    // Fix ownership\n    if (chown(exec_jar_path, uid, gid) != 0) {\n        fprintf(stderr, \"Warning: chown failed: %s\\n\", strerror(errno));\n        // Although it failed, still proceed\n    }\n\n    // Copy main.jar as /data/local/tmp/main.jar\n    const char *resolved_main_jar_path = NULL;\n    for (int i = 0; i < 4; i++) {\n        if (copy_file(main_jar_fallbacks[i], main_jar_path) == 0) {\n            resolved_main_jar_path = main_jar_fallbacks[i];\n            break;\n        }\n    }\n    if (resolved_main_jar_path == NULL) {\n        fprintf(stderr, \"Error! %s could not be found or copied.\\n\", main_jar_name);","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/cpp/run_server.c#L140-L176","documentation":"Neither the pre-copied /data/local/tmp/<am_jar_name> nor any of the four /sdcard/Android/data/<app_id>/cache fallback paths could be located and copied into place (copy_file failed for all candidates and no valid direct path existed). resolved_am_jar_path stayed NULL, so the binary aborts.","triggerScenarios":"am.jar is absent from TMP_PATH and every fallback candidate path; copy_file fails on all fallbacks due to missing files or unreadable storage.","commonSituations":"First launch where the app never staged am.jar to its cache dir; /sdcard storage unmounted or scoped-storage restrictions hide the cache path; wrong app_id makes fallback paths point to a nonexistent package directory; am.jar deleted by a cleaner app.","solutions":["Ensure the app copies am.jar to its external cache (context.getExternalCacheDir) or /data/local/tmp before launching this binary","Verify app_id is correct so the /sdcard/Android/data/<app_id>/cache fallback paths are valid","Check that storage is mounted and readable; test with `ls` on the fallback paths via adb","Re-deploy/ship am.jar with the app and stage it on every launch"],"exampleFix":"// before\nexec(binary + \" \" + port + ...); // jar never staged\n// after\ncopyAssetToCache(\"am.jar\");\nexec(binary + \" \" + port + ...);","handlingStrategy":"fallback","validationCode":"File[] candidates = {new File(\"/data/local/tmp/am.jar\"),\n    new File(getExternalCacheDir(), \"am.jar\")};\nboolean staged = Arrays.stream(candidates).anyMatch(File::exists);\nif (!staged) copyAssetToCache(\"am.jar\");","typeGuard":null,"tryCatchPattern":"try {\n    runServer(...);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"could not be found or copied\")) {\n        stageJarFromAssets(\"am.jar\");\n        runServer(...); // retry once after staging\n    }\n}","preventionTips":["Always stage jars to the external cache dir before exec","Verify app_id matches the package name so /sdcard/Android/data/<app_id>/cache paths exist","Check storage mount state and permissions on first launch","Re-stage jars on every launch (cleaner apps may delete them)"],"tags":["file-not-found","filesystem","native"],"backgroundTag":"file-not-found","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}