arnesson / cordova-plugin-firebase

Cordova plugin for Google Firebase
http://arnesson.github.io/cordova-plugin-firebase
MIT License
1.01k stars 1.56k forks source link

build error #837

Closed yomencity closed 6 years ago

yomencity commented 6 years ago

I have used 1.0.5 version and I upgraded 2 0.0(latest) now. But I have a problem which is about build error.

[cordova] FAILURE: Build failed with an exception. [cordova] [cordova] * Where: [cordova] Script '*/app/platforms/android/cordova-plugin-firebase/app-build.gradle' line: 27 [cordova] [cordova] What went wrong: [cordova] A problem occurred evaluating project ':app'. [cordova] > Plugin with id 'com.google.gms.google-services' not found. [cordova] [cordova] Try: [cordova] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. [cordova] [cordova] Get more help at https://help.gradle.org [cordova] [cordova] BUILD FAILED in 0s [cordova] (node:82096) UnhandledPromiseRejectionWarning: Error: /app/platforms/android/gradlew: Command failed with exit code 1 Error output: [cordova] FAILURE: Build failed with an exception. [cordova] [cordova] * Where: [cordova] Script '**/app/platforms/android/cordova-plugin-firebase/app-build.gradle' line: 27 [cordova] [cordova] What went wrong: [cordova] A problem occurred evaluating project ':app'. [cordova] > Plugin with id 'com.google.gms.google-services' not found

yomencity commented 6 years ago

cordova version: 8.0.0

hardcpp commented 6 years ago

+1 same here, fresh windows install, same for npm, cordova, the project & all the plugins

laychar commented 6 years ago

My app works when I used @1.0.5 version. I think It is better to use older version. do yo know where the release-version list is?

soumak77 commented 6 years ago

Release list: https://github.com/arnesson/cordova-plugin-firebase/releases

We only recently started a CHANGELOG to track the exact changes to each version

ahmadtawakol commented 6 years ago

+1 I tried everything to try to figure out what the problem is, no luck so far

briantq commented 6 years ago

I believe the issue goes back to a Pull Request for Crashlytics that removed the google play service dependency. Based on the FIrebase documentation and the issues reported by the community, this should resolve the issue.

If someone could confirm by testing this code by doing the following: cordova plugin remove cordova-plugin-firebase (uninstall current firebase plugin) cordova plugin add https://github.com/briantq/cordova-plugin-firebase.git#google-services (install the proposed fix)

Please let me know if that resolves the issue. If it does, we can get it merged. If not, I can try to make additional changes.

willmero commented 6 years ago

@briantq Thanks for putting together a proposed solution here! I attempted and resulted in the following error:

* What went wrong:
The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.2,15.0.2]], but resolves to 15.0.4. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.
jpduckwo commented 6 years ago

This is going to sound quite weird but I've been able to replicate getting it working or not by the order which I add platforms. If the config.xml contains the plugins and you 'platform add ios' and then 'platform add android' - android build won't work. However if you 'platform add android' then 'platform add ios' ... it works! What the... seems like some lifecycle hook is in the wrong place

so try

platform rm ios
platform rm android
platform add android
platform add ios

I'm using cordova 8 and latest platform versions...

    <engine name="ios" spec="^4.5.5" />
    <engine name="android" spec="^7.1.1" />
    <plugin name="cordova-plugin-firebase" spec="^2.0.0" />
ahmadtawakol commented 6 years ago

@jpduckwo Tried that, doesn't work for me

briantq commented 6 years ago

@willmero Thanks for testing. It sounds like like you are encountering classic dependency version hell :) Did you run the command to see what other plugin is referencing Google Play Services? As far as dependency versions, I added it with the same line that was in the repo a month ago prior to the problematic pull request, which is without a version simply a plus sign.

One other interesting note is that the version that should be getting pulled is version 4.1.0 according to the documention. If you are resolving to 15.X, I think you have another issue somewhere...

lucabro81 commented 6 years ago

@briantq hi! I've tried to install your fix but no luck, same error

* What went wrong:
A problem occurred evaluating project ':app'.
> Plugin with id 'com.google.gms.google-services' not found.

in my project.properties com.google.gsm.google-services is present

cordova.system.library.5=com.google.gms:google-services:+

