Cannot get Firebase working for Xamarin Forms iOS - xamarin.forms

I am using Visual Studio 2019 on Windows, developing an App using Xamarin Forms, for Android and iOS. Everything is the latest version.
I am trying to use Firebase to add Push Notification functionality. I have been able to get this functioning for the Android App, but whatever I do seems to fail / not work for iOS.
I have tried using both Xamarin.Firebase.iOS.CloudMessaging and Plugin.FirebasePushNotification with the same result. Starting from a basic app created in Visual Studio, as soon as I add the basic code for the iOS project, the app stops working and just times out after 17 seconds with running any of the project code (no breakpoints are hit).
I also tried downloading this demo app https://github.com/jfversluis/XFFCMPushNotificationsSample. I created my versions of google-services.json (Android) and GoogleService-Info.plist (iOS). The Android app runs but the iOS app does not (times out after 17 seconds).
Having tried so many different samples, examples, options, etc - I am at a complete loss as to what the issue might be. The situation is not helped by me being new to App development & Xamarin Forms!
I appreciate that I haven't added any "I tried this" code, but I'm hoping someone can help me with debugging this. Visual Studio doesn't appear to show anything, can I get more helpful info from the iPhone?
Edit:
For iOS,
I have created a Key and enabled Apple Push Notifications.
I have uploaded the key to the iOS project in Firebase (Cloud Messaging).
I have downloaded the GoogleService-Info.plist file and added it to the iOS project in Visual Studio, and set it to BundleResource
I have enabled Push Notifications in Entitlements.plist
I have enabled Background Modes & Remote Notifications in Info.plist
I am using Automatic Provisioning
I have checked that Bundle Identifier is correct
I have added FirebaseAppDelegateProxyEnabled to info.plist
EDIT 2:
I have manged to get an error message, which happens during the call to
FirebasePushNotificationManager.Initialize(options, true);
{System.NullReferenceException: Object reference not set to an instance of an object.
at Plugin.FirebasePushNotification.FirebasePushNotificationManager.Initialize (Foundation.NSDictionary options, System.Boolean autoRegistration) [0x00029] in /Users/runner/runners/2.169.1/work/1/s/Plugin.FirebasePushNotification/FirebasePushNotificationManager.ios.cs:141
at MyApp.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00014] in \MyKRing.iOS\AppDelegate.cs:34 }

Related

Xamarin App crashes after testFlight release before my code runs

Hello and thank you for reading.
This is my first time publishing an ios application and I am using Xamarin to publish my app to both Android and iOS (as requested by the client ).
Now the application deploys and works correctly when I run it via visual studio/Rider but when I push it to testflight (via azure pipeline and microsoft App Center) I get the following Crash report:
link to crashreport
oke so after some triel and error I have found the problem:
Apparently in Xamarin if you use EFCore then there is the possibility of mTouch to skip the reflections used by it
more info (and my saving grace) was found here:
https://learn.microsoft.com/en-us/ef/core/get-started/xamarin#explore-the-code

Xamarin Android app out of the box shows undefined Android.Support, Android.Views, Android.Content in MainActivity

