Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cordova platform add does not run after_plugin_add hooks #869

Closed
wyldsteed opened this issue Sep 25, 2018 · 26 comments · Fixed by #883
Closed

Cordova platform add does not run after_plugin_add hooks #869

wyldsteed opened this issue Sep 25, 2018 · 26 comments · Fixed by #883

Comments

@wyldsteed
Copy link

wyldsteed commented Sep 25, 2018

Describe the bug
on cordova platform add android the system doesn't perform the necessary hooks to utilize android.

To Reproduce
Scenario 1

cordova platform add android
cordova plugin add cordova-plugin-firebase

Take note of: compare platforms/android/build.gradle

Scenario 2

cordova platform remove android
cordova plugin add cordova-plugin-firebase
cordova platform add android

Scenario 1 can be built successfully scenario 2 will fail with the following statement

cordova build android

FAILURE: Build failed with an exception.

  • Where:
    Script '*******/platforms/android/cordova-plugin-firebase/mobileweb-build.gradle' line: 33

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

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more
    log output.

  • Get more help at https://help.gradle.org

Expected behavior
Adding and removing platforms should have no side effect on how the system performs.

Solution
In plugin.xml i added the following script to perform the same actions as after_plugin_add on platform_add

<hook src="scripts/after_plugin_add.js" type="after_platform_add" />
@Mykiee
Copy link

Mykiee commented Sep 25, 2018

I am able to add platform, say android, but I am unable to build android apk. Here is the log while build.

Running command: /............./hooks/after_prepare/010_add_platform_class.js 

add to body class: platform-android
Preparing Firebase on Android
ANDROID_HOME=/......../android-sdk-linux
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
:wrapper


BUILD SUCCESSFUL


Total time: 3.138 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.10/userguide/gradle_daemon.html
Subproject Path: CordovaLib
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.

	at build_1m12ji9l3yfzegi0ac6nf3wvm.run(/..................../platforms/android/build.gradle:142)


FAILURE: 
Build failed with an exception.


* Where:

Script '.........../platforms/android/cordova-plugin-firebase/guardTrack-build.gradle' line: 27


* What went wrong:

A problem occurred evaluating root project 'android'.
> Plugin with id 'com.google.gms.google-services' not found.

* 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: 1.58 secs
Error: /........../platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* Where:
Script '...................../platforms/android/cordova-plugin-firebase/guardTrack-build.gradle' line: 27

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

I started facing issue last night. Tried changing android platform version to latest as well as ~6.3.0 but no gains.

@briantq
Copy link
Contributor

briantq commented Sep 25, 2018

@Mykiee the work around is to wipe out the platform/android directory and run cordova prepare. That will run the plugin add script again.

@wyldsteed why don't you create a pull request with the change. We need to make sure to remove the changes on platform events, so just remember to include the clean up step also (should be an obvious one liner). Please see the Contribution Guidelines if you have any questions on how to do it.

@Mykiee
Copy link

Mykiee commented Sep 25, 2018

@briantq thanks for your response. Do you need me to first remove android platform (using command) and then run cordova prepare or after removing platform, adding back it and then running cordova prepare?

@briantq
Copy link
Contributor

briantq commented Sep 25, 2018

@Mykiee the best way to do it is to delete the plugins/ directory and platforms/ directory then run the command. It should rebuild everything from scratch which should add the correct modifications. That has worked for me in the past when I get in a weird state. Let me know if that does not resolve your issue.

@Mykiee
Copy link

Mykiee commented Sep 25, 2018

@briantq i tried both way: removing android platform and then running cordova prepare, which gives following error:
Error: No platforms added to this project. Please use cordova platform add .

And re-adding android platform, then running cordova prepare which again give same error as above.

add to body class: platform-android
Preparing Firebase on Android
ANDROID_HOME=/home/mayank/Desktop/locals/android-sdk-linux
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
Subproject Path: CordovaLib
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
  at build_1m12ji9l3yfzegi0ac6nf3wvm.run(...../platforms/android/build.gradle:142)

FAILURE: Build failed with an exception.

* Where:
Script '...../platforms/android/cordova-plugin-firebase/guardTrack-build.gradle' line: 27


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

* 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: 1.283 secs
Error: ...../platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* Where:
Script '...../platforms/android/cordova-plugin-firebase/guardTrack-build.gradle' line: 27

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

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

@briantq
Copy link
Contributor

briantq commented Sep 25, 2018

@Mykiee make sure the Android platform is added. Then run rm -rf platforms and rm -rf plugins to physically remove the directories. Then when you run cordova prepare, it will reinstall the plugins and platforms.

@Mykiee
Copy link

Mykiee commented Sep 25, 2018

@briantq After applying your workaround, i am getting following error now. I tried to solve it as given solutions on stackoverflow but the problem persists.

FAILURE: Build failed with an exception.

* Where:
Build file '...../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: 1.055 secs
Error: ...../platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* Where:
Build file '...../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.

@ghost
Copy link

ghost commented Sep 25, 2018

having the same problem, was wondering if it after_plugin_add.js is just bound to a wrong hook, shouldn't it be associated with after_plugin_install instead, since this is where you want to apply that, seems to work for me, not sure for now if there's any side effects.

