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

Build fails after downloading @havesource/cordova-plugin-push plugin . #239

Closed
gauravpatil79 opened this issue Aug 29, 2023 · 11 comments
Closed

Comments

@gauravpatil79
Copy link

gauravpatil79 commented Aug 29, 2023

Bug Report

Getting Error after giving cordova build command (@havesource/cordova-plugin-push is installed) .

Expected Behaviour

Build Successful without any errors

Actual Behaviour

Build fails as soon as we give the cordova build command.
Following is the error:
Adding classpath: com.google.gms:google-services:4.3.8
Warning: The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.

FAILURE: Build failed with an exception.

  • What went wrong:
    The Android Gradle plugin supports only kotlin-android-extensions Gradle plugin version 1.6.20 and higher.
    The following dependencies do not satisfy the required version:
    root project 'Gp' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20

In my root folders build.gradle file I have this code :
dependencies {
classpath "com.android.tools.build:gradle:${cordovaConfig.AGP_VERSION}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${cordovaConfig.KOTLIN_VERSION}"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Already tried :
1.statically changed AGP and KOTLIN versions like following :
classpath "com.android.tools.build:gradle:7.4.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.21"

2.Lowered jdk version to 8 current is 11
3.Lowered gradle version to 7.4.2 current is 8.2.1
4.Lowered cordova version to 10 current is 12
5.Lowered android studio version to Android Studio Dolphin | 2021.3.1 current is Android Studio Giraffe | 2022.3.1

Even after lowering and trying faced the same error+ few new errors too.

Project Installed Platforms:

 cordova version -12.0.0 (cordova-lib@12.0.1)
Gradle -8.2.1
Kotlin:       1.8.20

Groovy: 3.0.17
Java version "11.0.19"
Android Studio Giraffe | 2022.3.1

----------------------xxxxxxxxxxxxxx-------------------------

@Jammmmm
Copy link

Jammmmm commented Aug 29, 2023

I just encountered this problem as well.

I fixed it by adding to config.xml:

<preference name="GradlePluginKotlinVersion" value="1.6.20" />

Then running:

cordova prepare
cordova clean

I haven't done extensive testing yet but it seems to work on my end. If this is indeed the solution, hopefully it can be merged into the main repo so we can remove that preference value from our config files.

EDIT: Someone has already submitted a pull request at #224 which sets the version to 1.7.10

@andreszs
Copy link

Try the solution shown here #218 (comment)

@gauravpatil79
Copy link
Author

Yes it worked Thanks mate. @andreszs @Jammmmm

@gauravpatil79
Copy link
Author

gauravpatil79 commented Sep 1, 2023

@andreszs @Jammmmm I can build app successfully but the notification popup is not coming on opening the app...any suggestions?

@pellejero44
Copy link

pellejero44 commented Sep 1, 2023

The notification popup is not displayed because in android API 33 we have to request for the permission manually, there is a PR that you can test: #238

@lordStrider
Copy link

Don't use Master version 3.0.1 use @havesource/cordova-plugin-push@4.0.0-dev.0 version
don't forget to set Kotlin version in config.xml:
<preference name="GradlePluginKotlinVersion" value="1.6.20" />
Adds the following permission to the AndroidManifest.xml:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
and everything will work correctly.

@gauravpatil79
Copy link
Author

gauravpatil79 commented Sep 4, 2023

@lordStrider I tried your solution but still not getting the popup .

@lordStrider
Copy link

when you debug the app do you receive the registrationID?

image

@Jammmmm
Copy link

Jammmmm commented Sep 4, 2023

Here's what I've done to personally fix it.

  1. Add <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> and <preference name="GradlePluginKotlinVersion" value="1.7.10" /> to config.xml. For example:
	<platform name="android">
		...
		...
        	<config-file parent="/manifest" target="AndroidManifest.xml">
            		<uses-permission android:name="android.permission.INTERNET" />
            		<uses-permission android:name="android.permission.NETWORK_ACCESS" />
            		<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
           		 <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
        	</config-file>
        	...
        	...
		<preference name="GradlePluginKotlinVersion" value="1.7.10" />
	</platform>
  1. Change your targetSdkVersion to 33 in config.xml. For example:
    <platform name="android">
        <preference name="android-minSdkVersion" value="26" />
        <preference name="android-targetSdkVersion" value="33" />
        ...
        ...
    </platform>
  1. Add the latest DEV version of the plugin:

    cordova plugin add @havesource/cordova-plugin-push@dev

  2. Merge the code from this pull request: fix(android): Ask for POST_NOTIFICATIONS permission if necessary #238 - By "merge", I mean download the three files from that pull request and overwrite those you have on your filesystem with the newly downloaded files.

  3. (optional) Find/Replace every instance of Kotlin version 1.5.20 and replace with 1.7.10. I don't believe this is strictly necessary but I've found it speeds up my compile time and reduces the size of my app, which is nice. For example:

    Any files that contain:

     <preference name="GradlePluginKotlinVersion" value="1.5.20" />
    

    I replace with:

     <preference name="GradlePluginKotlinVersion" value="1.7.10" />
    
  4. Add the Android permissions plugin:

    cordova plugin add cordova-plugin-android-permissions

  5. (optional) Add the Device plugin so you can test device version. Obviously this isn't necessary if you don't need to do that test:

    cordova plugin add cordova-plugin-device

  6. Change your push code to use the permissions plugin. Mine is similar to the following. If true is returned, push notifications have been accepted. Proceed with init as required:

	function checkPush ()
	{
		var permission = false;

		if (device.platform == 'android')
		{
			PushNotification.hasPermission (function (data)
			{
				if (data.isEnabled === true)
				{
					permission = true;
				}
				else
				{
					// Get permissions for Android v13 (SDK v33) and above
					if (parseInt (device.version) >= 13)
					{
						cordova.plugins.permissions.requestPermissions (['android.permission.POST_NOTIFICATIONS'],
							function (status)
							{
								permission = (status.hasPermission) ? true : false;
							},
							function () { }
						);
					}
				}
			}, function (err) { });
		}

		return permission;
	}
  1. cordova prepare, clean, build, etc.

This has been tested on Android 9, Android 13 and Android 14 Beta devices at BrowserStack.
I've tested new installations of the app as well as installing an update to an old version.
I'll be testing on my actual devices in the near future.

What I've found is:

  • On 13 and 14 beta, the prompt appears, as expected.
  • On all versions, the push notification works when the app is in the foreground or background.
  • On all versions, the push notification does not work when the app is killed. I think is a limitation of BrowserStack because I tried it with an old version of my app, which definitely receives notifications on my real devices even when they're killed, and it wasn't receiving them.
  • On all versions, denying the permission works as expected (ie. no notifications are received).

From what I'm reading, people have issues with iOS too. If that doesn't concern you, the above should be all you need.
I personally need to support iOS so I'll be tackling that soon. I think the "dpa99c/cordova-diagnostic-plugin" plugin might be the solution. I'll find out soon enough.

Hope the above helps someone! And hopefully @havesource is able to push out an update that addresses these issues, or maybe someone (with extensive knowledge in the area) can fork the project and continue providing support.

@ggiordan
Copy link

@Jammmmm , trying to follow your steps above and I'm a bit confused on #4. You say to merge in the PR from #238
Did you edit the code after adding the plugin? Or did you download the repo and do the merge via git?

@Jammmmm
Copy link

Jammmmm commented Sep 20, 2023

@ggiordan Sorry for the confusion. I meant after adding the plugin in step 3, I downloaded each file from #238 (there's only three files) and overwrote the originals on my filesystem with the downloaded files.

I'm somewhat of a git newbie so there's likely a command that does that automatically, but it was just three files so it's done very quickly.

EDIT: I've updated that step to be clearer for anyone in the future.

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

No branches or pull requests

6 participants