willmero commented 6 years ago

@lucabro81 have you tried installing the cordova-android-play-services-gradle-release plugin? That is what solved the above error for me.

@briantq sigh yeah, don't you just love it? Thanks for your help here. I managed to get your branch working after installing the following plugins and set their versions in the config.xml file: cordova-plugin-firebase:+ cordova-android-support-gradle-release:27.+ cordova-android-play-services-gradle-release:+

Running on Cordova android 7.0.0

jpduckwo commented 6 years ago

I've dug a bit deeper because I was able to replicate as described above. What I found was that the following section was sometime missing in platforms/android/app/build.grade... for me it was around line 95 in the file.

missing section

// Fabric Cordova Plugin - Start Fabric Build Tools 
buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        maven { url 'https://maven.google.com' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.25.4'
        classpath 'com.google.gms:google-services:+'
    }
}

apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'

Possible it could be to do with the order plugins are being added and one overriding the other... my plugins are

    <plugin name="cordova-plugin-ionic-webview" spec="^1.2.1" />
    <plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
    <plugin name="cordova-custom-config" spec="^4.0.2" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
    <plugin name="cordova-plugin-statusbar" spec="^2.4.2" />
    <plugin name="cordova-plugin-firebase" spec="^2.0.0" />
    <plugin name="cordova-plugin-googleplus" spec="git+https://github.com/EddyVerbruggen/cordova-plugin-googleplus.git">
    </plugin>
    <plugin name="cordova-universal-links-plugin" spec="git+https://github.com/veloce/cordova-universal-links-plugin.git" />
briantq commented 6 years ago

@lucabro81 @willmero @jpduckwo Thank you guys for testing out the code!

My understanding is the same as @jpduckwo, there is missing reference to the gms plugin in platform/android/src/build.gradle. As such, when Android gradle syncs, it is not pulling all the required dependencies.

@jpduckwo looing back at your reply, I don't think you are running with the proposed solution as your spec version for cordova-plugin-firebase does not reference the branch but instead the release version.

@willmero I am not sure what other dependencies you have, but this plugin shouldn't need any other plugins to run successfully. That being said, there are definitely things beyond my knowledge!

@lucabro81 That is puzzling. I did not know about the project.properties file but when I checked, it does seem like that does reference gradle dependencies. Could you do me a favor and check your platform/android/src/build.gradle as that is the actual file Android uses to build. Check to see if you can find a line that says compile "com.google.gms:google-services:+". If it is not in there, you might try deleting the platform/android directory and running cordova prepare android.

briantq commented 6 years ago

I am learning more :) I believe there are additional modifications that are required. Now that I can recreate the issue, I can see what I can come up with.

jpduckwo commented 6 years ago

Thanks @briantq! Yes that's right - I am referencing the release branch - however I did this on purpose because I could get it working with the release branch depending on the order that my plugins were installed and the proposed fix branch didn't fix the bug in question.

jpduckwo commented 6 years ago

@briantq https://cordova.apache.org/docs/en/latest/guide/appdev/hooks/ 'after_platform_add' hook might be needed to trigger the stuff that happens in after_plugin_add for the current hook... just a guess

briantq commented 6 years ago

Thanks @jpduckwo I am struggling to find the time tonight, but I do know v1.0.5 does work. Additionally, here are the files that were changed (warning, there are quite a few) that broke the functionality.

I have created the android platform with v1.0.5 and v2.0.0 and then am diffing them. That is where I found it was more than just the build.gradle. With that diff, along with the files that changed, I think there in lies the solution.

If you have the time and want to take a stab at it, you can fork the repo, make your changes in a branch and then install your branch (the same way I was suggested you install my branch). If you can get it working, then simply turn your branch into a pull request and I will cancel mine.

paulstelzer commented 6 years ago

Had the same issue Plugin with id 'com.google.gms.google-services' not found. (cordova-plugin-firebase@2.0.1)

