havesource / cordova-plugin-push

Register and receive push notifications
MIT License
150 stars 283 forks source link

AndroidX support #83

Closed robertszuba closed 3 years ago

robertszuba commented 3 years ago

Hi,

first of all, thank you for maintaining the push plugin!

I was wondering, what are your plans on migrating this project from deprecated Android Support Library to AndroidX? I saw your message here https://github.com/havesource/cordova-plugin-push/issues/18#issuecomment-682517766 that you wanted to stay with the deprecated dependency for a while, since it's hard to use both the old and new one. However, many cordova plugins already migrated to the new one, which causes the dependency conflicts if they are used with the Cordova Push Plugin. To fix the issue people have to either stay with older versions of plugins or create a new fork of the Cordova Push Plugin with the AndroidX support, which is troublesome in a long term.

There's also this pull request awaiting https://github.com/havesource/cordova-plugin-push/pull/66

Therefore I'd like to ask what are the plans regarding the AndroidX support, when can we expect it?

erisu commented 3 years ago

what are the plans regarding the AndroidX support, when can we expect it?

Migrating to AndroidX will be in the next major release.

I can't give you an exact release date, but I will try and start looking into the changes maybe next week. This would be mostly researching to outline some changes I want to land in version 3 other than just Android X. For example, upgrading the FCM default version.

I also just released version 2.0.0 that resolved the iOS and npm restore related issues.

There's also this pull request awaiting #66

This PR needs to be fixed before being ever be approved or merged. The scope of this PR itself is too excessive. It has too many changes and focuses on many tasks. It should be updated to focus on one task.

With that PR, it needs to

  1. Rebased with master & fix conflicts
  2. Remove all iOS-related changes
  3. Remove the changes done in PushPlugin.m.
  4. Relabel the PR title and commit. E.g. "breaking(android): use AndroidX library"

AndroidX Support

Have you tried the following steps to see if this works for supporting AndroidX right now?

  1. Add the preference variable AndroidXEnabled with the value of true in config.xml
<preference name="AndroidXEnabled" value="true" />
  1. Add the cordova-plugin-androidx-adapter plugin.
cordova plugin add cordova-plugin-androidx-adapter

I can build successfully with the above setup but have not tested in-depth. The "cordova-plugin-androidx-adapter" is used to help get Android X working for plugins that haven't migrated yet. Also, in my test, it still uses the default FCM version 18.+.

ppetree commented 3 years ago

I'm not sure how you're getting a build, perhaps you can document all your settings. My builds fail consistently.

With preference:

    <preference name="AndroidXEnabled" value="true" />

And plugins:

  <plugin name="cordova-plugin-androidx-adapter" spec="1.1.3" />
  <plugin name="cordova-android-play-services-gradle-release" spec="4.0.0" />
  <plugin name="@havesource/cordova-plugin-push" spec="1.0.0">
    <variable name="SENDER_ID" value="888888888888" />
    <variable name="FCM_VERSION" value="17.0.0" />
  </plugin>

Using CLI 10.0 I can not get a successful build. I get the following errors:

> Task :app:compileDebugJavaWithJavac FAILED
/platforms/android/app/src/main/java/com/adobe/phonegap/push/PushInstanceIDListenerService.java:6: error: cannot find symbol
import com.google.firebase.iid.InstanceIdResult;
                              ^
  symbol:   class InstanceIdResult
  location: package com.google.firebase.iid
/platforms/android/app/src/main/java/com/adobe/phonegap/push/PushInstanceIDListenerService.java:13: error: method does not override or implement a method from a supertype
  @Override
  ^
/platforms/android/app/src/main/java/com/adobe/phonegap/push/PushInstanceIDListenerService.java:15: error: cannot find symbol
    super.onNewToken(s);
         ^
  symbol: method onNewToken(String)
/platforms/android/app/src/main/java/com/adobe/phonegap/push/PushInstanceIDListenerService.java:18: error: cannot find symbol
      .addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
                                                  ^
  symbol:   class InstanceIdResult
  location: class PushInstanceIDListenerService
