162 lines
4.4 KiB
Markdown
162 lines
4.4 KiB
Markdown
# Fix Notifikasi untuk Release Build
|
|
|
|
## Masalah
|
|
Notifikasi tidak muncul pada aplikasi release (APK yang sudah di-install), padahal berfungsi normal saat debug.
|
|
|
|
## Penyebab
|
|
1. **ProGuard/R8 Code Shrinking**: Pada release build, Android secara otomatis menghapus kode yang dianggap tidak digunakan, termasuk komponen notifikasi plugin.
|
|
2. **Minify Enabled**: Setting minifyEnabled di build.gradle menyebabkan code shrinking aktif.
|
|
|
|
## Solusi yang Diterapkan
|
|
|
|
### 1. File `proguard-rules.pro` (BARU)
|
|
File ini berisi rules untuk mencegah ProGuard menghapus kode notifikasi:
|
|
- Keep Flutter plugin classes
|
|
- Keep flutter_local_notifications classes
|
|
- Keep Android notification components
|
|
- Keep MQTT client classes
|
|
|
|
### 2. Update `build.gradle.kts`
|
|
Menambahkan konfigurasi:
|
|
```kotlin
|
|
isMinifyEnabled = false // Disable code shrinking
|
|
isShrinkResources = false // Disable resource shrinking
|
|
proguardFiles(...) // ProGuard rules (untuk jika diaktifkan nanti)
|
|
```
|
|
|
|
### 3. Update `MainActivity.kt`
|
|
Menambahkan pembuatan notification channel saat aplikasi start:
|
|
- Membuat channel "pengering_ikan_channel"
|
|
- Set importance ke HIGH
|
|
- Enable vibration dan lights
|
|
|
|
## Cara Build Ulang Aplikasi
|
|
|
|
### Option 1: Build APK (Tanpa minify - Recommended)
|
|
```bash
|
|
flutter clean
|
|
flutter pub get
|
|
flutter build apk --release
|
|
```
|
|
APK akan ada di: `build/app/outputs/flutter-apk/app-release.apk`
|
|
|
|
### Option 2: Build APK (Dengan minify + ProGuard)
|
|
Jika ingin APK lebih kecil, edit `build.gradle.kts`:
|
|
```kotlin
|
|
isMinifyEnabled = true
|
|
isShrinkResources = true
|
|
```
|
|
Lalu build:
|
|
```bash
|
|
flutter clean
|
|
flutter pub get
|
|
flutter build apk --release
|
|
```
|
|
|
|
### Option 3: Build App Bundle (untuk Google Play)
|
|
```bash
|
|
flutter clean
|
|
flutter pub get
|
|
flutter build appbundle --release
|
|
```
|
|
AAB akan ada di: `build/app/outputs/bundle/release/app-release.aab`
|
|
|
|
## Testing Notifikasi
|
|
|
|
### 1. Uninstall aplikasi lama
|
|
```bash
|
|
adb uninstall com.example.aplikasi_novil
|
|
```
|
|
|
|
### 2. Install APK baru
|
|
```bash
|
|
adb install build/app/outputs/flutter-apk/app-release.apk
|
|
```
|
|
|
|
### 3. Test notifikasi
|
|
- Buka aplikasi
|
|
- Pastikan permission notifikasi sudah di-allow (Android 13+)
|
|
- Jalankan proses pengeringan
|
|
- Tunggu hingga selesai
|
|
- Notifikasi harus muncul
|
|
|
|
### 4. Check via Logcat
|
|
```bash
|
|
adb logcat | grep -i notification
|
|
```
|
|
|
|
## Verifikasi Permission
|
|
|
|
### Check di Settings Android:
|
|
1. Buka **Settings > Apps > Pengering Ikan**
|
|
2. Pilih **Notifications**
|
|
3. Pastikan notifikasi **ENABLED**
|
|
4. Check channel "Pengering Ikan" harus ada
|
|
|
|
### Check via ADB:
|
|
```bash
|
|
adb shell dumpsys notification_listener
|
|
adb shell cmd notification list
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Notifikasi masih tidak muncul?
|
|
|
|
1. **Check permission di runtime:**
|
|
- Aplikasi harus request permission POST_NOTIFICATIONS untuk Android 13+
|
|
- Sudah di-handle di `NotificationService.initialize()`
|
|
|
|
2. **Check notification channel:**
|
|
- Channel harus dibuat di native (MainActivity.kt) ✅
|
|
- Channel ID harus sama dengan yang di Dart ✅
|
|
|
|
3. **Check battery optimization:**
|
|
- Buka Settings > Battery > Battery Optimization
|
|
- Set aplikasi ke "Don't optimize"
|
|
|
|
4. **Check Do Not Disturb:**
|
|
- Pastikan DND mode tidak aktif
|
|
- Atau allow aplikasi bypass DND
|
|
|
|
5. **Test dengan notification sederhana:**
|
|
Tambahkan button test notifikasi di UI untuk memastikan sistem notifikasi bekerja.
|
|
|
|
## Files yang Diubah/Ditambahkan
|
|
|
|
### Baru:
|
|
- ✅ `android/app/proguard-rules.pro`
|
|
|
|
### Diubah:
|
|
- ✅ `android/app/build.gradle.kts`
|
|
- ✅ `android/app/src/main/kotlin/com/example/aplikasi_novil/MainActivity.kt`
|
|
|
|
### Tidak berubah (sudah benar):
|
|
- ✅ `android/app/src/main/AndroidManifest.xml` (permission sudah lengkap)
|
|
- ✅ `lib/services/notification_service.dart` (channel ID sudah benar)
|
|
|
|
## Catatan Penting
|
|
|
|
1. **Setiap kali build release**, pastikan:
|
|
- `flutter clean` dulu
|
|
- `flutter pub get`
|
|
- Uninstall APK lama sebelum install yang baru
|
|
|
|
2. **minifyEnabled = false** akan membuat APK lebih besar (~10-20MB lebih besar)
|
|
- Tapi notifikasi dijamin bekerja
|
|
- Jika ingin APK lebih kecil, gunakan minify + ProGuard rules
|
|
|
|
3. **Testing harus di device fisik**, bukan emulator
|
|
- Emulator kadang tidak akurat untuk notifikasi
|
|
|
|
4. **Versi Android yang didukung:**
|
|
- Android 5.0+ (API 21+) untuk notifikasi dasar
|
|
- Android 8.0+ (API 26+) untuk notification channels
|
|
- Android 13+ (API 33+) perlu permission POST_NOTIFICATIONS
|
|
|
|
## Kontak
|
|
Jika masih ada masalah, check:
|
|
1. Logcat untuk error messages
|
|
2. Notification settings di Android
|
|
3. Battery optimization settings
|