To make the build work and afterwards my app work, I had to do the following:

  1. In my project level build.gradle I add the following: (as stated at https://firebase.google.com/docs/crashlytics/get-started#android and https://firebase.google.com/docs/android/setup#manually_add_firebase )
buildscript {
    repositories {
....
        maven {
           url 'https://maven.fabric.io/public'
        }
...
    }
    dependencies {
...
        classpath 'com.google.gms:google-services:4.1.0' // google-services plugin
        classpath 'io.fabric.tools:gradle:1.25.4'
...

    }
}

allprojects {
    repositories {
...
        google()
...
    }

}
  1. In app/build.gradle I added

apply plugin: 'io.fabric' (directly under apply plugin: 'com.android.application')

And now the build is successful AND the app loads

PS: I do not know, if EVERYTHING is needed to add and hopefully some of that can added to cordova-plugin-firebase build.gradle

briantq commented 6 years ago

I fixed it. It took a long while to unwind the code to figure out that we had incomplete fix on top of incomplete fix along with learning all about Cordova's build framework and all the scripts in this plugin, but this should resolve the issue.

@lucabro81 @willmero @jpduckwo could you guys test this new branch? Since I could test it before submitting, I have much higher confidence in this.

cordova plugin remove cordova-plugin-firebase (uninstall current firebase plugin) cordova plugin add https://github.com/briantq/cordova-plugin-firebase.git#android-build (install the proposed fix)

@paulstelzer It is not recommended that you modify the build files by hand. This requires that you check in all the native code files otherwise the next time you generate the platform your changes will be gone. CHECKING IN PLATFORM FILES (ESPECIALLY BUILD SCRIPTS) IS AN ANTI-PATTERN after Cordova 4.3.0. Documentation states : "This feature (platform management} allows developers to save and restore their app to a known state without having to check in all of the platform and plugin source code." I would strongly encourage you not to take such work arounds as they will cause more complication in the future. Just my 2 cents.

paulstelzer commented 6 years ago

@briantq I know that it's not good to edit it manually, but now you found an automatic way. I just want to say you what was missing and was causing the issue ;)

briantq commented 6 years ago

@paulstelzer Thanks :) I started on Cordova less than 2 months ago and trying to figure out what to check in and not to check in took some investigation. I think some times people take the easiest approach not knowing any better so I try to inform people about best practices when possible.

ahmadtawakol commented 6 years ago

I fixed it. It took a long while to unwind the code to figure out that we had incomplete fix on top of incomplete fix along with learning all about Cordova's build framework and all the scripts in this plugin, but this should resolve the issue.

@lucabro81 @willmero @jpduckwo could you guys test this new branch? Since I could test it before submitting, I have much higher confidence in this.

cordova plugin remove cordova-plugin-firebase (uninstall current firebase plugin) cordova plugin add https://github.com/briantq/cordova-plugin-firebase.git#android-build (install the proposed fix)

@briantq I tried that branch but I didn't see any difference, I am still getting the same errors as before. I tried it with and without cordova-android-play-services-gradle-release and cordova-android-firebase-gradle-release

briantq commented 6 years ago

@ahmadtawakol Thank you for testing it! Can you list the plugins without the extra gradle release plugins, cordova plugin list.

Also, can you confirm that there were 4 lines added to the project's build.gradle? You would be and to tell as the added lines have a comment that include cordova-plugin_firebase. Those 4 lines are 80% of the fix. In fact, those 4 lines alone should resolve the specific error mentioned in this issue.

ahmadtawakol commented 6 years ago

@briantq Thanks for pointing that out! Turns out that those 4 lines weren't in the build.gradle, probably because I added the platform after I added the plugin? Anyways, I removed the plugin and the platform then added the platform again and added the plugin after that and I confirmed that the extra lines were added. The build was successful and I was able to run the app without any issues!

jfbourne commented 6 years ago

Same issue here: Plugin list:

