Cordova project. Firebase plugin (custom plugin). I am trying to figure out what the correct way to specify custom resource details that a plugin will use when the platform or plugin is added.
For instance, API_KEY, APP_ID and google-service.json for android, and GoogleServices-Info.plist for iOS
I have API_KEY and APP_ID nailed I think in plugin.xml
<platform name="android">
<preference name="API_KEY"/>
<preference name="APP_ID"/>
<config-file parent="/resources" target="res/values/strings.xml">
<string name="google_app_id">$APP_ID</string>
<string name="google_api_key">$API_KEY</string>
</config-file>
</platform>
So when the plugin is added I do cordova plugin add myfirebaseplugin --variable APP_ID=blah --variable API_KEY=blah
But what I have not worked out yet is the correct way to install google-service.json or Google-Service.Info.plist
I have tried having --variable IOS_FIREBASE_CONFIG="<path>"
and using <source-file src="$IOS_FIREBASE_CONFIG" target-dir="$PACKAGE_NAME/Resources"/>
in plugin.xml
but it seems source-file wont expand $IOS_FIREBASE_CONFIG.
".../plugins/firebase/$IOS_FIREBASE_CONFIG" not found!
Can the plugin handle the setup the config based on variables I pass in? Or is this (copying the config files) something config.xml would handle during platform add?
I have looked at a few firebase plugins and how they deal with it and it seems they cop out and tell you to manually copy in the config files into the platform folders, which doesn't feel right.
As a last resort I can probably write a hook for platform add.
When adding plugins or platforms, use the --save flag to add them to config. xml. Ex: cordova platform add android --save. Existing projects can use cordova plugin save and cordova platform save commands to save all previously installed plugins and platforms into your project's config.
First, you have to pass the plugin-spec command in the command prompt. Then, plugin-spec is saved into the xml and package. json file of an app. After saving the file, we can publish the latest plugin version to npm that our current project supports.
If you are using Cordova CLI 7 you can use resource-file
tag in the config.xml
you don't have to do anything, just document it so the user put the file on the root of the project and adds this in the config.xml
For cordova-android 6.x.x and older
<platform name="android">
<resource-file src="google-services.json" target="google-services.json" />
</platform>
For cordova-android 7.x.x
<platform name="android">
<resource-file src="google-services.json" target="app/google-services.json" />
</platform>
For iOS
<platform name="ios">
<resource-file src="GoogleService-Info.plist" />
</platform>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With