🔖 หมวดบทเรียน: การเตรียมแอป Flutter สำหรับเผยแพร่จริง
📌 เหมาะสำหรับ: นักพัฒนาที่เตรียมส่งแอปขึ้น Play Store / App Store
🎯 เป้าหมาย: รู้กระบวนการ build release ที่ปลอดภัย เบา และพร้อมใช้งานจริง
🧭 เกริ่นนำ
การนำแอป Flutter ไปเผยแพร่จริง (production) ต้องเตรียมการหลายขั้น เช่นการ sign app เพื่อความปลอดภัย, ลดขนาดด้วย obfuscation และทำ build ให้เหมาะกับ release โดยไม่รวม debug code หรือ resource ที่ไม่จำเป็น
🔐 การ Signing (Android)
- สร้างไฟล์ key:
keytool -genkey -v -keystore my-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-key
- เพิ่มไฟล์
key.properties
storePassword=xxxx
keyPassword=xxxx
keyAlias=my-key
storeFile=../my-key.jks
- แก้ไฟล์
android/app/build.gradle
signingConfigs {
release {
storeFile file(keyProperties['storeFile'])
storePassword keyProperties['storePassword']
keyAlias keyProperties['keyAlias']
keyPassword keyProperties['keyPassword']
}
}
⚙️ สร้าง release build
flutter build apk --release
flutter build ios --release
🔐 Obfuscation (ลดการ reverse engineer)
flutter build apk --release --obfuscate --split-debug-info=build/debug-info
📦 ลดขนาดไฟล์ APK/AAB
- ใช้
flutter build appbundleแทนapkสำหรับ Play Store - ใช้
--split-per-abiสำหรับแบ่งตาม CPU
flutter build apk --split-per-abi
📋 เช็ครายละเอียด release
- ตรวจสอบไฟล์ใน
build/app/outputs/flutter-apk - ใช้ DevTools ตรวจ memory และ performance ก่อนส่งขึ้น Store
✅ สรุป
- Signing ช่วยรับรองความถูกต้องของแอป
- Obfuscation ป้องกันการ decompile โค้ด
- ควรตรวจสอบขนาดไฟล์และ performance ก่อนเผยแพร่
จบบทเรียนชุด Flutter Advanced แล้วครับ! คุณพร้อมส่งแอปคุณสู่โลกจริงแล้ว 🎉