I needed to rebuild my fairly ancient Xamarin Forms app from scratch and in the process arrived at a situation where I had a new working iOS app but had needed to delete the draft Android app and start it again. So as a next step I added a vanilla Android app project out of the box and immediately what I saw was that (in MainActivity) Android.Support, Android.Views and Android.Content were undefined with wiggy red lines beneath -- for example in a reference to Android.Support.V7.Widget.Toolbar.
Trying to solve the problem, I set each of Target Framework, Minimum Android Version and Target Android Version to Android 9.0 Pie (API Level 28). In SDK Manager I checked that Android SDK Location and Java SDK Location were 'Found' and that Android SDK Platform 28 was installed.
The following NuGets came installed along with the project, I deleted them and reinstalled them (removing bin/obj folders in between): Xamarin.Android.Support.Core.Utils, Xamarin.Android.Support.CustomTabs and Xamarin.Android.Support.Design.
I tried installing NuGets Xamarin.Android.Support.v7.*. And I added the Xamarin.Forms NuGet. I tried adding 'use' declarations.
None of this helped.
For comparison I separately installed a blank Android app solution-- it worked perfectly out of the box.
Android is pretty new to me - would be grateful for suggestions on fixing this.
The app has a .NET Standard 2.0 project, an iOS project, the (vanilla) Android project (all three with Xamarin Forms), and a .NET Standard 2.0 library project.
I'm using Visual Studio for Mac V8.5.4 (stable) on MacOS 10.15.3.
I noticed that the content of MainActivity.cs is quite different, depending whether the Android project is created separately or as part of a Xamarin Forms solution. Also the provided NuGets are different. So perhaps what I was trying to do, adding an Android app to an existing XF solution, is simply not allowed.
To fix the problem, I created an empty Xamarin Forms solution with Android and iOS projects, added a further empty library project, then in Finder replaced the content of all the project folders, except the Android one, with the content of the corresponding folders in my working solution (the one with a working iOS app).
Migrating to AndroidX is a good idea though.
I don't know if this will help, but you should migrate to AndroidX as soon as possible, nevertheless. Xamarin has migrated to them, starting from Forms 4.5
Here is some more information about the libraries - Introducing AndroidX for Xamarin
There is a special NuGet package for the migration - Xamarin.AndroidX.Migration. Also available is a built-in functionality in Visual Studio - here
What I can suggest is you try to migrate to AndroidX libraries, since the old support libraries won't be supported from now on, and you will surely encounter some issues if not like this one, then something else will pop-up in the future.

How to Sync Project with Gradle Files when Adding Firebase to Flutter Android App in Android Studio (April 2020)

Edit: This question refers to Flutter apps.
When adding Firebase to my Android app, the instructions say: "Finally, press "Sync now" in the bar that appears in the IDE"
However, no bar appears in Android Studio.
It seems that there used to be a button in the tool bar: Where is a "Sync project with gradle files" button in Android Studio 3?
And that more recently it could be found at "File > Sync Project with Gradle Files": Syncing Android Studio project with Gradle files
But neither of those options exist in Android Studio as of April 4, 2020. The closest thing I can find is an item in the dropdown menu that says "Sync with File System."
I thought maybe it was the same thing, but they are not:
What is the difference between Sync project with gradle files and Sync with File System?
Any ideas how I can sync project with gradle files in Android Studio in April 2020?
Thank you!
According to your picture, it looks like you are using flutter and not native android development. If you want to add firebase analytics to your flutter app then you need to go to the pubspec.yaml file, and you can add the dependency:
dependencies:
firebase_analytics: ^5.0.11
After adding it a top bar will appear to that will automatically execute pub get
https://pub.dev/packages/firebase_analytics#-installing-tab-
what I do is open the android folder of our Flutter project as a new project,
** Archivo> Abrir> Proyect-android **
in this way the IDE recognizes it, and enables the Gradle synchronization button ( only enabled in native android projects)
Image Example
once synced, you can close the native Android project, and it would be synced to your Flutter project

Android Debugging Failing With "Couldn't connect to logcat, GetProcessId returned: 0" FFImageLoading.Platform.dll.so Not Found

