xamarin / GoogleApisForiOSComponents

MIT License
225 stars 161 forks source link

`GaiConstants` values are all null in iOS app extension #116

Closed kspearrin closed 6 years ago

kspearrin commented 6 years ago

Pretty weird behavior here, but whenever we updated Xamarin.Google.iOS.Analytics from version 3.17.0.1 => 3.17.0.2 our action app extension started breaking. Upon further investigation we find that this line in our code is the problem:

_tracker.Set(GaiConstants.ScreenName, pageName);

It throws an ArgumentNullException:

'parameterName' cannot be null.

Debugging the line shows that all values in GaiConstants are null.

This only seems to happen from our app extension and not the main app. The only difference between the build that does work and the build that does not work is updating from version 3.17.0.1 => 3.17.0.2.

Any ideas?

Project for reference: https://github.com/bitwarden/mobile

SotoiGhost commented 6 years ago

@kspearrin can you share an isolated test case with the problem, please? That would help us to speed up the process to find out if this is a bug in the tool.

kspearrin commented 6 years ago

@SotoiGhost I've narrowed this down further to the Xamarin.Build.Download dependency. I can leave Xamarin.Google.iOS.Analytics at version 3.17.0.1 and just install Xamarin.Build.Download version 0.4.7 and the same problem occurs. Without installing Xamarin.Build.Download explicitly you get version 0.4.3 which doesn't appear to have this issue.

I'll see if I can put together an isolated test project.

kspearrin commented 6 years ago

@SotoiGhost I created a trimmed down version of our app here that just has a simple Forms page with the iOS app extension. Strangely enough, with this version it seems to occur even with v3.17.0.1 as well. Seems very inconsistent, but it's definitely still happening here even with all the other noise from the app removed. Feel free to update it v3.17.0.2 to still see the same behavior.

https://github.com/kspearrin/BuildDownloadTest

Just set your breakpoint here when launching the extension:

https://github.com/kspearrin/BuildDownloadTest/blob/master/src/iOS.Extension/LoadingViewController.cs#L19

screen shot 2017-12-16 at 9 59 22 am

SotoiGhost commented 6 years ago

@kspearrin For me is working. I tested your test case on Simulator with iOS 11.2, 11.0.2, 10.3.1 and 9.3 and worked for me:

image

I couldn't test it on a real device because is asking me for a provisioning profile with certain entitlements enabled (even disabling all of them, keeps asking me something else). So, I created a quick sample, tested it on an iPhone 7 with iOS 11.1.2 and worked for me:

image

What was your environment test?

kspearrin commented 6 years ago

That's weird. I am testing on an iPhone 6s device, macOS with VS 2017. Did you try updating Xamarin.Google.iOS.Analytics to 3.17.0.2?

=== Visual Studio Enterprise 2017 for Mac ===

Version 7.3 (build 799)
Installation UUID: 15eeb07b-27a3-4e5d-b35e-edfee3d0f28c
Runtime:
    Mono 5.4.1.7 (2017-06/e66d9abbb27) (64-bit)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 504010007

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    2.0.3
    2.0.0
SDK: /usr/local/share/dotnet/sdk/2.0.3/Sdks
SDK Versions:
    2.0.3
    2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

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

=== Xamarin.Android ===

Not Installed

=== Xamarin Inspector ===

Version: 1.3.2
Hash: 461f09a
Branch: 1.3-release
Build date: Tue, 03 Oct 2017 18:26:57 GMT
Client compatibility: 1

=== Apple Developer Tools ===

Xcode 9.2 (13772)
Build 9C40b

=== Xamarin.iOS ===

Version: 11.6.1.2 (Visual Studio Enterprise)
Hash: 6857dfcc
Branch: xcode9.2
Build date: 2017-12-04 21:20:41-0500

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Build Information ===

Release ID: 703000799
Git revision: df590420ea5bc681994baefff2eabdaad889fba9
Build date: 2017-12-05 09:23:45-05
Xamarin addins: 51068d6eaf3b6fb4fbc72b33cb869b0ebff04ec5
Build lane: monodevelop-lion-d15-5