@Mykiee
Copy link

Mykiee commented Sep 25, 2018

@oborudko thanks for your response. May you please elaborate it with code example and detail description so that it will help us too. Regards

@ghost
Copy link

ghost commented Sep 25, 2018

just in plugin.xml

change the hook to
<hook src="scripts/after_plugin_add.js" type="after_plugin_install" />

you can look at https://cordova.apache.org/docs/en/dev/guide/appdev/hooks/index.html the meaning of each type, I kinda think after_plugin_install should be where the stuff is modified in the gradle files, otherwise after each platform rm you will end up to have to to purge and re-install the plugin itself...agian just a non-educated guess that seems to work for me

@Mykiee
Copy link

Mykiee commented Sep 25, 2018

@oborudko same problem persist. I edited plugin.xml of firebase plugin as saidby you, and then removed android platform add readded platfom. But still am getting same error.

@Repox
Copy link

Repox commented Sep 26, 2018

I tried adding the hook to plugin.xml as suggested and this fixed my problem.

@ghost ghost mentioned this issue Sep 26, 2018
@Mykiee
Copy link

Mykiee commented Sep 26, 2018

@Repox may you please let me know the way you did that? Because may be that is making difference. What I did was installed plugin, removed platform and run cordova prepare (changes done in plugin.xml of plugin) but still the results are same. :(

Any solutions from contributors? I would be thankful to them.

@kevinswartz
Copy link

I've got the exact same issue as @Mykiee. I've tried both:
<hook src="scripts/after_plugin_add.js" type="after_platform_add" />
and <hook src="scripts/after_plugin_add.js" type="after_plugin_install" />

I'm on cordova 6.5.0 and on my android platform is at 6.3.0

@Repox
Copy link

Repox commented Sep 26, 2018

may you please let me know the way you did that?

@Mykiee Sure.

I made sure that the plugin, cordova and gradle was up to date. Gradle is v4.10.2, plugin is v2.0.2 and cordova is v8.0.0

I added <hook src="scripts/after_plugin_add.js" type="after_plugin_install" /> to ./plugins/cordova-plugin-firebase/plugin.xml as the last hook before the </plugin> closing element.

I just removed all platforms, and added android with cordova platform add android and then I could easily build with cordova build android.

@soumak77
Copy link
Contributor

@Mykiee @kevinswartz could you test PR #872 to see if it fixes this issue for you. That'll help get the fix released faster. You can check our contributing doc for info on how to test a PR.

@kevinswartz
Copy link

@soumak77 Thanks for the PR, but I'm still seeing the same thing. I've seen a couple sources mentioning that upgrading gradle to 4.0 fixes things. I'm not in a position to update my android platform right now, but maybe @Mykiee can?

@Mykiee
Copy link

Mykiee commented Sep 28, 2018

@soumak77 @Repox I did the same you told. But still same error persisted. So what i did, I commented google() function from build.gradle file and after that it worked without build failure. Also then I checked by sending push to the device from google firebase, and it was receiving. What was issue with the above method, is still not clear to me.

@kevinswartz Please try removing google function and let me know if it works for as well.

Will dig into this to know more about the reason. If anybody have any idea about that, please share your knowledge. Thanks in advance.

@soumak77
Copy link
Contributor

@Mykiee your issue is related to #881. Waiting for a response to my question on that thread to see if we even need to add the google() repo.

@Mykiee
Copy link

Mykiee commented Sep 28, 2018

@soumak77 aren't we doing that by

        maven {
            url "https://maven.google.com"
        } 

as I guess it also for Google's maven repo, if am not wrong. Please rectify me if am in wrong direction. Regards

@soumak77
Copy link
Contributor

I'm wondering whether the setup steps have changed since the initial Crashlytics release. The official firebase guide don't show needing to add google(), but another non-official guide shows to add it. I'm thinking we could just remove the google() repo and things would work as expected as you have witnessed.

@Mykiee
Copy link

Mykiee commented Sep 28, 2018

I suggest to go with official one until it's not working the way it should.

@soumak77
Copy link
Contributor

For those encountering this issue, please install the plugin from master to verify this has been fixed

cordova plugin add https://github.com/arnesson/cordova-plugin-firebase.git#master

@kevinswartz
Copy link

Just tried installing the plugin from master now, but I have the same error. It's mentioned in a few other places, as in #881 but I think the root of this is that I need to upgrade gradle. In my gradle-wrapper.properties file I have this:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

From what I understand, upgrading to 4.1 should fix this. I'm in the middle of a project and I can't do that right now, I'll get there when I can. Thanks for the help everyone

@josuper
Copy link

josuper commented Mar 7, 2019

@soumak77 where can i find plugin.xlm ?

@topalavlad
Copy link

I think the current hook usage: <hook src="scripts/after_plugin_add.js" type="after_plugin_add" /> is wrong because of the following case:

Having an Android/ios app, if I add ios platform and build for ios and only after that I add/build android, the following steps are not added to gradle.build:

        androidHelper.removeFabricBuildToolsFromGradle();
        androidHelper.addFabricBuildToolsGradle();

Similarly, the ios steps won't be triggered if the platforms are installed in reverse order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants