Getting Started
Note: Before proceeding, make sure you have Flutter & Node.js/NPM setup for your system.
Clone this repo locally
git clone https://github.com/firebase/mlkit-custom-image-classifier
Create a new Firebase project from the console.
- Take a note of the Project ID from Settings page as we'll use it later. Also add a support email - this is required for sign-in to work.
- Follow the steps to add Firebase to the Flutter app in this repo. For the Android version, use
com.example.classifier as bundle ID and for iOS use com.example.imageclassifier. If you want to provide your own bundleIDs, remember to replace the pre-filled bundleIDs from the code in flutter/
NOTE: For the Android app, make sure to add a Debug signing certificate SHA-1 for Google Sign-in to work.
Enable Services
- Enable Firestore by going to Database tab in Firebase Console, click on Create Database, select "Start in locked mode" & click on Enable.
- Next, head to Sign-In Method tab under Authentication tab in Firebase console and enable the Google sign-in provider.
- Next up, we'd need to enable ML Kit by going to ML Kit and click on getting started.
- Follow that by clicking on the AutoML tab and click on getting started. This should take a few minutes to provision AutoML.
- Once that's done, we'd need to head to Storage and enable Storage. Finally, we'll need to add the pre-generated AutoML bucket (named:
${PROJECT_ID}-vcm) by doing the following:
- Click on Add bucket in the overflow menu
- In the "Set up bucket" dialog, choose Import existing Google Cloud Storage buckets and here you'll see a bucket name ${PROJECT_ID}-vcm. Select this bucket and click on continue.
- Finally, head to the rules tab and copy the rules from storage.rules & automlstorage.rules to the
${PROJECT_ID}.appspot.com & ${PROJECT_ID}-vcm buckets respectively.
Firebase setup
- You must have the Firebase CLI installed. If you don't have it install it with
npm install -g firebase-tools and then configure it with firebase login.
- Configure the CLI locally by using
firebase use --add and select your project in the list.
- Install dependencies locally by running:
cd functions; npm install; cd -
- For sending emails via your firebase functions, you'd need to set your
api_key for the service you're using. In this case, we use Sendgrid. Once you have an API key, run the following command to configure it
$ firebase functions:config:set sendgrid.key="<API_KEY>"
- Next, set the
FROM_EMAIL constant in this file to be email ID from which emails will be sent.
- Follow that up with setting the
APP_NAME that you've decided for your app.
- Go to the Firebase Console, select the gear image > project settings > Service Accounts and click Generate New Private Key to download a Service Account Key JSON document.
- Add the JSON service account credentials file to the Functions directory as functions/lib/service-account-key.json.
- Now run,
npm run deploy to deploy the functions, firestore & storage configuration.
Flutter app setup
- Set the
PROJECT_ID constant in the flutter app in this file.
- If you're using iOS, you'd need to follow these steps for Google Sign-In to work.
- You can now run the app locally!
- If you want to deploy the app, make sure to read the Android and iOS instructions to finalize the app name, icon etc.