code-push 2.0.6 "CodePushAcquisition" cordova-plugin-add-swift-support 1.7.1 "AddSwiftSupport" cordova-plugin-browsertab 0.2.0 "cordova-plugin-browsertab" cordova-plugin-buildinfo 2.0.1 "BuildInfo" cordova-plugin-camera 4.0.2 "Camera" cordova-plugin-code-push 1.11.12 "CodePush" cordova-plugin-compat 1.2.0 "Compat" cordova-plugin-customurlscheme 4.3.0 "Custom URL scheme" cordova-plugin-device 2.0.1 "Device" cordova-plugin-dialogs 2.0.1 "Notification" cordova-plugin-facebook4 1.9.1 "Facebook Connect" cordova-plugin-file 4.3.3 "File" cordova-plugin-file-transfer 1.6.3 "File Transfer" cordova-plugin-firebase 2.0.1 "Google Firebase Plugin" // https://github.com/briantq/cordova-plugin-firebase.git#android-build cordova-plugin-googleplus 5.3.0 "Google SignIn" cordova-plugin-inappbrowser 2.0.2 "InAppBrowser" cordova-plugin-ionic-webview 1.1.19 "cordova-plugin-ionic-webview" cordova-plugin-mauron85-background-geolocation 3.0.0-alpha.37 "CDVBackgroundGeolocation" cordova-plugin-nativegeocoder 3.1.1 "NativeGeocoder" cordova-plugin-splashscreen 5.0.2 "Splashscreen" cordova-plugin-statusbar 2.4.1 "StatusBar" cordova-plugin-whitelist 1.3.3 "Whitelist" cordova-plugin-zip 3.1.0 "cordova-plugin-zip" cordova-universal-links-plugin 1.2.1 "Universal Links Plugin" ionic-plugin-keyboard 2.2.1 "Keyboard"

@briantq I tried your suggestion (possible fix) but for some reason the lines are not being added.

julienkermarec commented 6 years ago

Up, same error with cordova-plugin-firebase 2.0.1

briantq commented 6 years ago

@julienkermarec @jfbourne Can you please see the two comments above #1 #2. The change required the add plugin hook to run. Please confirm the proper lines are in the files. If they are not, try removing the /plugins and /platform directory and run cordova prepare to run the platform manager that should install the plugin with the proper hooks.

julienkermarec commented 6 years ago

I can't use the plugin hook, because the build is created in a gitlab pipeline with proxy 👎

briantq commented 6 years ago

@julienkermarec I don't have experience with gitlab pipelines but do have experience with Jenkins pipelines. Is there not a way to include a shell command in your build? I figure I must be missing something.

julienkermarec commented 6 years ago

i can include command in the build.

briantq commented 6 years ago

@julienkermarec why can't you use the plugin hook? It should be run as part of cordova prepare. Again, I probably misunderstood something.

julienkermarec commented 6 years ago

I have this error with the hook on the gitlab pipeline :

npm install npm ERR! Error while executing: npm ERR! /usr/bin/git ls-remote -h -t https://github.com/briantq/cordova-plugin-firebase.git npm ERR! npm ERR! fatal: unable to access 'https://github.com/briantq/cordova-plugin-firebase.git/': Failed to connect to github.com port 443: Connection timed out npm ERR! npm ERR! exited with error code: 128 npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-09-17T10_35_26_842Z-debug.log ERROR: Job failed: exit code 1`

briantq commented 6 years ago

@julienkermarec loading the plugin from github is only a temporary work around. This is not intended to be in production. The commands were simply to test your build locally to confirm that when we push the change it will indeed fix your issue.

If you can run it locally on your machine and confirm that will fix the issue, that will help confirm it will resolve your issue and allow us to release a new official version quicker, which you can reference in your production builds.

alexhildebrand commented 6 years ago

Hey @briantq,

I am running a test with this version of the plugin and I am still getting the same error. It could be however that I am doing something else that is wrong altogether. Cordova plug in list:

cordova-plugin-device 2.0.2 "Device" cordova-plugin-firebase 2.0.1 "Google Firebase Plugin" cordova-plugin-ionic-keyboard 2.1.2 "cordova-plugin-ionic-keyboard" cordova-plugin-ionic-webview 2.1.4 "cordova-plugin-ionic-webview" cordova-plugin-splashscreen 5.0.2 "Splashscreen" cordova-plugin-statusbar 2.4.2 "StatusBar" cordova-plugin-whitelist 1.3.3 "Whitelist"

Android Studio error:

Error:FAILURE: Build failed with an exception.

BUILD FAILED in 1s

Hope this helps.

briantq commented 6 years ago

@alexhildebrand Looks like you have version 2.0.1 of the plugin and not the branch in the PR. Try running cordova plugin remove cordova-plugin-firebase and then cordova plugin add https://github.com/briantq/cordova-plugin-firebase.git#android-build. Confirm you see cordova-plugin-firebase 2.0.1 "Google Firebase Plugin" // https://github.com/briantq/cordova-plugin-firebase.git#android-build when you list your plugins.

