I am trying to build a Cordova app for Huawei that use push notification using OneSignal and its cordova plugin (onesignal-cordova-plugin - npm).
In order to use Huawei push notification, I am following the following guide:
The problem is that, in order to make it works, I have to add a particular JSON file, called agconnect.json, to my project (this file is used by all huawei services, not only push notification). The guide, at point 6, says:
Copy the agconnect-services.json file to the <project_root>/platforms/android/app directory.
IS there a way to do this using Voltbuilder? I tryied to add to the project the platforms/android/app folders with the file in it (and of course adding that to the .zip before upload), but the build log tells me that the platforms/android folder was found but not used.
Does anyone has any suggestion on how to solve this?
Thank you in advance for your time!
After struggling, I found a solution that I’ll post here for the benefits of other fellow devs who could run into the same issue.
Please note, for this solution to work with Voltbuilder you need to upload custom plugins/aka enterprise plan.
The trick is the following: since I am uploading to Voltbuilder a modified version of the cordova-plugin-hms-push (because the one currently on NPM has not been updated to work with android 12), I wrote a custom “before_plugin_install” hook that I put in the hooks folder of the plugin and I also put the agconnect-services.json file in root folder of the plugin. This new js file simply searches for the agconnect-services.json file in the expected location and copy it to platforms/android/app. Since this script only run after android platform has already been added, everything works fine and I was finally able to create a functioning build with push notification.
Also, remember to set in voltbuilder.json “release” to “release” and not debug, because for Huawei push you need to sign your apk/build with the same keystore you used to configure push notification on you App Connect Gallery.
I’ll just leave here the GitHub repo of the modified cordova-plugin-hms-push. Remember, use it at your own discretion and I take no responsibility for it
Great post - thank you!
Hopefully, the maintainer of the post will implement your changes. Otherwise, you could create a new plugin in npm with your code. Let us know and we’ll add it to the approved list so it isn’t Enterprise only.