Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 4829dc3

Browse files
#699 Add ML Kit support (install script)
1 parent 751a5fc commit 4829dc3

File tree

2 files changed

+226
-106
lines changed

2 files changed

+226
-106
lines changed

publish/scripts/installer.js

Lines changed: 113 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -129,61 +129,97 @@ function askAndroidPromptResult(result) {
129129
function promptQuestions() {
130130
prompt.get([{
131131
name: 'firestore',
132-
description: 'Are you using Cloud Firestore (y/n)',
132+
description: 'Are you using Cloud Firestore? (y/n)',
133133
default: 'n'
134134
}, {
135135
name: 'realtimedb',
136-
description: 'Are you using Realtime DB (y/n)',
136+
description: 'Are you using Realtime DB? (y/n)',
137137
default: 'n'
138138
}, {
139139
name: 'remote_config',
140-
description: 'Are you using Firebase RemoteConfig (y/n)',
140+
description: 'Are you using Firebase RemoteConfig? (y/n)',
141141
default: 'n'
142142
}, {
143143
name: 'messaging',
144-
description: 'Are you using Firebase Messaging (y/n)',
144+
description: 'Are you using Firebase Messaging? (y/n)',
145145
default: 'n'
146146
}, {
147147
name: 'crashlytics',
148-
description: 'Are you using Firebase Crashlytics (y/n)',
148+
description: 'Are you using Firebase Crashlytics? (y/n)',
149149
default: 'n'
150150
}, {
151151
name: 'crash_reporting',
152-
description: 'Are you using Firebase Crash Reporting (answer "n" if you want to use Crashlytics instead) (y/n)',
152+
description: 'Are you using Firebase Crash Reporting? (answer "n" if you want to use Crashlytics instead) (y/n)',
153153
default: 'n'
154154
}, {
155155
name: 'storage',
156-
description: 'Are you using Firebase Storage (y/n)',
156+
description: 'Are you using Firebase Storage? (y/n)',
157157
default: 'n'
158158
}, {
159159
name: 'facebook_auth',
160-
description: 'Are you using Firebase Facebook Authentication (y/n)',
160+
description: 'Are you using Firebase Facebook Authentication? (y/n)',
161161
default: 'n'
162162
}, {
163163
name: 'google_auth',
164-
description: 'Are you using Firebase Google Authentication (y/n)',
164+
description: 'Are you using Firebase Google Authentication? (y/n)',
165165
default: 'n'
166166
}, {
167-
name: 'ml_kit',
168-
description: 'Are you using ML Kit (y/n)',
167+
name: 'admob',
168+
description: 'Are you using AdMob? (y/n)',
169169
default: 'n'
170-
}, {
171-
name: 'admob',
172-
description: 'Are you using AdMob (y/n)',
173-
default: 'n'
174170
}, {
175171
name: 'invites',
176-
description: 'Are you using Firebase Invites and/or Dynamic Links (y/n)',
172+
description: 'Are you using Firebase Invites and/or Dynamic Links? (y/n)',
177173
default: 'n'
174+
}, {
175+
name: 'ml_kit',
176+
description: 'Are you using ML Kit? (y/n)',
177+
default: 'n'
178178
}], function (err, result) {
179179
if (err) {
180180
return console.log(err);
181181
}
182-
mergeConfig(result);
183-
promptQuestionsResult(result);
184-
askSaveConfigPrompt();
182+
if (!isSelected(result.ml_kit)) {
183+
mergeConfig(result);
184+
promptQuestionsResult(result);
185+
askSaveConfigPrompt();
186+
} else {
187+
prompt.get([{
188+
name: 'ml_kit_text_recognition',
189+
description: 'With Ml Kit, do you want to recognize text? (y/n)',
190+
default: 'n'
191+
}, {
192+
name: 'ml_kit_barcode_scanning',
193+
description: 'With Ml Kit, do you want to scan barcodes? (y/n)',
194+
default: 'n'
195+
}, {
196+
name: 'ml_kit_face_detection',
197+
description: 'With Ml Kit, do you want to detect faces? (y/n)',
198+
default: 'n'
199+
}, {
200+
name: 'ml_kit_image_labeling',
201+
description: 'With Ml Kit, do you want to label images? (y/n)',
202+
default: 'n'
203+
}, {
204+
name: 'ml_kit_custom_model',
205+
description: 'With Ml Kit, do you want to use a custom TensorFlow Lite model? (y/n)',
206+
default: 'n'
207+
}], function (mlkitErr, mlkitResult) {
208+
if (mlkitErr) {
209+
return console.log(mlkitErr);
210+
}
211+
console.log("result: " + JSON.stringify(result));
212+
console.log("mlkitResult: " + JSON.stringify(mlkitResult));
213+
for (var attrname in mlkitResult) { result[attrname] = mlkitResult[attrname]; }
214+
console.log("mergedResult result: " + JSON.stringify(result));
215+
mergeConfig(result);
216+
promptQuestionsResult(result);
217+
askSaveConfigPrompt();
218+
});
219+
}
185220
});
186221
}
222+
187223
function promptQuestionsResult(result) {
188224
if (usingiOS) {
189225
writePodFile(result);
@@ -194,10 +230,37 @@ function promptQuestionsResult(result) {
194230
writeGradleFile(result);
195231
writeGoogleServiceCopyHook();
196232
writeGoogleServiceGradleHook(result);
233+
echoAndroidManifestChanges(result);
197234
}
198235
console.log('Firebase post install completed. To re-run this script, navigate to the root directory of `nativescript-plugin-firebase` in your `node_modules` folder and run: `npm run config`.');
199236
}
200237

238+
function echoAndroidManifestChanges(result) {
239+
if (isSelected(result.ml_kit)) {
240+
var selectedFeatures = [];
241+
if (isSelected(result.ml_kit_text_recognition)) {
242+
selectedFeatures.push("text");
243+
}
244+
if (isSelected(result.ml_kit_barcode_scanning)) {
245+
selectedFeatures.push("barcode");
246+
}
247+
if (isSelected(result.ml_kit_face_detection)) {
248+
selectedFeatures.push("face");
249+
}
250+
if (isSelected(result.ml_kit_image_labeling)) {
251+
selectedFeatures.push("label");
252+
}
253+
if (selectedFeatures.length > 0) {
254+
console.log('\n######################################################################################################');
255+
console.log('Open your app\'s resources/Android/AndroidManifest.xml file and add this (see the demo for an example):');
256+
console.log('<meta-data\n' +
257+
' android:name="com.google.firebase.ml.vision.DEPENDENCIES"\n' +
258+
' android:value="' + selectedFeatures.join(',') + '" />');
259+
console.log('######################################################################################################\n');
260+
}
261+
}
262+
}
263+
201264
function exposeAdMobSymbols(enable) {
202265
if (enable && fs.existsSync(directories.ios + '/build.xcconfig.admob')) {
203266
fs.renameSync(directories.ios + '/build.xcconfig.admob', directories.ios + '/build.xcconfig');
@@ -237,19 +300,19 @@ function writePodFile(result) {
237300
pod 'Firebase/Core', '~> 5.0.0'
238301
pod 'Firebase/Auth'
239302
240-
# Uncomment if you want to enable Realtime DB
303+
# Realtime DB
241304
` + (!isPresent(result.realtimedb) || isSelected(result.realtimedb) ? `` : `#`) + `pod 'Firebase/Database'
242305
243-
# Uncomment if you want to enable Cloud Firestore
306+
# Cloud Firestore
244307
` + (isSelected(result.firestore) ? `` : `#`) + `pod 'Firebase/Firestore'
245308
246-
# Uncomment if you want to enable Remote Config
309+
# Remote Config
247310
` + (isSelected(result.remote_config) ? `` : `#`) + `pod 'Firebase/RemoteConfig'
248311
249-
# Uncomment if you want to enable Crash Reporting
312+
# Crash Reporting
250313
` + (isSelected(result.crash_reporting) && !isSelected(result.crashlytics) ? `` : `#`) + `pod 'Firebase/Crash'
251314
252-
# Uncomment if you want to enable Crashlytics
315+
# Crashlytics
253316
` + (isSelected(result.crashlytics) ? `` : `#`) + `pod 'Fabric'
254317
` + (isSelected(result.crashlytics) ? `` : `#`) + `pod 'Crashlytics'
255318
` + (!isSelected(result.crashlytics) ? `` : `
@@ -263,34 +326,31 @@ post_install do |installer|
263326
end
264327
end`) + `
265328
266-
# Uncomment if you want to enable FCM (Firebase Cloud Messaging)
329+
# Firebase Cloud Messaging (FCM)
267330
` + (isSelected(result.messaging) ? `` : `#`) + `pod 'Firebase/Messaging'
268331
269-
# Uncomment if you want to enable Firebase Storage
332+
# Firebase Storage
270333
` + (isSelected(result.storage) ? `` : `#`) + `pod 'Firebase/Storage'
271334
272-
# Uncomment if you want to enable AdMob
335+
# AdMob
273336
` + (isSelected(result.admob) ? `` : `#`) + `pod 'Firebase/AdMob'
274337
275-
# Uncomment if you want to enable Invites and/or Dynamic Links
338+
# Invites / Dynamic Links
276339
` + (isSelected(result.invites) ? `` : `#`) + `pod 'Firebase/Invites'
277340
278-
# Uncomment if you want to enable ML Kit
341+
# ML Kit
279342
` + (isSelected(result.ml_kit) ? `` : `#`) + `pod 'Firebase/MLVision'
280-
# TODO we'de better make these conditional as well
281-
` + (!isSelected(result.ml_kit) ? `` : `
282-
pod 'Firebase/MLVisionBarcodeModel'
283-
pod 'Firebase/MLVisionFaceModel'
284-
pod 'Firebase/MLVisionLabelModel'
285-
pod 'Firebase/MLVisionTextModel'
286-
pod 'Firebase/MLModelInterpreter'
287-
`) + `
288-
289-
# Uncomment if you want to enable Facebook Authentication
343+
` + (isSelected(result.ml_kit) && isSelected(result.ml_kit_text_recognition) ? `` : `#`) + `pod 'Firebase/MLVisionTextModel'
344+
` + (isSelected(result.ml_kit) && isSelected(result.ml_kit_barcode_scanning) ? `` : `#`) + `pod 'Firebase/MLVisionBarcodeModel'
345+
` + (isSelected(result.ml_kit) && isSelected(result.ml_kit_face_detection) ? `` : `#`) + `pod 'Firebase/MLVisionFaceModel'
346+
` + (isSelected(result.ml_kit) && isSelected(result.ml_kit_image_labeling) ? `` : `#`) + `pod 'Firebase/MLVisionLabelModel'
347+
` + (isSelected(result.ml_kit) && isSelected(result.ml_kit_custom_model) ? `` : `#`) + `pod 'Firebase/MLModelInterpreter'
348+
349+
# Facebook Authentication
290350
` + (isSelected(result.facebook_auth) ? `` : `#`) + `pod 'FBSDKCoreKit'
291351
` + (isSelected(result.facebook_auth) ? `` : `#`) + `pod 'FBSDKLoginKit'
292352
293-
# Uncomment if you want to enable Google Authentication
353+
# Google Authentication
294354
` + (isSelected(result.google_auth) ? `` : `#`) + `pod 'GoogleSignIn'`);
295355
console.log('Successfully created iOS (Pod) file.');
296356
} catch(e) {
@@ -499,46 +559,46 @@ dependencies {
499559
// for reading google-services.json and configuration
500560
compile "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
501561
502-
// Uncomment if you want to use the regular Database
562+
// Realtime DB
503563
` + (!isPresent(result.realtimedb) || isSelected(result.realtimedb) ? `` : `//`) + ` compile "com.google.firebase:firebase-database:15.0.0"
504564
505-
// Uncomment if you want to use 'Cloud Firestore'
565+
// Cloud Firestore
506566
` + (isSelected(result.firestore) ? `` : `//`) + ` compile "com.google.firebase:firebase-firestore:16.0.0"
507567
508-
// Uncomment if you want to use 'Remote Config'
568+
// Remote Config
509569
` + (isSelected(result.remote_config) ? `` : `//`) + ` compile "com.google.firebase:firebase-config:15.0.2"
510570
511-
// Uncomment if you want to use 'Crash Reporting'
571+
// Crash Reporting
512572
` + (isSelected(result.crash_reporting) && !isSelected(result.crashlytics) ? `` : `//`) + ` compile "com.google.firebase:firebase-crash:15.0.2"
513573
514-
// Uncomment if you want to use 'Crashlytics'
574+
// Crashlytics
515575
` + (isSelected(result.crashlytics) ? `` : `//`) + ` compile "com.crashlytics.sdk.android:crashlytics:2.9.1"
516576
517-
// Uncomment if you want to use FCM (Firebase Cloud Messaging)
577+
// Firebase Cloud Messaging (FCM)
518578
` + (isSelected(result.messaging) ? `` : `//`) + ` compile "com.google.firebase:firebase-messaging:15.0.2"
519579
520-
// Uncomment if you want to use Google Cloud Storage
580+
// Cloud Storage
521581
` + (isSelected(result.storage) ? `` : `//`) + ` compile "com.google.firebase:firebase-storage:15.0.2"
522582
523-
// Uncomment if you want to use AdMob
583+
// AdMob
524584
` + (isSelected(result.admob) ? `` : `//`) + ` compile "com.google.firebase:firebase-ads:15.0.0"
525585
526-
// Uncomment if you want to use ML Kit
586+
// ML Kit
527587
` + (isSelected(result.ml_kit) ? `` : `//`) + ` compile "com.google.firebase:firebase-ml-vision:15.0.0"
528588
529-
// Uncomment if you need Facebook Authentication
589+
// Facebook Authentication
530590
` + (isSelected(result.facebook_auth) ? `` : `//`) + ` compile ("com.facebook.android:facebook-android-sdk:4.+"){ exclude group: 'com.google.zxing' }
531591
532-
// Uncomment if you need Google Sign-In Authentication
592+
// Google Sign-In Authentication
533593
` + (isSelected(result.google_auth) ? `` : `//`) + ` compile "com.google.android.gms:play-services-auth:$googlePlayServicesVersion"
534594
535-
// Uncomment if you need Firebase Invites or Dynamic Links
595+
// Firebase Invites / Dynamic Links
536596
` + (isSelected(result.invites) ? `` : `//`) + ` compile "com.google.firebase:firebase-invites:$googlePlayServicesVersion"
537597
}
538598
539599
apply plugin: "com.google.gms.google-services"
540600
541-
// Uncomment if you want to use 'Crashlytics'
601+
// Crashlytics
542602
` + (isSelected(result.crashlytics) ? `` : `//`) + `apply plugin: "io.fabric"
543603
`);
544604
console.log('Successfully created Android (include.gradle) file.');

0 commit comments

Comments
 (0)