Repository navigation
108 lines (91 loc) · 5.38 KB
/
Copy pathandroid.yml
File metadata and controls
108 lines (91 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Build Android APK
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- run: npm install --legacy-peer-deps
- run: npm install --legacy-peer-deps @capacitor/core @capacitor/cli @capacitor/android @capacitor/filesystem @capacitor/share @capacitor/local-notifications @capacitor/status-bar @capacitor/splash-screen @capacitor/assets
- run: npm run build
- run: npm install --no-save --legacy-peer-deps typescript@5.6.3
- name: Add Android platform
run: |
if [ ! -d android ]; then npx cap add android; fi
# Generates ALL native Android app icons from your assets/icon.png
- name: Generate App Icons and Splash
run: npx @capacitor/assets generate --android
# Uses Python to safely inject your Base64 image without hitting the OS text limit
- name: Inject Animated Splash into Web Build
run: |
cat << 'EOF' > inject-splash.py
import base64
import os
paths = ['dist/index.html', 'www/index.html', 'build/index.html']
target = next((p for p in paths if os.path.exists(p)), None)
if target:
with open('assets/icon.png', 'rb') as f:
b64 = base64.b64encode(f.read()).decode('utf-8')
with open(target, 'r', encoding='utf-8') as f:
html = f.read()
splash = '<div id="gh-splash" style="position:fixed;top:0;left:0;width:100vw;height:100vh;background:#000;z-index:9999;display:flex;justify-content:center;align-items:center;transition:opacity 0.5s ease-out;"><img src="data:image/png;base64,' + b64 + '" style="width:150px;height:150px;animation:ghPulse 1.5s infinite alternate;" /></div>'
splash += '<style>@keyframes ghPulse{from{transform:scale(0.9);opacity:0.8}to{transform:scale(1.1);opacity:1}}</style>'
splash += '<script>window.addEventListener("load",()=>{setTimeout(()=>{const e=document.getElementById("gh-splash");if(e){e.style.opacity="0";setTimeout(()=>e.remove(),500)}},2000)})</script>'
html = html.replace('</body>', splash + '</body>')
with open(target, 'w', encoding='utf-8') as f:
f.write(html)
print('Splash injected successfully into ' + target)
else:
print('Could not find index.html')
EOF
python3 inject-splash.py
- name: Fix status bar and gesture bar overlap
run: |
F=$(find android/app/src/main/java -name MainActivity.java | head -n 1)
PKG=$(grep -m1 '^package ' "$F" | sed 's/package //; s/;//')
cat > "$F" <<EOF
package $PKG;
import android.os.Bundle;
import android.view.View;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import com.getcapacitor.BridgeActivity;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setBackgroundColor(0xFF121212);
WindowCompat.getInsetsController(getWindow(), getWindow().getDecorView()).setAppearanceLightStatusBars(false);
View root = findViewById(android.R.id.content);
ViewCompat.setOnApplyWindowInsetsListener(root, (v, insets) -> {
Insets bars = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
v.setPadding(bars.left, bars.top, bars.right, bars.bottom);
return WindowInsetsCompat.CONSUMED;
});
}
}
EOF
- name: Force Native Splash Screen Background to Black
run: |
mkdir -p android/app/src/main/res/values
echo '<?xml version="1.0" encoding="utf-8"?><resources><color name="splashBackground">#000000</color></resources>' > android/app/src/main/res/values/colors.xml
sed -i 's|<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">|<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">\n <item name="windowSplashScreenBackground">@color/splashBackground</item>|' android/app/src/main/res/values/styles.xml
- name: Add permissions
run: |
grep -q POST_NOTIFICATIONS android/app/src/main/AndroidManifest.xml || sed -i 's|<application|<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>\n <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32"/>\n <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32"/>\n <application|' android/app/src/main/AndroidManifest.xml
- run: npx cap sync android
- run: cd android && chmod +x gradlew && ./gradlew assembleDebug
- uses: actions/upload-artifact@v4
with:
name: app-debug
path: android/app/build/outputs/apk/debug/app-debug.apk