Implementing Firebase on ionic project: Errors and solutions - 1 of 2: Client side



We were working on a Mobile Application project for the internal employees in the company, it was build on ionic as I mentioned before here , The reason of building it on ionic is that: ionic is hibered and for some extend its fast, and Angular is flexible on coding. 

So, we decided to use onesignal push notification client to push our notification, rather than its free, it was clear and easy to use because of it's will written documentation, and the website is opened on Sudan. 

But.. 

Suddenly,  onesignal website was blocked from Sudan, but the push notification API for the server side was working, 
Then the API stopped and to work you have to run the code on Server that access the internet through VPN. but still you can recieve the notification on the phone without no issues. 
Then they even blocked the client side, and to receive notification the phone must access the internet through VPN! and this is impossible to be implemented for 1000 users in different internet speed and technology knowledge. 

So 

We decided throw all that effort and code that we had written, and use Firebase for notification push (only the website is blocked from Sudan, but the API and the client side is working, DON'T SHOW THEM THIS BLOG! ) 

and I found this good article about how to implement  Firebase on ionic, but I faced some issues that I would like to share. 

1.

Could not find method google() for arguments [] on repository container.
To solve this you have to remove the android platform and re-add it again, first you have to make sure that the cordova plugins are saved. 

run the following commands: 
> cordova plugin save
> cordova platform rm android
> cordova platform add android



2.

after I have done this I tried to to run ionic cordova run android -l -c   but a new error pops up: 
A problem occurred evaluating project ':app'.
> Plugin with id 'com.google.gms.google-services' not found.

Here, the dependency classpath 'com.google.gms:google-services:4.1.0' should be added to the project-level build.gradle, as answered on this link

3.

but another error raised: 
> Plugin with id 'io.fabric' not found.

So I had added classpath 'io.fabric.tools:gradle:1.+' to the project-level build.gradle file as answered on this link

Or, Its better to create an account at fabric.io site, on organization page copy API Key and API Secret and add its plugin to ionic:


$ ionic cordova plugin add cordova-fabric-plugin --variable FABRIC_API_KEY=XXX --variable FABRIC_API_SECRET=xxx 


$ npm install --save @ionic-native/fabric 

4.

Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.

the solution is: put + on the version at com.google.gms:google-services:+ on the build.gradle file of the project level.

5.

failed to execute aapt ionic

ugh !! for this run the folloing as answered on this link
cordova plugin add cordova-android-support-gradle-release --fetch

6.

And then, the BIG ERROR: "cordova_not_available"😒😒

to solve this, as described here : 
Replace in node_modules/@ionic/app-scripts/dist/dev-server/serve-config.js:
exports.ANDROID_PLATFORM_PATH = path.join('platforms', 'android', 'assets', 'www');
to
exports.ANDROID_PLATFORM_PATH = path.join('platforms', 'android', 'app', 'src', 'main', 'assets', 'www');

It runs !

Yesss it finally runs 😍

and now we have to build the server side to push the notifications to the registered devices. and this will be discussed on the 2nd article. 




PS: FCM Plugin and Firebase Plugin will not work together. it will gave this error, you have to remove one of them.




Comments

Popular posts from this blog

How to Automatically deploy Configuration Files with Azure DevOps CD pipelines

Adapting a New Technology: A General Guide to keep Your Systems up-to-date

Adding Multiple DB Contexts in your DotNet Project