I am having issue debugging Android project. I can deploy to device and run it, all works fine but if I try to debug, the app gets deployed to the device and very briefly opened, splash screen shows up but the app then closes.
I am using Xamarin Forms on Visual Studio 2015.
Device is running Android Oreo (8.0.0). Another device running Android 6.0.1 is debugging fine.
The output shows following:
InspectorDebugSession(11): StateChange: Start -> EntryPointBreakpointRegistered
InspectorDebugSession(11): Constructed
Android application is debugging.
InspectorDebugSession(11): HandleTargetEvent: TargetExited
InspectorDebugSession(11): Disposed
Couldn't connect to logcat, GetProcessId returned: 0
I checked Logcat and it seem to be having issues finding FFImageLoading library:
Time Device Name Type PID Tag Message
09-18 14:35:52.361 Huawei Nexus 6P Debug 1560 Mono AOT:
image '/usr/local/lib/mono/aot-cache/arm/FFImageLoading.Platform.dll.so'
not found: dlopen failed: library "/data/app/myapp.android.dev-
WEb1bz8edgF7vwx6uCoZ-A==/lib/arm/libaot-FFImageLoading.Platform.dll.so" not found
I have added Nuget package for FFImageLoading to my projects and Droid project references show it as in image below:
This worked for me :-
Deselecting the 'Use Shared Runtime' in Project Properties > Android
Options > Packaging properties
I also had this issue with Android 8.1 and Visual Studio 2017 15.7.4.
There are three steps to got it working again.
Under Android Options, go to Advanced and add your device architecture, in my case it was x86_64.
Go to Tools -> Options -> Xamarin > Android Settings and enable: Provide debug symbols for shared runtime and base class libraries.
And the final step is to delete following Apps from your device:
All Xamarin.Android API Support libraries
Mono Shared Runtime
Your App
After these steps you don't need to disable "Use Shared Runtime" and can Deploy and Debug much faster.
This is a known issue with Oreo and Xamarin Android on Visual Studio for Windows. It works on Visual Studio for Mac apparently. It will be fixed in an upcoming release. In the mean time there is a work around down near the bottom of the bug link above (comment 20).
deselecting 'Use Shared Runtime' in Project Properties > Android Options
delete bin & obj files from solution
clean solution
rebuild the solution it works
One another reason for that is if you dont enable usb debugging on your device, VS 2017 still recognizes your phone and installs the app on your phone. Just after debugging starts, it will throw this error and not continue debugging. Make sure to enable Developer Mode -> Usb debugging like described here
https://learn.microsoft.com/en-us/xamarin/android/get-started/installation/set-up-device-for-development

ERROR ITMS-90161 when trying to upload an app built with Visual Studio for Apache Cordova

We just started creating cross platform mobile apps using "Visual Studio Tools for Apache Cordova".
I followed the procedures described in Install Tools to Build for iOS and To run your app on an iOS device. Everything works nicely, the app gets deployed on my USB attached iPhone and runs as expected.
I then tried to upload the app to iTunes, to provide the app via TestFlight to testers and to generally see how app-submitting works:
Build the iOS app as "Release" in VS: it builds and deploys to the iPhone nicely
On the Mac: Start Application Loader, click on "Deliver your App" and navigate to "...remote-builds/builds/"xxx-buildnmb"/cordovaApp/plattforms/iOS/build/device/APPNAME.ipa"
Several checks run OK ("verifying assets, etc.), but it then stops with the error
ERROR ITMS-90161: "Invalid Provisioning Profile. The provisioning profile included in the bundle xxx.yyyyyy.zzzz [Payload/xxx.yyyyyy.zzzz.app] is invalid. [Missing code-signing certificate.] For more information, visit the iOS Developer Portal."
I then discovered the Xcode Project in ".taco_home/remote-builds/taco-remote/builds/<build-number>​/cordovaApp/platform‌​s/ios/" and used Xcode to define the code signing identities in "Build Settings" and the Team information in "General", created the archive via Product-->Archive and submitted it in the Organizer - Archives. And voila it worked!
My questions:
Do I have to use Xcode to submit?
If not, what might I be missing in a) regard to building and signing apps with vs-mda-remote, and b) submitting it with Application Loader?
What are Microsoft's plans in regard to providing access the build settings from within Visual Studio (similar to the ones in Xcode)?
Thanks a lot for any pointers in the right direction.
Thomas
You need to use distribution provisioning profile to sign the package and apps are published to the App Store by using the iTunes Connect website along with the Xcode Archive Tool, which is included with the iOS SDK.

Resources