The see this comment to confirm the actual fix is installed. If it is not, you can try deleting the /platform directory and running cordova prepare as this should recreate the file correctly.

briantq commented 6 years ago

@jfbourne You might try removing your /platform directory and recreating it using cordova prepare. That should cause all the files to be recreated correctly.

alexhildebrand commented 6 years ago

Hey @briantq,

So I have tried using the cordova command (cordova plugin add https://github.com/briantq/cordova-plugin-firebase.git#android-build) after having removed the platforms and deleting the respective plugin(cordova plugin remove cordova-plugin-firebase).

For some reason the version installed with the cordova command was not correct. So I have now cloned the branch ( https://github.com/briantq/cordova-plugin-firebase#android-build) and have overwritten it in the plugins. When I "git log" the folder, I see that the latest commit is "commit 9ed901b45fe2982695e6383f19632f0f275ffa82", which I think is in accordance to the branch given in https://github.com/briantq/cordova-plugin-firebase.git#android-build . However even though I have followed all these steps, I still get the following cordova list (and the same error):

cordova-plugin-device 2.0.2 "Device" cordova-plugin-firebase 2.0.1 "Google Firebase Plugin" cordova-plugin-ionic-keyboard 2.1.2 "cordova-plugin-ionic-keyboard" cordova-plugin-ionic-webview 2.1.4 "cordova-plugin-ionic-webview" cordova-plugin-splashscreen 5.0.2 "Splashscreen" cordova-plugin-statusbar 2.4.2 "StatusBar" cordova-plugin-whitelist 1.3.3 "Whitelist" phonegap-plugin-barcodescanner 8.0.0 "BarcodeScanner"

Am I still missing something?

---Update: sorry as you said looking at different branch. ignore!

julienkermarec commented 6 years ago

Nice job @briantq ! Your hook works in locally on my machine !!

Screen with official firebase plugin / with your hook plugin

capture d ecran 2018-09-17 a 19 47 56 capture d ecran 2018-09-17 a 20 09 29
briantq commented 6 years ago

@julienkermarec I am glad it worked! Thanks for testing it.

@alexhildebrand I had an issue in the past that the uninstall for the firebase plugin didn't complete successfully. To get around that I just modified the plugin references directly in the config file. You can update the dependency in the config.xml to <plugin name="cordova-plugin-firebase" spec="https://github.com/briantq/cordova-plugin-firebase.git#android-build" />. Additionally you need update the firebase plugin reference in the package.json also to "cordova-plugin-firebase": "git+https://github.com/briantq/cordova-plugin-firebase.git#android-build",. Then delete your /plugins directory to force the removal of the old version of the plugin. Then try running `cordova prepare. I think that should update the plugin version.

alexhildebrand commented 6 years ago

Thank you @briantq, that worked!

soumak77 commented 6 years ago

The fix has been released in v2.0.2

salim7 commented 6 years ago

I still get the error with 2.0.2:

Here is the result of cordova plugins

cordova-plugin-advanced-http 1.11.1 "Advanced HTTP plugin" cordova-plugin-ble-central 1.2.2 "BLE" cordova-plugin-compat 1.2.0 "Compat" cordova-plugin-file 6.0.1 "File" cordova-plugin-firebase 2.0.2 "Google Firebase Plugin" cordova-plugin-inappbrowser 3.0.0 "InAppBrowser" cordova-plugin-splashscreen 5.0.2 "Splashscreen" cordova-plugin-whitelist 1.3.3 "Whitelist" cordova-support-android-plugin 1.0.1 "cordova-support-android-plugin" es6-promise-plugin 4.1.0 "Promise" wifiwizard2 3.0.0 "WifiWizard2"

briantq commented 6 years ago

@salim7 try deleting your plugins and platform directories, then running cordova prepare. That should regenerate the files and resolve your errors.

salim7 commented 6 years ago

@briantq that helped, thank you!

jassiwaliaVC commented 6 years ago

I am still getting this issue

soumak77 commented 6 years ago

Did you follow the README regarding play services?