/platforms/android/app/src/main/java/com/adobe/phonegap/push/PushInstanceIDListenerService.java:20: error: cannot find symbol
        public void onSuccess (InstanceIdResult instanceIdResult) {
                               ^
  symbol: class InstanceIdResult
/platforms/android/app/src/main/java/com/adobe/phonegap/push/PushInstanceIDListenerService.java:17: error: cannot find symbol
    FirebaseInstanceId.getInstance().getInstanceId()

This is with both the 1.0 and 2.0 versions of the plugin and with and without jetifier enabled.

erisu commented 3 years ago

@ppetree

$ cordova info

Cordova Packages:

    cli: 10.0.0
        common: 4.0.2
        create: 3.0.0
        lib: 10.0.0
            common: 4.0.2
            fetch: 3.0.1
            serve: 4.0.0

Project Installed Platforms:

    android: 9.0.0

Project Installed Plugins:

    @havesource/cordova-plugin-push: 2.0.0
    cordova-plugin-androidx-adapter: 1.1.3
    cordova-plugin-whitelist: 1.3.4

Environment:

    OS: macOS 11.1 (20C69) (darwin 20.2.0) x64
    Node: v14.15.4
    npm: 6.14.10

android Environment:

    android:
ERROR: Command failed with ENOENT: android list target
spawn android ENOENT

Project Setting Files:

    config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.foobar.cordovaTest" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>cordovaTest</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="https://cordova.apache.org/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />

        <!-- Android -->
    <platform name="android">
        <preference name="AndroidXEnabled" value="true" />
        <allow-intent href="market:*" />

        <!-- Google Services Configurations (e.g. Cloud Messaging) -->
        <resource-file src="res/android/google-services.json" target="/app/google-services.json" />
    </platform>
</widget>

    package.json:
--- Start of Cordova JSON Snippet ---
{
  "plugins": {
    "cordova-plugin-whitelist": {},
    "@havesource/cordova-plugin-push": {
      "ANDROID_SUPPORT_V13_VERSION": "28.0.0",
      "FCM_VERSION": "18.+"
    },
    "cordova-plugin-androidx-adapter": {}
  },
  "platforms": [
    "android"
  ]
}
--- End of Cordova JSON Snippet ---

Here is also a build command output

$ cordova build android

[Gradle Properties] Detected Gradle property "android.useAndroidX" with the value of "true", Cordova's recommended value is "false"
[Gradle Properties] Detected Gradle property "android.enableJetifier" with the value of "true", Cordova's recommended value is "false"
cordova-plugin-androidx-adapter: Processed 19 source files in 298ms
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/Users/cordova/Library/Android/sdk (recommended setting)
ANDROID_HOME=/Users/cordova/Library/Android/sdk (DEPRECATED)
Using Android SDK: /Users/cordova/Library/Android/sdk
Reading build config file: /Users/cordova/git/open-source/@havesource/cordovaTest/build.json
Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 3s
1 actionable task: 1 executed
Subproject Path: CordovaLib
Subproject Path: app
Starting a Gradle Daemon (subsequent builds will be faster)

> Configure project :app
Adding classpath: com.google.gms:google-services:4.2.0
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

> Task :app:processDebugGoogleServices
Parsing json file: /Users/cordova/git/open-source/@havesource/cordovaTest/platforms/android/app/google-services.json

> Task :app:compileDebugJavaWithJavac
注意:一部の入力ファイルは非推奨のAPIを使用またはオーバーライドしています。
注意:詳細は、-Xlint:deprecationオプションを指定して再コンパイルしてください。
注意:/Users/cordova/git/open-source/@havesource/cordovaTest/platforms/android/app/src/main/java/com/adobe/phonegap/push/PushPlugin.javaの操作は、未チェックまたは安全ではありません。:app:compileDebugJavaWithJavac

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 16s
42 actionable tasks: 42 executed
Built the following apk(s):
    /Users/cordova/git/open-source/@havesource/cordovaTest/platforms/android/app/build/outputs/apk/debug/app-debug.apk
ppetree commented 3 years ago

Thanks! That helped a lot!

Cachwir commented 3 years ago

Hi. I updated cordova to 10.0.0 and cordova-android to 9.0.0 in order to use other plugins and I left phonegap-plugin-push for cordova-plugin-push. I didn't change the code as it seems to be the same on the documentation, and I made sure to add androidx's support. However, when I send a push notification from the server (using the registrationId, with success), there is no reaction on the phone. No notification, no vibration, nothing (I tested in background and in killed modes). I checked the logs and here's what I managed to fetch :

V/AlarmManager(31697): set(PendingIntent{63f10b5: PendingIntentRecord{82c1b10 com.google.android.gms broadcastIntent}}) : type=2 triggerAtTime=2221692898 win=0 tElapsed=2221692898 maxElapsed=2221692898 interval=0 flags=0xd
I/SendBroadcastPermission(16904): action:com.google.android.c2dm.intent.RECEIVE, mPermissionType:0
I/SendBroadcastPermission(16904): action:com.google.android.c2dm.intent.RECEIVE, mPermissionType:0
W/GCM     (16904): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.nectardecode.myvizito.atest (has extras) }

I checked the permissions and my app has the permission to display notifications. It was working well with phonegap-plugin-push on cordova-android 8 and cordova 8. Do you need me to make a new issue or is posting here fine ?

ppetree commented 3 years ago

Please make a new post and make sure you've created created channels in your in your app or android won't play sounds.

Cachwir commented 3 years ago

Aren't channels only for Android 8 and more ? My phone is on Android 6.

Cachwir commented 3 years ago

Ok. I found the reason. Stupid me had installed cordova-plugin-firebasex which was taking cordova-plugin-push's job but couldn't do it right (he can't find the pushed notification's data properly). I discovered something interesting on the way, I'll make a new issue about that.

erisu commented 3 years ago

I will close this ticket as the AndroidX support PR was created and merged into master.