Bug 40085 - [Google Cloud Messaging/Android] Changing code and rebuilding app results in GCM messages not being received.
Summary: [Google Cloud Messaging/Android] Changing code and rebuilding app results in ...
Status: RESOLVED NOT_ON_ROADMAP
Alias: None
Product: Components
Classification: Xamarin
Component: Xamarin Components ()
Version: Production (addons.xamarin.com)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jon Dick
URL:
Depends on:
Blocks:
 
Reported: 2016-04-04 20:18 UTC by Jon Goldberger [MSFT]
Modified: 2017-09-28 15:22 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_ON_ROADMAP

Description Jon Goldberger [MSFT] 2016-04-04 20:18:12 UTC
## Description

Working from the walkthrough for using GCM on Android [1], the notification is received on first build, but if you change some code and re-deploy, the remote notification will not be received unless the app is manually uninstalled from the device/simulator before re-deploying. 

[1] https://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/android/remote_notifications_in_android/

I noted that after a code change is made and the app is redeployed _without_ uninstalling the app manually from the device first, that the token received from:

>var token = instanceID.GetToken(productID,
                        GoogleCloudMessaging.InstanceIdScope, null);

is the same as on the first build, but if you uninstall manually first then the token received is different. The reporting customer was able to workaround this issue by doing the following:

>var instanceID = InstanceID.GetInstance(this);
>#if DEBUG
>instanceID.DeleteInstanceID ();
>instanceID = InstanceID.GetInstance (Application.Context);
>#endif
>var token = instanceID.GetToken(productID,
                        GoogleCloudMessaging.InstanceIdScope, null);

which forces receiving a new token for the new build without having to uninstall the app manually first. I suspect something is getting cached that is making Google treat the app as the same build/installed app unless the app is manually uninstalled from the device and re-installed. Turning off the Fast Deployment option does not affect the issue. 

## Steps to reproduce:

1. Get the sample code for the Remote Notifications walkthrough here:
https://developer.xamarin.com/samples/monodroid/RemoteNotifications/

2. Set up GCM in your Google APIs console as noted here:
https://developer.xamarin.com/guides/cross-platform/application_fundamentals/notifications/android/google-cloud-messaging/#Setting_Up_Google_Cloud_Messaging

3. Build the MessageSender console app.

4. Build and deploy the ClientApp to an Android device (or simulator with the Google APIs). Make sure you get the "Google play services is available" in the UI. You may also want to note the token value in the Application output to compare it to what is received on future deployments.

5. Run the MessageSender console app.

6. Note that a notification is received on the Android device/simulator. 

7. Stop debugging and make a change in the code (I just added a Console.WriteLine command)

8. Build and deploy the changed app. Note that the received token has not changed.

9. Run the MessageSender console app.

Expected result: Remote notification will be received.

Actual result: Remote notification not received.

10. Uninstall the app from the device. 

11. Build and deploy the app again. Note that the received token has changed.

Expected result: Remote notification will be received.

Actual result: As expected.


## Notes

I realize this is likely not an issue with the component itself, but I was not sure which product this should be filed against, so please move as need be. 

## Environment:

=== Xamarin Studio Business ===

Version 5.10.3 (build 51)
Installation UUID: 964c531b-d928-456b-a9ae-e1f82266b360
Runtime:
	Mono 4.2.3 (explicit/832de4b)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402030004

=== Xamarin.Profiler ===

Version: 0.32.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 7.3 (10183.3)
Build 7D175

=== Xamarin.iOS ===

Version: 9.6.1.9 (Xamarin Business)
Hash: 5f11db8
Branch: master
Build date: 2016-03-25 21:26:55-0400

=== Xamarin.Android ===

Version: 6.0.3.5 (Xamarin Business)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.3

Java SDK: /usr
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.4.2.1 (Xamarin Business)

=== Xamarin Inspector ===

Version: 0.5.0.0
Hash: 45b35bb
Branch: master
Build date: Thu Jan 14 18:53:32 UTC 2016

=== Build Information ===

Release ID: 510030051
Git revision: f3c0d982165f785772d125f02668370d929014fb
Build date: 2016-03-24 18:51:31-04
Xamarin addins: ee5cfd3ecb6b20de47c1d25efb9a9abc101e8ce7
Build lane: monodevelop-lion-cycle6-c6sr3

=== Operating System ===

Mac OS X 10.11.4
Darwin Jons-iMac.local 15.4.0 Darwin Kernel Version 15.4.0
    Fri Feb 26 22:08:05 PST 2016
    root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64
Comment 1 Jon Dick 2017-09-28 15:22:11 UTC
I believe using Firebase Cloud Messaging has fixed this scenario.  If not, we should open a new bug with information specific to FCM instead.