andrehtissot / cordova-plugin-fcm-with-dependecy-updated

Google FCM Push Notifications Cordova Plugin
MIT License
210 stars 275 forks source link

Android Installation #130

Open BRadHoc opened 4 years ago

BRadHoc commented 4 years ago

Hey guys,

I'm using the plugin great on iOS, however I'm now trying to build for android and am stuck at the:

Checking if the app has communicated with our servers. You may need to uninstall and reinstall your app.

screen. In the app the plugin is reporting the fcm token and notification permission as granted but for some reason it can't see it on Google's side. Is there anyway I can debug this?

andrehtissot commented 4 years ago

Yes. If you are still debugging the FCM support, I suggest you send one from the Firebase Console (Messaging section) directly to the device. Giving the token you collect from getToken().

A basic notification then should show up on the device. You might also consider network issues.

BRadHoc commented 4 years ago

Tried with physical device, got the notification through, but still no connection showing (so can't do things like send an FCM to all users on both platforms) It also seems to only work with the app running in the background. The app doesn't fire the wasTapped method as it does on iOS

BRadHoc commented 4 years ago

After some debugging, I discovered that android is sending a slightly different data object than on iOS:

You can detect iOS with:

if (!data.detail.hasOwnProperty("aps")) {

So I've got it working now, except Google SDK setup still does not see android as being alive.

BRadHoc commented 4 years ago

With the firebase registration issue, when trying to follow the instructions on the firebase console. I get this error:

Gradle DSL method not found: 'implementation()'

Anyone know how to fix this? I'm not too familiar with gradle and how it works, it says "Upgrade plugin to version 4.0.1 and sync project" but as far as I'm aware it's either using 4.0.1 or "gradleVersion = '4.10.3'".

If anyone can help with this would be eternally grateful.

andrehtissot commented 4 years ago

Tried with physical device, got the notification through

Cool

but still no connection showing (so can't do things like send an FCM to all users on both platforms)

What do you mean by "connection"?

It also seems to only work with the app running in the background.

When the app is on the foreground, the onNotification should capture the notification. But it won't show in the status bar. https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated#how-it-works

The app doesn't fire the wasTapped method as it does on iOS

For this, are you still triggering FCM notifications from Firebase Console?

andrehtissot commented 4 years ago

After some debugging, I discovered that android is sending a slightly different data object than on iOS:

You can detect iOS with:

if (!data.detail.hasOwnProperty("aps")) {

I fail to see why it would matter. Whatever data object this plugin receives, it'll pass over to the application.

So I've got it working now, except Google SDK setup still does not see android as being alive.

If you get it working, what does it matter if Google itself is not capable of noticing?

andrehtissot commented 4 years ago

With the firebase registration issue, when trying to follow the instructions on the firebase console. I get this error:

Gradle DSL method not found: 'implementation()'

Seems to be related to how the gradle dependencies are defined https://stackoverflow.com/questions/45936305/build-gradle-causes-gradle-dsl-method-not-found-implementation

As you can see in https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/blob/master/src/android/FCMPlugin.gradle The decision of using compile or implementation is based on gradleNumberVersion.

Anyone know how to fix this? I'm not too familiar with gradle and how it works, it says "Upgrade plugin to version 4.0.1 and sync project" but as far as I'm aware it's either using 4.0.1 or "gradleVersion = '4.10.3'".

Please check into your app and plugin's ".gradle" files and try to replace:

dependencies {
    compile "...dependencies..."
}

to:

dependencies {
    implementation "...dependencies..."
}
BRadHoc commented 4 years ago

With the firebase registration issue, when trying to follow the instructions on the firebase console. I get this error:

Gradle DSL method not found: 'implementation()'

Seems to be related to how the gradle dependencies are defined https://stackoverflow.com/questions/45936305/build-gradle-causes-gradle-dsl-method-not-found-implementation

As you can see in https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/blob/master/src/android/FCMPlugin.gradle The decision of using compile or implementation is based on gradleNumberVersion.

Anyone know how to fix this? I'm not too familiar with gradle and how it works, it says "Upgrade plugin to version 4.0.1 and sync project" but as far as I'm aware it's either using 4.0.1 or "gradleVersion = '4.10.3'".

Please check into your app and plugin's ".gradle" files and try to replace:

dependencies {
  compile "...dependencies..."
}

to:

dependencies {
  implementation "...dependencies..."
}

I don't have any dependencies that use implementation or compile, when trying to use either on the firebase instructions I get the error that I pasted:

Gradle DSL method not found: 'implementation()'

BRadHoc commented 4 years ago

After some debugging, I discovered that android is sending a slightly different data object than on iOS: You can detect iOS with:

if (!data.detail.hasOwnProperty("aps")) {

I fail to see why it would matter. Whatever data object this plugin receives, it'll pass over to the application.

So I've got it working now, except Google SDK setup still does not see android as being alive.

If you get it working, what does it matter if Google itself is not capable of noticing?

It matters because the app isn't registering as a device on the fcm network, so if you push campaigns from the firebase console, only iOS devices receive the notifications. The android devices don't get registered to the "all" topic.

andrehtissot commented 4 years ago

Would you provide your package.json or, better yet, a app example that I can clone and debug?

BRadHoc commented 4 years ago

Would you provide your package.json or, better yet, a app example that I can clone and debug?

Sure thing, https://github.com/BRadHoc/cordova-plugin-fcm-with-dependecy-updated-issue130/tree/master

andrehtissot commented 4 years ago

I've cloned your repository, ran cordova run android, and got a successfully-running application

Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=[REDACTED] (recommended setting)
ANDROID_HOME=[REDACTED] (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app
> Task :app:preBuild UP-TO-DATE
> Task :CordovaLib:preBuild UP-TO-DATE
> Task :CordovaLib:preDebugBuild UP-TO-DATE
> Task :CordovaLib:checkDebugManifest UP-TO-DATE
> Task :CordovaLib:processDebugManifest UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :CordovaLib:compileDebugAidl NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :CordovaLib:packageDebugRenderscript NO-SOURCE
> Task :app:compileDebugRenderscript UP-TO-DATE
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources UP-TO-DATE
> Task :CordovaLib:compileDebugRenderscript UP-TO-DATE
> Task :CordovaLib:generateDebugBuildConfig UP-TO-DATE
> Task :CordovaLib:generateDebugResValues UP-TO-DATE
> Task :CordovaLib:generateDebugResources UP-TO-DATE
> Task :CordovaLib:packageDebugResources UP-TO-DATE
> Task :CordovaLib:generateDebugRFile UP-TO-DATE
> Task :CordovaLib:prepareLintJar UP-TO-DATE
> Task :CordovaLib:generateDebugSources UP-TO-DATE
> Task :CordovaLib:javaPreCompileDebug UP-TO-DATE
> Task :CordovaLib:compileDebugJavaWithJavac UP-TO-DATE
> Task :CordovaLib:processDebugJavaRes NO-SOURCE
> Task :CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:mainApkListPersistenceDebug UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:processDebugGoogleServices UP-TO-DATE
> Task :app:mergeDebugResources UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:processDebugResources UP-TO-DATE
> Task :app:compileDebugJavaWithJavac UP-TO-DATE
> Task :app:compileDebugNdk NO-SOURCE
> Task :app:compileDebugSources UP-TO-DATE
> Task :app:mergeDebugShaders UP-TO-DATE
> Task :app:compileDebugShaders UP-TO-DATE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :CordovaLib:mergeDebugShaders UP-TO-DATE
> Task :CordovaLib:compileDebugShaders UP-TO-DATE
> Task :CordovaLib:generateDebugAssets UP-TO-DATE
> Task :CordovaLib:packageDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets UP-TO-DATE
> Task :app:validateSigningDebug UP-TO-DATE
> Task :app:signingConfigWriterDebug UP-TO-DATE
> Task :app:transformClassesWithDexBuilderForDebug UP-TO-DATE
> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug UP-TO-DATE
> Task :app:transformDexArchiveWithDexMergerForDebug UP-TO-DATE
> Task :app:mergeDebugJniLibFolders UP-TO-DATE
> Task :CordovaLib:compileDebugNdk NO-SOURCE
> Task :CordovaLib:mergeDebugJniLibFolders UP-TO-DATE
> Task :CordovaLib:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE
> Task :CordovaLib:transformNativeLibsWithIntermediateJniLibsForDebug UP-TO-DATE
> Task :app:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
> Task :app:packageDebug UP-TO-DATE
> Task :app:assembleDebug UP-TO-DATE
> Task :app:cdvBuildDebug UP-TO-DATE

BUILD SUCCESSFUL in 0s
43 actionable tasks: 43 up-to-date
Built the following apk(s):
    [REDACTED]/cordova-plugin-fcm-with-dependecy-updated-issue130/platforms/android/app/build/outputs/apk/debug/app-debug.apk
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=[REDACTED] (recommended setting)
ANDROID_HOME=[REDACTED] (DEPRECATED)
No target specified and no devices found, deploying to emulator
Using apk: [REDACTED]/cordova-plugin-fcm-with-dependecy-updated-issue130/platforms/android/app/build/outputs/apk/debug/app-debug.apk
Package name: io.firebase.issue
INSTALL SUCCESS
LAUNCH SUCCESS

... But,... after "upgrading gradle", it actually screw up the application build.

As you can find here https://developer.android.com/studio/releases/gradle-plugin, there is a version matching expected on Gradle version. Which, for your cordova-android version, appears to be, at least 6.1.1.

So, I'd recommend to manually set the desired gradle version on "File > Project Structure > Project" to something like:

Screenshot 2020-07-25 at 17 27 56

andrehtissot commented 4 years ago

Let me know if adjusting that solved your issue.

BRadHoc commented 4 years ago

I made the following changes:

https://github.com/BRadHoc/cordova-plugin-fcm-with-dependecy-updated-issue130/commit/59e1e5522e328278ab8d638d4532b9a8216b9763

build is successful but still doesn't show in firebase console as connected

Screenshot 2020-07-26 at 22 51 52

andrehtissot commented 4 years ago

That's so strange. In my local test, it went so fast I wasn't even able to see this step 4 message. I'll continue trying, but currently I have no idea why would you face such issue.

BRadHoc commented 4 years ago

Thanks for the assist, scratching my brains too. From everyone else's issues I would have thought iOS would be the one causing issues haha

andrehtissot commented 4 years ago

@BRadHoc I wasn't able to test it :/ It just works...

Here is a gif: 2020-08-01 22-12-41 2020-08-01 22_14_01

BRadHoc commented 4 years ago

I've tried with 2 brand new projects (including the one I sent you) and just can't seem to get it to connect. I'm wondering then if it's something to do with the environment, if you're running the same code and getting connected straight away?

andrehtissot commented 3 years ago

I'm sorry. I really don't know what's happening on your environment.