Describe the bug
Last version of the plugin causes an error when building the project in ionic.
To Reproduce
Create a blank ionic (v3) project.
ionic start cordova-firebase-plugin blank
Add the plugin
ionic cordova plugin add cordova-plugin-firebase
npm i @ionic-native/firebase
Build the app
ionic cordova build android --prod
Expected behavior
The project is build with no errors
Console Logs
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/yc00033/Documents/temp/cordova-firebase-plugin/platforms/android/build.gradle' line: 25
* What went wrong:
A problem occurred evaluating root project 'android'.
> Could not find method google() for arguments [] on repository container.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.653 secs
Error: /Users/yc00033/Documents/temp/cordova-firebase-plugin/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/yc00033/Documents/temp/cordova-firebase-plugin/platforms/android/build.gradle' line: 25
* What went wrong:
A problem occurred evaluating root project 'android'.
> Could not find method google() for arguments [] on repository container.
Plugin Version
cordova-plugin-firebase 2.0.2 "Google Firebase Plugin"
Additional context
I created a project to replicate the issue.
@briantq do you know why we add the google() repo to the gradle file? Looking at the Crashlytics guide, there is no google() repo shown, so I'm wondering why we even need to add it. Based on this comment, removing the line has shown to get the build working for others.
@briantq looking at this Crashlytics setup guide, it says to add the google() repo. However, the location of the google() repo is under allprojects and not under buildscript where it is currently being added. Perhaps that is the reason some are experiencing issues.
@davidanaya for just workaround comment google() function from build.gradle file and after that it will work without build failure. @soumak77 looking forward to get it resolved.
@Mykiee could you verify whether adding the following to the gradle file works or not?
allprojects {
repositories {
google()
}
}
@soumak77 I need to add this method under allprojects, right? Please let me know how can I verify this if its working good. Also do I need to uncomment google() function commented previously in buildscript? As it is doing fine with the method.
I created PR #882 which removes the need to add google() to the repo list. The official guide doesn't add it so I'm thinking we don't even need it.
@davidanaya please install the plugin from master to verify this has been fixed
ionic cordova plugin add https://github.com/arnesson/cordova-plugin-firebase.git#master
Works like a charm, @soumak77 thanks!
Thanks @soumak77 :)
@soumak77 I don't like that we removed the required setup steps for Firebase. Since only @Mykiee and @davidanaya are the only ones experiencing the issue, I'd check to see if it's environmental. I did a quick Google search (only took 60 seconds) but it looks like the issue might be due to an older gradle version, https://github.com/react-native-community/react-native-camera/issues/1530#issuecomment-385752864 I think we might check to see if that resolved the issue. @Mykiee and @davidanaya, what version of gradle are you using for your projects?
@briantq It seems to me that the build would fail if the goggle() repo was required, but it is listed in the setup guide so I guess it's needed....
In any case, looks like I'll need to revert my changes.
@briantq it was failing with 4.1 and I updated to 4.6 and still was failing
@davidanaya do you have a gradle.properties located in platforms\android\gradle\wrapper\? If so, can you paste the contents of that file please?
I have a gradle-wrapper.properties file with these contents
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Looks like you are using Gradle 3.3 for building your project. Check out these directions on how to upgrade your gradle version, https://blog.nishtahir.com/2018/04/15/how-to-properly-update-the-gradle-wrapper/ I am running 4.4. Based on the few stackoverflow posts I read, that should resolve your issue. You might consider upgrading your gradle version more often as 3.3 is well over a year and a half old...
Thanks @briantq The thing is that this file is automatically generated by ionic (cordova) so even if I change it when I do the build it will be generated again with the wrong version; maybe the way to update gradle is by updating cordova itself (I'm using version 7.1.0) ? I upgraded gradle by android studio but it seems that this did not affect the version of gradle used in my project.
Hi everyone.
I was following this thread because I was with exactly same error. I'm using Ionic 3 and cordova-plugin-firebase.
I was using cordova [email protected] and when I upgrade it to 6.4.0 I could build the project without problem.
@davidanaya can you try to build with this cordova-android version?
Thanks @guilhermegjr I will try but I need to sync with my team as we are using the same Ionic version for a few different apps and we need to check if it does not break anything.
I'll report back on Monday.
@davidanaya interesting, I do not use Ionic so I was not aware. With this knowledge I would do 2 things:
Create an issue against Ionic to upgrade to a release of Gradle that came out within the last year.
1b. Submit a Pull Request against Ionic for the upgrade as it should be a pretty trivial change and unless Ionic has a lot of build plugins, there's a decent chance it just works.
If you read the article I liked to, you will find that you upgrade the gradlew version by running gradlew. After Ionic prepares the platform, simply add one line to your script to upgrade gradlew to 4.1+ and it should work. Where ever you call your Ionic build script, add that one line and you should be good every time you recreate the platform from there on out.
@guilhermegjr Thanks for the pointer! @davidanaya, definitely let us know if you are able to confirm that does resolve the issue. Looking at the Cordova Android 6.4.0 Release Notes, they explicitly reference gradle and that they are removing it going forward. It sounds like that might be the issue.
I use ionic and I don't think it relies on a specific Gradle version. I suspect the Gradle version you have in your PATH is the old version and wasn't upgraded properly. Just a hunch.
The Gradle Wrapper was designed to be self contained. When Android started using Gradle it was not very familiar and no one had it installed. Hence they designed a self contained system that overrides the system gradle and installs a version if you elected. If you run ./gradle, it will use the system but ./gradlew will definitely run the version specified in the gradle.properties. Just depends on which command Ionic runs (and possible the 6.3.0 version as it seems like gradlew might have been removed completely in later releases).
Ionic relies on cordova for building the source. My app has cordova-android v7.1 and has the following line contained in node_modules/cordova-android/framework/gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Therefore I think if you upgrade your cordova-android version, this issue should be resolved.
This appears to be resolved. You'll need to update your cordova-android version to get this fixed. I've modified our supported cordova versions to reflect this.
what is the solution of this problem
Most helpful comment
Hi everyone.
I was following this thread because I was with exactly same error. I'm using Ionic 3 and cordova-plugin-firebase.
I was using cordova [email protected] and when I upgrade it to 6.4.0 I could build the project without problem.
@davidanaya can you try to build with this cordova-android version?