Theory
Backend બનાવ્યા વગર backend
તમારું FestConnect Mobile app, જે ગયા semesterમાં Kotlinમાં બનાવ્યું હતું, phone પર કામ કરે છે, પરંતુ હજી અલગ devices વચ્ચે usersને login કરાવી શકતું નથી કે cloudમાં data store કરી શકતું નથી. તેને backendની જરૂર છે. તેના માટે તમારા પોતાના servers બનાવવું અને ચલાવવું ઘણું કામ છે.
Firebase shortcut આપે છે: તે Googleનું backend-as-a-service છે, એટલે ready-made cloud servicesનો collection, જેને તમારું app સીધું connect કરે છે. Authentication, databases અને storage Google દ્વારા provide અને host થાય છે. આ subject Firebaseનો ઉપયોગ કરીને FestConnect Mobileને real cloud-connected appમાં ફેરવે છે. આ lesson Firebase અને તેને Android project સાથે જોડવાની રીત introduce કરે છે.
Theory
Firebase શું provide કરે છે
Firebase એક backend-as-a-service (BaaS) છે: server code લખવાને બદલે તમે SDK દ્વારા Googleની hosted services વાપરો છો. આ subjectમાં મુખ્ય services:
- Authentication: usersને sign in કરાવવા, જેમ કે email/password, Google અને Facebook.
- Cloud Firestore અને Realtime Database: app data store અને sync કરવા.
- Cloud Storage: images જેવી files store કરવા.
આ સિવાય Hosting, notifications માટે Cloud Messaging અને Analytics જેવી services પણ છે. Mobile app માટે authentication અને databases મુખ્ય છે. તેનો લાભ સ્પષ્ટ છે: servers provision કર્યા વગર scalable, managed backend મળે છે, એટલે તમે app પર focus કરી શકો છો.
Follow along
Firebaseને Android app સાથે connect કરવું
- Firebase project બનાવો Firebase consoleમાં sign in કરીને FestConnect માટે project બનાવો.
- Android app register કરો Applicationનું package name (applicationId) વાપરીને appને projectમાં add કરો.
- google-services.json add કરો Consoleમાંથી generated config file download કરીને app moduleમાં મૂકો.
- SDK અને plugin add કરો Firebase SDK dependencies અને google-services Gradle plugin ઉમેરો.
- Sync અને use કરો Gradle sync કરો; હવે app Firebase services, જેમ કે Auth અને Firestore, call કરી શકે છે.
Practical
Appના Gradleમાં Firebase add કરવું
// app-level build.gradle: apply the plugin and add SDK dependencies
plugins {
id 'com.android.application'
id 'com.google.gms.google-services' // reads google-services.json
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:33.0.0')
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore'
}
// google-services.json (from the console) sits in the app module.Formula
Config file એ link છે
google-services.json file તમારા specific appને Firebase project સાથે જોડે છે. App register કરતી વખતે consoleમાંથી download થતી આ fileમાં projectના identifiers અને keys હોય છે, જેથી SDKને કયા backend સાથે વાત કરવી તે ખબર પડે.
આ file અને તેને વાંચતો google-services plugin ન હોય તો Firebase SDK યોગ્ય રીતે connect થઈ શકતું નથી. Setupનો સાર છે: online project બનાવો, app register કરો, google-services.json app moduleમાં મૂકો અને SDK add કરો. આ steps સાચા હોય તો Kotlin codeમાંથી Firebase features available થઈ જાય છે. BCA603-01ના web sideમાં પણ આવો JSON-config idea આવ્યો હતો; અહીં તે Android equivalent છે.
Quiz
Android appના contextમાં Firebaseને સૌથી સારી રીતે કેવી રીતે describe કરી શકાય?
- Android માટેની programming language
- Backend-as-a-service: hosted cloud services, જેમ કે auth, databases અને storage, જેને app પોતાના backend બનાવવાને બદલે connect કરે છે
- Kotlinનું replacement
- Layouts માટેનું design tool
Show the answer
Backend-as-a-service: hosted cloud services, જેમ કે auth, databases અને storage, જેને app પોતાના backend બનાવવાને બદલે connect કરે છે
Firebase backend-as-a-service (BaaS) છે: Google-hosted cloud services, જેમ કે Authentication, Firestore, Realtime Database, Storage અને બીજી services, જેને app SDK દ્વારા connect કરે છે. તેથી તમારે પોતાનું backend build અને run કરવું પડતું નથી. Option A ખોટું છે: Firebase servicesનું platform છે, programming language નથી; app હજી Kotlin અથવા Javaમાં લખાય છે. Option C પણ ખોટું છે: Firebase Kotlinને replace કરતું નથી; Kotlin app Firebaseને CALL કરે છે. Option D ખોટું છે: layouts Android Studioના toolsથી design થાય છે, Firebaseથી નહીં. Firebase backend આપે છે જેથી તમે app પર focus કરી શકો.
Think first
પોતાનો server બનાવવાને બદલે backend-as-a-service શા માટે વાપરવું?
તમે BCA603-01ની જેમ Express backend લખી શકો છો. તો mobile app Firebase તરફ શા માટે વળી શકે? પછી tap.
Show the answer
કારણ કે Firebase જેવી backend-as-a-service તમને FASTER SHIP કરવામાં મદદ કરે છે અને servers જાતે build, host, scale અને secure કરવાની ભારે મહેનત બચાવે છે. પોતાના backendમાં authentication લખવું પડે છે, passwords securely hash કરવા પડે છે, sessions અને tokens manage કરવા પડે છે, database set up અને maintain કરવો પડે છે, servers provision કરવા પડે છે, users વધે ત્યારે scaling handle કરવી પડે છે, security patches અને backups manage કરવા પડે છે. આ મોટું ongoing responsibility છે.
Firebase આમાંથી ઘણું managed services તરીકે આપે છે: multiple providers સાથે authentication, real-time databases, automatic scaling અને Googleના servers, security અને uptime. તેથી appને Firebase સાથે connect કરીને ઓછા codeમાં login અને cloud storage મેળવી શકાય છે, servers જાતે ચલાવ્યા વગર. તમે app experience પર focus કરી શકો છો.
Trade-offs પણ છે: Googleના platform, pricing અને availability પર dependency રહે છે; custom backendની સરખામણીમાં control ઓછો હોય છે; અને ખૂબ specialised requirements Firebaseના modelમાં fit ન પણ થાય. તેથી BCA603-01માં Express/Nodeથી પોતાનું backend બનાવવાનું પણ શીખવાય છે. બંને approaches valid છે: speed, real-time sync અને ઓછું operational work મહત્વનું હોય ત્યારે BaaS સારું છે; સંપૂર્ણ control અથવા highly specific logic જોઈએ ત્યારે custom backend યોગ્ય છે. બંને જાણવાથી તમે યોગ્ય પસંદગી કરી શકો છો. Managed services થોડું control છોડીને ઘણો convenience આપે છે.
Summary
Key takeaways
- Firebase Googleનું backend-as-a-service (BaaS) છે: app પોતાના backend બનાવવાને બદલે hosted cloud services સાથે connect થાય છે.
- Mobile માટેની core services: Authentication, Cloud Firestore, Realtime Database અને Cloud Storage.
- Setup: Firebase consoleમાં project બનાવો, package nameથી Android app register કરો, google-services.json add કરો, અને SDK તથા plugin ઉમેરો.
- google-services.json config file તમારા specific appને Firebase project સાથે link કરે છે જેથી SDK યોગ્ય backend વાપરી શકે.
- આ setup Kotlin FestConnect Mobile appને real cloud-connected appમાં ફેરવે છે.
- BaaS servers, scaling અને security manage કરીને development ઝડપી બનાવે છે, પરંતુ custom backend કરતાં થોડું control ઓછું આપે છે.
- Memory hook: Firebase ready-made cloud backend છે; google-services.json appને Firebase સાથે જોડતી link છે.