=== Operating System ===

Mac OS X 10.13.2
Darwin 17.3.0 Darwin Kernel Version 17.3.0
    Thu Nov  9 18:09:22 PST 2017
    root:xnu-4570.31.3~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Internet of Things (IoT) development (Preview) 7.1
SotoiGhost commented 6 years ago

I have the same result updating to most recent version. Can you try deleting the bin and obj folder, removing the app from your device and reinstalling it?

kspearrin commented 6 years ago

I just tested this with a fresh pull from the GitHub repo. I run it using the iPhone 8 simulator and it works correctly on 3.17.0.1 and 3.17.0.2. No values are null.

However, whenever I pull a fresh copy again, deploy it to my iPhone 6S device (previously app uninstalled completely) it works on 3.17.0.1 but when I update to 3.17.0.2 (clearing bin and obj between and uninstalling previous deployed app) I get null values on all GaiConstants properties. Seems to be something definitely to do when deployed to device rather than running in simulator. Device is running iOS 11.2.1.

SotoiGhost commented 6 years ago

So, just to be clear. The steps to reproduce the bug are:

  1. Have installed G.Analytics v3.17.0.1 package in fresh project
  2. Run the project for the first time on a device
  3. Update the package to v3.17.0.2
  4. Clean the project, clear bin and debug folders and uninstall the app
  5. Run the project on a device

Right?

Another thing, what happens if you make a fresh pull, update the package to v3.17.0.2 and then run it for the first time on a device?

SotoiGhost commented 6 years ago

Hmm… I cannot reproduce the bug… this is weird.

kspearrin commented 6 years ago

I just updated the GitHub repo to v3.17.0.2.

  1. Pull refresh copy of repo.
  2. Uninstall any previous version of the app from device.
  3. Set breakpoint in LoadingViewController
  4. Deploy iOS.Extension -> Debug - iPhone -> My iPhone 6S
  5. Launch extension from a Safari website share menu.
  6. Observe nulls at breakpoint.
kspearrin commented 6 years ago

I'm just guessing here, but maybe it has something to do with this app id being previously installed on my device (the real app)?

SotoiGhost commented 6 years ago

Mmm… I cannot install the test case on a device, keeps saying that something is not well configured.

image

Even disabling all of the Entitlements, keeps throwing me that I cannot install the app, am I missing something?

kspearrin commented 6 years ago

Welcome to provisioning hell 😭 . I think iCloud and Push Notifications should be enabled.

Here is main app:

image

Extension:

image

SotoiGhost commented 6 years ago

Ohh… Push Notifications, I think that's the problem, let me check

SotoiGhost commented 6 years ago

Yep, that was the problem, needed to remove a key on Info.plist about the remote notifications in the background. Also, I can see the null values. Let me deep in into this.

kspearrin commented 6 years ago

Hooray, I'm not crazy!

SotoiGhost commented 6 years ago

@kspearrin Please, try changing the linker behavior of you iOS extension app. Open your extension project settings, go to iOS Build, and change Link behavior from Don't Link to Link Framework SDKs Only and let me know your results. Thanks in advance :)

kspearrin commented 6 years ago

@SotoiGhost Yes, that seems to fix it.

screen shot 2017-12-19 at 8 40 35 am

Seems pretty odd that linking would fix the issue. Usually it's the other way around.

SotoiGhost commented 6 years ago

Yes, I know… I had the same thought. Glad to read that this worked for you.

After playing with some iOS configuration and different kind of projects, I have come to the conclusion that this is an odd scenario caused by Xamarin.Forms, NetStandard, and the linker that affects only G.Analytics, I tried using Firebase.Analytics and everything worked as expected. Please, if you can, file an issue in Xamarin.Forms GitHub repo, explaining what's happening.

I'm closing this issue now. If something else happens related with this, feel free to re-open this issue.

Best!