diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 93e2cf4..203230b 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -162,7 +162,7 @@ jobs: path: dist-electron/Paarrot-*.AppImage build-android: - runs-on: windows + runs-on: ubuntu-latest needs: increment-version if: always() && (needs.increment-version.outputs.should_build == 'true' || needs.increment-version.result == 'skipped') @@ -174,12 +174,10 @@ jobs: ref: ${{ github.ref_name }} - name: Checkout submodules manually - shell: powershell run: git submodule update --init --recursive - name: Pull latest (after version bump) if: github.ref == 'refs/heads/master' - shell: powershell run: git pull origin master - name: Setup Node.js @@ -187,18 +185,23 @@ jobs: with: node-version: '20' + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '21' + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + - name: Install dependencies (root) run: npm install --prefer-offline - name: Clean previous cinny dist - shell: powershell - run: | - if (Test-Path cinny/dist) { Remove-Item -Recurse -Force cinny/dist } + run: rm -rf cinny/dist - name: Apply overlay and build Android APK - run: npm run android:apk - env: - ANDROID_HOME: ${{ secrets.ANDROID_HOME }} + run: npm run android:apk:linux - name: Upload APK uses: actions/upload-artifact@v3 diff --git a/package.json b/package.json index 3a2f6e7..6540df7 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,11 @@ "android:open": "cd cinny && npx cap open android", "android:run": "cd cinny && npx cap run android", "android:apk": "npm run android:prepare && cd cinny/android && gradlew.bat assembleDebug && cd ../.. && node scripts/restore-cinny.mjs", + "android:apk:linux": "npm run android:prepare && cd cinny/android && ./gradlew assembleDebug && cd ../.. && node scripts/restore-cinny.mjs", "android:apk:release": "npm run android:prepare && cd cinny/android && gradlew.bat assembleRelease && cd ../.. && node scripts/restore-cinny.mjs", - "android:aab": "npm run android:prepare && cd cinny/android && gradlew.bat bundleRelease && cd ../.. && node scripts/restore-cinny.mjs" + "android:apk:release:linux": "npm run android:prepare && cd cinny/android && ./gradlew assembleRelease && cd ../.. && node scripts/restore-cinny.mjs", + "android:aab": "npm run android:prepare && cd cinny/android && gradlew.bat bundleRelease && cd ../.. && node scripts/restore-cinny.mjs", + "android:aab:linux": "npm run android:prepare && cd cinny/android && ./gradlew bundleRelease && cd ../.. && node scripts/restore-cinny.mjs" }, "keywords": [], "author": { diff --git a/scripts/apply-overlay.mjs b/scripts/apply-overlay.mjs index 98b5230..a0aac8c 100644 --- a/scripts/apply-overlay.mjs +++ b/scripts/apply-overlay.mjs @@ -7,7 +7,7 @@ * 3. Copies overlay/tsconfig.json into cinny/tsconfig.json * 4. Merges overlay/package-additions.json dependencies into cinny/package.json * 5. Copies capacitor.config.json (root) into cinny/capacitor.config.json with webDir reset to "dist" - * 6. Creates a Windows directory junction cinny/android -> root android/ so Capacitor can find it + * 6. Creates a cinny/android symlink/junction -> root android/ so Capacitor can find it * 7. Writes android/local.properties from ANDROID_HOME env var (so it works on any machine) * * Run before every Android build to keep the cinny submodule clean while layering @@ -97,28 +97,36 @@ const cinnyCapConfig = { ...rootCapConfig, webDir: 'dist' }; writeFileSync(join(CINNY, 'capacitor.config.json'), JSON.stringify(cinnyCapConfig, null, 2) + '\n', 'utf8'); console.log(` wrote cinny/capacitor.config.json (webDir: "dist")`); -// 6. Create a directory junction cinny/android -> root android/ so Capacitor CLI can find it -console.log('[apply-overlay] Setting up android/ junction...'); +// 6. Create cinny/android -> root android/ link so Capacitor CLI can find it +console.log('[apply-overlay] Setting up android/ link...'); const androidJunction = join(CINNY, 'android'); const androidTarget = resolve(ROOT, 'android'); if (!existsSync(androidJunction)) { - try { - execSync(`cmd /c mklink /J "${androidJunction}" "${androidTarget}"`, { stdio: 'pipe' }); - console.log(` created junction: cinny/android -> ${androidTarget}`); - } catch (err) { - console.warn(' mklink /J failed, falling back to directory copy...'); - copyDirRecursive(androidTarget, androidJunction); - console.log(` copied android/ into cinny/android/`); + if (process.platform === 'win32') { + try { + execSync(`cmd /c mklink /J "${androidJunction}" "${androidTarget}"`, { stdio: 'pipe' }); + console.log(` created junction: cinny/android -> ${androidTarget}`); + } catch (err) { + console.warn(' mklink /J failed, falling back to directory copy...'); + copyDirRecursive(androidTarget, androidJunction); + console.log(` copied android/ into cinny/android/`); + } + } else { + const { symlinkSync } = await import('fs'); + symlinkSync(androidTarget, androidJunction); + console.log(` created symlink: cinny/android -> ${androidTarget}`); } } else { - console.log(` android/ junction already exists, skipping`); + console.log(` android/ link already exists, skipping`); } // 7. Write android/local.properties with the current machine's Android SDK path const androidHome = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT; if (androidHome) { console.log('[apply-overlay] Writing android/local.properties...'); - const sdkDir = androidHome.replace(/\\/g, '\\\\'); + const sdkDir = process.platform === 'win32' + ? androidHome.replace(/\\/g, '\\\\') + : androidHome; writeFileSync(join(androidTarget, 'local.properties'), `sdk.dir=${sdkDir}\n`, 'utf8'); console.log(` sdk.dir=${androidHome}`); } else { diff --git a/scripts/restore-cinny.mjs b/scripts/restore-cinny.mjs index a8baebe..8aaf3ee 100644 --- a/scripts/restore-cinny.mjs +++ b/scripts/restore-cinny.mjs @@ -29,14 +29,18 @@ if (existsSync(capConfig)) { console.log('[restore-cinny] Removed cinny/capacitor.config.json'); } -// 3. Remove the android junction (rmdir only removes the junction, not the real directory) +// 3. Remove the android link (junction on Windows, symlink on Linux) const androidJunction = join(CINNY, 'android'); if (existsSync(androidJunction)) { try { - execSync(`cmd /c rmdir "${androidJunction}"`, { stdio: 'pipe' }); - console.log('[restore-cinny] Removed cinny/android junction'); + if (process.platform === 'win32') { + execSync(`cmd /c rmdir "${androidJunction}"`, { stdio: 'pipe' }); + } else { + unlinkSync(androidJunction); + } + console.log('[restore-cinny] Removed cinny/android link'); } catch (err) { - console.warn('[restore-cinny] Could not remove android junction:', err.message); + console.warn('[restore-cinny] Could not remove android link:', err.message); } }