Firebase configuration

Hi everyone,

I'm trying to use Firebase with Xamarin.Android at the moment. I read the documentation on the website (https://firebase.google.com/docs/android/setup#add_firebase_to_your_app) and i think i've done everything good but 2 points:

  • Xamarin doesn't use gradle/maven so what am i supposed to do with : "apply plugin: 'com.google.gms.google-services'" in the gradle configuration file.
  • Where should i put the file "google-services.json" downloaded from the Firebase website ? It seems like in Android Studio i put it in the app folder and the app read it automatically, but not in Xamarin Studio.

At the moment i've included the Xamarin Firebase library from alpha channel and i've implemented the two required service. When i try to get the Token from firebase i get the error : FirebaseApp with name [DEFAULT] doesn't exist

I think it's because my app isn't reading the "google-services.json" configuration file so i dont have any connection with my firebase app or maybe something is missing in the manifest ?

Any help ?

Thanks,

Best regards,

Armand

PS: I've done the same thing in the documentation in an Android Project with Android Studio and it's working fine.

«13

Posts

  • DylanSchoenmakersDylanSchoenmakers NLMember ✭✭

    First off, the Xamarin Firebase bindings are in alpha development and therefor as far as I know not production ready. However I've been busy implementing Firebase myself and can give you some tips to get you started.

    Forget about adding "apply plugin: 'com.google.gms.google-services'" line or the "google-services.json" file anywhere. It's not necessary. Just add the NuGet packages and you're set. You will need to initialise the app and I've had some luck with this:

    var options = new FirebaseOptions.Builder()
    .SetApplicationId("Firebase-App-Id")
    .SetApiKey("Firebase-Api-Key")
    .SetDatabaseUrl("Firebase-Database-Url")
    .SetGcmSenderId("Firebase-Sender-Id")
    .Build();

    var firebaseApp = FirebaseApp.InitializeApp(this, options);

    var database = FirebaseDatabase.GetInstance(firebaseApp);

    database.GetReference("test").SetValue("Hello world!");

    I could not get Auth (I'm using signInWithCustomToken which gives me Bad Request) or Messaging to work. If you have some luck with that let me you as Gcm is replaced by Fcm.

  • ArmandCharbonnierArmandCharbonnier FRMember ✭✭
    edited June 2016

    @DylanSchoenmakers thanks for your feedback !

    As i'm reading this i just found out about the FirebaseApp.InitializeApp(this, options). I've set every options rights and i get no error. Now i'm also trying to get the Firebase Messaging to work.

    I've implemented the 2 required service :

    public class MyFirebaseMessagingService : FirebaseMessagingService
        {
            public override void OnMessageReceived (RemoteMessage message)
            {
                string title = message.GetNotification ().Title;
                string text = message.GetNotification ().Body;
                string image = message.GetNotification ().Icon;
                string sound = message.GetNotification ().Sound;
    
                // TODO: Upgrade Notifier to include sound if needed
                DependencyService.Get<INotifier> ().Notify (title, text, image);
    
                base.OnMessageReceived (message);
            }
    
            public override void OnMessageSent (string msgId)
            {
                base.OnMessageSent (msgId);
            }
        }
    
    public class MyFirebaseInstanceIDService : FirebaseInstanceIdService
        {
            public override void OnTokenRefresh ()
            {
                string refreshedToken = FirebaseInstanceId.Instance.Token;
                if (!string.IsNullOrEmpty (refreshedToken)) {
                    System.Console.WriteLine ("Refreshed Firebase Token : " + refreshedToken);
                    SendRegistrationToken (refreshedToken);
                }
    
                base.OnTokenRefresh ();
            }
    
            private void SendRegistrationToken (string token)
            {
                // TODO: Function to store token / send to server
            }
        }
    
    

    But when i'm doing FirebaseInstanceId.Instance.Token it's always null. I've tried with FirebaseInstanceId.GetInstance(app).Token;

    Do you have the same issue and is there anything else to do ?

    Thanks,

    Armand

  • DylanSchoenmakersDylanSchoenmakers NLMember ✭✭

    @ArmandCharbonnier I have the same problem unfortunately!

    The method OnTokenRefresh never gets called in my code. Does yours?

    Btw, I have annotated the services like this:
    `
    [Service(Exported = true), IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
    public class MyFirebaseInstanceIDService : FirebaseInstanceIdService
    {

    }`

  • ArmandCharbonnierArmandCharbonnier FRMember ✭✭

    Well in the Android Project in Android Studio, this method never gets called either so i think it's ok. But I do get the Token in the service instance. Maybe there's something wrong in the library. I can't see what is missing here.

    Thanks for the annotation, i'll try with that too.

    Best regards,

    Armand

  • DylanSchoenmakersDylanSchoenmakers NLMember ✭✭

    Maybe @JamesMontemagno can help us solve this problem or relay it to the dev team. I know they're actively working on the bindings as the latest published version is from last week.

    In any case, can you @ArmandCharbonnier post back here if and when you get this working?

  • ArmandCharbonnierArmandCharbonnier FRMember ✭✭

    @DylanSchoenmakers sure i will post back here. I'm working on something at the moment with my team so we are looking for solutions.

    It would indeed be nice if @JamesMontemagno or the DevTeam could help us. I'm really eager to try the new FCM :)

    Best regards,

    Armand

  • ArmandCharbonnierArmandCharbonnier FRMember ✭✭
    edited March 2018

    Hi everyone,

    I've got news, now i found out how to generate a token, here is the code in my MainActivity:

    // Firebase initialization
    var options = new FirebaseOptions.Builder ()
                     .SetApplicationId(Keys.Firebase.Application_ID)
                     .SetApiKey(Keys.Firebase.Api_Key)
                     .SetDatabaseUrl(Keys.Firebase.Database_Url)
                     .SetGcmSenderId(Keys.Firebase.GcmSender_ID)
                     .SetStorageBucket(Keys.Firebase.StorageBucket)
            .Build();
    FirebaseApp app = FirebaseApp.InitializeApp(this, options);
    
    // Generate token in background thread
    Task.Factory.StartNew (() => {
        var token = FirebaseInstanceId.Instance.GetToken (Keys.Firebase.GcmSender_ID, "FCM");
        System.Console.WriteLine ("Firebase Token : " + token);
    });
    

    You have to call the GetToken method instead of Token Properties. This is a blocking methid so if you call it on the main thread you get an exception "MAIN THREAD". Here's the documentation : https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId#public-methods

    Still, after getting the token, i dont receive any notification and my both Firebase services methods are never called (break points not hitting at all in the OnMessageReceived(RemoteMessage message) method.

    Best regards,

    Armand

  • DylanSchoenmakersDylanSchoenmakers NLMember ✭✭

    @ArmandCharbonnier That is great news! I will try this myself and will let you know if I have any success with receiving notifications.

    Did you try to subscribe to a topic?

  • ArmandCharbonnierArmandCharbonnier FRMember ✭✭

    @DylanSchoenmakers yes i tried to subscribe to a topic but i have the same result. (Tried the 3 ways of sending a test push message from the Firebase console).

    Let me know if you have more clue :)

    Best regards,

    Armand

  • AnthonyClarkAnthonyClark USMember

    @DylanSchoenmakers I was able to get FirebaseAuth working for account creation and sign in using the example google has here:

    https://github.com/firebase/quickstart-android/blob/master/auth/app/src/main/java/com/google/firebase/quickstart/auth/GoogleSignInActivity.java

    Since I didn't try and copy the whole example I mostly just made a single activity based on that example and ended up using FirebaseApp.InitializeApp.

  • User.0440User.0440 DEMember

    @AnthonyClark great to hear. Could you please post the C# code used for FirebaseAuth?

  • uNiverseuNiverse USMember ✭✭
    edited July 2016

    @AnthonyClark thanks for the feedback, it would be great if you share the code of your activity.

    Just one question, GoogleSignIn and Auth aren't required to your messaging ? Because i didnt include any of this.

    Thanks,

    Best regards,

    Armand

    [Wrong account, please delete this post :)]

  • ArmandCharbonnierArmandCharbonnier FRMember ✭✭
    edited July 2016

    @AnthonyClark thanks for the feedback, it would be great if you share the code of your activity.

    Just one question, GoogleSignIn and Auth aren't required to your messaging ? Because i didnt include any of this.

    Thanks,

    Best regards,

    Armand

    PS: Sorry for the previous post from @ArmandCharbonnier.4570, i don't know where it comes from. I was logged with this user and not my real account. If someone can delete it :)

  • AnthonyClarkAnthonyClark USMember

    @ArmandCharbonnier Of course, I tired to clean it up a bit but it's mostly just a test to make sure I can at least use firebase before I start trying to actually use it in a real project.

    https://github.com/Anth0ny229/FirebaseTest

    You will have to change MainLauncher in each activity since I reused the UI and mostly just tested one at a time.
    The database writing works as well but I have my database setup as default where the user must be authenticated.

    I too am having issues with FCM. :neutral: I don't think you need to be authenticated via normal user. From what I've read you just need the token but that doesn't seem to work. It does not call my service when I update the token. Hopefully one of us has luck because it feels like that's the only thing I haven't been able to do yet.

    If you have any questions from the project I posted just let me know :smiley:

  • AnthonyClarkAnthonyClark USMember

    Also, forgot to mention for auth I had to add my Certificate Fingerprints (SHA-1) for my app.

  • uNiverseuNiverse USMember ✭✭

    @AnthonyClark thanks for the sharing.

    Well i just want to use the messaging from FCM but i still can't get it to work. I tried with Azure Notification Hub and the tutorial for Xamarin.Android. They says FCM works same way as GCM and is compatible but it's not really working.

    I made a broadcast receiver with GCM, and when i send a notification from Azure Notification Hub Portal, i get the notification. The funny thing is, when i send a notification from Firebase Console, i received it also in the GCM Broadcast Receiver.

    When i don't use the GCM stuff and use the FirebaseMessagingService, i don't receive any notification from both platforms (Azure / Firebase).

    I'm a bit lost now. I don't know if i'm missing something, or if it's just the Xamarin Firebase alpha package that's not working properly for the moment.

    @JamesMontemagno can you help us please ? :)

    Thanks,

    Best regards,

  • AnthonyClarkAnthonyClark USMember

    @ArmandCharbonnier Yeah I'm wondering that too now. https://github.com/xamarin/GooglePlayServicesComponents/tree/v9.0.1/firebase-messaging/samples

    That is a sample I tried using as well and didn't have much luck. I spent most of the day trying to work out why it's not getting called.

  • AnthonyClarkAnthonyClark USMember
    edited July 2016

    Today I spent some time trying to get the GoogleServicesJson Build Action working so that it would consume the google-services.json. Using the current GooglePlayServices.Basement it has a build task that calls GooglePlayServices.Tasks.dll but it seems like that assembly doesn't have the ProcessGoogleServicesJson class. Anyways, I ended up building from the repo just the buildtask project found here:
    https://github.com/xamarin/GooglePlayServicesComponents/tree/v9.0.1/basement/buildtasks
    Now I no longer need to call FirebaseApp.InitializeApp. My hopes were that maybe one of the internal classes expected the resource created by the build task. I haven't had any luck so far besides that now I no longer need to initialize. I feel like I've tried everything possible but maybe @OldRedth or @JamesMontemagno can shed some light?

  • ArmandCharbonnierArmandCharbonnier FRMember ✭✭
    edited July 2016

    @AnthonyClark,

    Nice work here, it's cool to get closer to the original android build without any Initialize. I was hoping it would solve our problem but it seems not. It would be great to have some help from the Xamarin Team here because we have tried everything so far and we have no clues left !

    Thanks,

    Armand

  • AnthonyClarkAnthonyClark USMember

    I can't believe it took me so long to run across this but if we fill the xml string values there's no need to process the google-service.json.

    https://developers.google.com/android/guides/google-services-plugin

    That's pretty much what the task handles and does for us. But we can do it manually and not have to worry about having the build task references. I still can't seem to get the messaging class to work no matter what I try. I've ever tired running the sample and copying all the debug output and all I've seen is that the native java gets called and in C# it does not.. I wish I could get more info but I even tried using compile 'com.google.firebase:firebase-messaging:9.0.2' which is the Xamarin library uses. The current version is 9.0.2 which doesn't seem to make a difference. The service's doesn't even seem to run which is an issue.. They have no problem in the java version.

  • JigneshKJigneshK INMember

    Hi,

    @ArmandCharbonnier is your dashboard working with FirebaseApp initialization. I am getting error in application output : "[FirebaseInitProvider] FirebaseApp initialization unsuccessful".
    I am trying this code for Firebase initialization. FYI:

    var opt = new FirebaseOptions.Builder()
    .SetApplicationId("Firebase-App-Id")
    .SetApiKey("Firebase-Api-Key")
    .SetDatabaseUrl("Firebase-Database-Url")
    .SetGcmSenderId("Firebase-Sender-Id")
    .Build();
    FirebaseApp app = FirebaseApp.InitializeApp(this, opt,Application.PackageName);

    Please guide me if i am doing anything wrong here.

    Thanks

  • ArmandCharbonnierArmandCharbonnier FRMember ✭✭

    Hi @JigneshK,

    Well in my Code the Firebase initialization is working. I'm not using packagename in the InitializeApp method. It's the only difference i have with your code.

    (I guess you replaced the string values by the right values from your google-services.json in each Set method).

    Did you create the firebase application on your Firebase Dashboard ? Did you write the required line from the documentation in the manifest ?

    I think it's a configuration issue because i don't have much more code than yours.

    Best regards,

    Armand

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    I haven't tested out any of the Firebase things yet. Sorry.

  • ArmandCharbonnierArmandCharbonnier FRMember ✭✭

    @JamesMontemagno,

    No problem, just tell us if you try it. And can you relay this issue/problem to the dev team please ? I think there's multiple developer who wants to try out the new Firebase with Xamarin and can't get it to work properly.

    Thanks,

    Best regards,

    Armand,

  • JigneshKJigneshK INMember

    Hi,

    @ArmandCharbonnier , Thanks for your answer.

    I have tried both method(with/without application name) but getting same output.

    Yes, I have created firebase application in my dashboard, also i have replaced string values from google-services.json file. Which line i have to write in manifest?

    i wrote
    "<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />" this in manifest.

    Thanks,
    Jignesh

  • JigneshKJigneshK INMember

    Also given user-permission mentioned in documentation.

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    

    Thanks & Regards,
    Jignesh

  • JigneshKJigneshK INMember

    Hi @ArmandCharbonnier ,

    I have added packages listed below,

      <package id="Xamarin.Firebase.Analytics" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Analytics.Impl" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Auth" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Auth.Common" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Auth.Module" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Common" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Core" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Iid" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Messaging" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Auth" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Auth.Base" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Base" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Basement" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Gcm" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Iid" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Tasks" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
    

    and what you did for step 1? : Add rule to root level build.gradle

    buildscript {
        // ...
        dependencies {
            // ...
            classpath 'com.google.gms:google-services:3.0.0'
        }
    }
    

    for this i have created binding for "com.google.gms:google-services:3.0.0" and added reference to my project.

    Thanks,
    Jignesh

  • JigneshKJigneshK INMember

    Hi,

    @ArmandCharbonnier , Thanks for your answer.

    I have tried both method(with/without application name) but getting same output.

    Yes, I have created firebase application in my dashboard, also i have replaced string values from google-services.json file. Which line i have to write in manifest?

    i wrote
    "<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />" this in manifest.

    Thanks,
    Jignesh

  • JigneshKJigneshK INMember

    Also given user-permission mentioned in documentation.

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    

    Thanks & Regards,
    Jignesh

  • JigneshKJigneshK INMember

    Hi @ArmandCharbonnier ,

    I have added packages listed below,

      <package id="Xamarin.Firebase.Analytics" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Analytics.Impl" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Auth" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Auth.Common" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Auth.Module" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Common" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Core" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Iid" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.Firebase.Messaging" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Auth" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Auth.Base" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Base" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Basement" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Gcm" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Iid" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
      <package id="Xamarin.GooglePlayServices.Tasks" version="30.0.2-alpha1" targetFramework="MonoAndroid60" />
    

    and what you did for step 1? : Add rule to root level build.gradle

    buildscript {
        // ...
        dependencies {
            // ...
            classpath 'com.google.gms:google-services:3.0.0'
        }
    }
    

    for this i have created binding for "com.google.gms:google-services:3.0.0" and added reference to my project.

    Thanks,
    Jignesh

  • DylanSchoenmakersDylanSchoenmakers NLMember ✭✭

    @AnthonyClark I'm using custom auth provider like auth.SignInWithCustomToken() which does not work in my case, but good to know that the Google signin method works!

  • ArmandCharbonnierArmandCharbonnier FRMember ✭✭

    Still no feedback from the Xamarin Dev Team ?

  • AnthonyClarkAnthonyClark USMember
    edited July 2016

    @ArmandCharbonnier I finally got it working!!!

    Using the latest Github branch and following the build instructions.
    After building, I opened up the solution and updated the reference for the Nuget Package Xamarin.Android.Support.v4 in the Firebase-Iid Project.
    Once done I rebuilt
    And then I used the FirebaseMessagingQuickstart sample and modified the google-services.json file and changed the package name in the properties to match mine in the Firebase console test project.
    After that I uncommented the Task.Run region in the MainActivity.cs

            Task.Run (() => {
                var instanceID = FirebaseInstanceId.Instance;
                instanceID.DeleteInstanceId ();
                var iid1 = instanceID.Token;
                var iid2 = instanceID.GetToken (GetString (Resource.String.gcm_defaultSenderId), Firebase.Messaging.FirebaseMessaging.InstanceIdScope);
                Android.Util.Log.Debug (TAG, "Iid1: {0}, iid2: {1}", iid1, iid2);
            });
    

    After building and running it, it finally hit my breakpoints for both Instance ID OnTokenRefresh and the OnMessageReceived.
    Make sure to set the Certificate Fingerprints (SHA-1) in the Firebase Console for your project, and that the Package name field match yours in the project properties\android manifest.

    Here is a link to the Github branch that worked for me:
    https://github.com/xamarin/GooglePlayServicesComponents/tree/v9.2.0

    It's only a few days old, and it has been updated to use the 9.2.0 libraries instead of the older ones.
    Just follow the instructions on the readme to do the initial build.
    Let me know if you have any questions and I will try and help, Good luck! :smiley:

  • ArmandCharbonnierArmandCharbonnier FRMember ✭✭

    @AnthonyClark,

    Wow i'm glad to hear that, thanks for the feedback i'll try it out as soon as i can and tell you if i get it to work too :)

    Best regards,

    Armand

  • PaulyPauly USMember ✭✭
    edited July 2016

    @AnthonyClark

    I am also trying the GitHub branch to work. Building the externals works, but libs throws an error.

    powershell .\build.ps1 -Target libs

    "C:\GooglePlayServicesComponents-9.2.0\GooglePlayServices.sln" (Build target) (1) ->
    "C:\GooglePlayServicesComponents-9.2.0\base\source\Base.csproj" (default target) (4) ->
    (CoreCompile target) ->
    Additions\GoogleApiAvailability.cs(7,29): error CS0115: 'GoogleApiAvailability.IsGooglePlayServicesAvailable(Context)': no suitable method found to override [C:\GooglePlayServicesComponents-9.2.0\base\source\Base.csproj]
    Additions\GoogleApiAvailability.cs(12,32): error CS0115: 'GoogleApiAvailability.GetOpenSourceSoftwareLicenseInfo(Context)': no suitable method found to override [C:\GooglePlayServicesComponents-9.2.0\base\source\Base.csproj]
    Additions\GoogleApiAvailability.cs(17,51): error CS0115: 'GoogleApiAvailability.GetErrorResolutionPendingIntent(Context, int, int)': no suitable method found to override [C:\GooglePlayServicesComponents-9.2.0\base\source\Base.c
    sproj]

    Any ideas?

    Thanks,
    Pauly

  • AnthonyClarkAnthonyClark USMember

    @Pauly Can you share some of your build tools info? For example VS Version, Win Version and also Xamarin.Android version?

    Here is what I have
    Xamarin.Android 6.1 Compiling using Android 6.0 with Target Android version as 6.0 also Windows 10, Visual Studio Community Edition 2015

    When I had issues I did a git cleanup and removed all untracked files and directories. After that I made sure to pull the latest version and that I had the latest clean branch. Then instead of building externals. I went straight to building the libs. It will download the externals for you automatically.

    .\build.ps1 -Target libs -Verbosity diagnostic

    Also, not sure if it makes a difference but I ran powershell as admin because of the location of my local repo. I hope one of those things helps.

  • PaulyPauly USMember ✭✭
    edited July 2016

    @AnthonyClark

    Thanks for the reply. I pretty much have everything you do.

    Windows 10
    Microsoft Visual Studio Enterprise 2015
    Version 14.0.25421.03 Update 3
    Microsoft .NET Framework
    Version 4.6.01038
    Xamarin 4.1.1.3 (34a92cd)
    Xamarin.Android 6.1.1.1 (7db2aac)
    Xamarin.iOS 9.8.1.4 (3cf8aae)

    I deleted everything and started fresh a couple of different times and received a different about Resource not existing. Tried updating Xamarin nuget packages too. I probably should just wait for the official release.

    36>MainActivity.cs(17,29): error CS0103: The name 'Resource' does not exist in the current context [C:\GooglePlayServicesComponents-9.2.0\all\samples\GpsBuildAll\GpsBuildAll.csproj]
    36>MainActivity.cs(21,51): error CS0103: The name 'Resource' does not exist in the current context [C:\GooglePlayServicesComponents-9.2.0\all\samples\GpsBuildAll\GpsBuildAll.csproj]
    36>Done Building Project "C:\GooglePlayServicesComponents-9.2.0\all\samples\GpsBuildAll\GpsBuildAll.csproj" (default targets) -- FAILED.
    1>Done Building Project "C:\GooglePlayServicesComponents-9.2.0\GooglePlayServices.sln" (Build target(s)) -- FAILED.

    ld FAILED.

    "C:\GooglePlayServicesComponents-9.2.0\GooglePlayServices.sln" (Build target) (1) ->
    "C:\GooglePlayServicesComponents-9.2.0\all\samples\GpsBuildAll\GpsBuildAll.csproj" (default target) (36) ->
    (CoreCompile target) ->
      MainActivity.cs(17,29): error CS0103: The name 'Resource' does not exist in the current context [C:\GooglePlayServicesComponents-9.2.0\all\samples\GpsBuildAll\GpsBuildAll.csproj]
      MainActivity.cs(21,51): error CS0103: The name 'Resource' does not exist in the current context [C:\GooglePlayServicesComponents-9.2.0\all\samples\GpsBuildAll\GpsBuildAll.csproj]
    

    Thanks,
    Pauly

  • AnthonyClarkAnthonyClark USMember
    edited July 2016

    @Pauly Now it seems like the resource designer isn't being built. I even tried to break my own compiling to try and reproduce the errors you had so I could try and fix them. I wish I had an answer at the moment. Until then, I uploaded the built dll's and nupkg files. I hope this helps for now.

    https://github.com/Anth0ny229/GooglePlayServicesComponentsOutput920

  • RainerMagerRainerMager JPMember ✭✭

    I'm only trying to use Firebase Analytics for the moment, but thanks to your help here I got it working. Here's what I did...

    First, as you hinted at, you don't need to try to build the google-services.json file, or more precisely, you can do it manually pretty easily. You need to create a XML file in your Android project's Resources/values folder called goog_svcs_json.xml. The format of this file is:

    <?xml version="1.0" encoding="utf-8"?> <resources> <string name="___key___" translatable="false">___value___</string> </resources>

    But, what keys do you need and what values? Well, fortunately you pointed me to that in https://developers.google.com/android/guides/google-services-plugin. Specifically in ProcessGoogleServicesJson.cs in the Execute method it has:

    var valuesItems = new Dictionary <string, string> { { "ga_trackingId", googleServices.GetGATrackingId (AndroidPackageName) }, { "gcm_defaultSenderId", googleServices.GetDefaultGcmSenderId () }, { "google_app_id", googleServices.GetGoogleAppId (AndroidPackageName) }, { "test_banner_ad_unit_id", googleServices.GetTestBannerAdUnitId (AndroidPackageName) }, { "test_interstitial_ad_unit_id", googleServices.GetTestInterstitialAdUnitId (AndroidPackageName) }, { "default_web_client_id", googleServices.GetDefaultWebClientId (AndroidPackageName) }, { "firebase_database_url", googleServices.GetFirebaseDatabaseUrl () }, { "google_api_key", googleServices.GetGoogleApiKey (AndroidPackageName) }, { "google_crash_reporting_api_key", googleServices.GetCrashReportingApiKey (AndroidPackageName) }, };

    Unfortunately you then need to cross reference each of those GetXXX methods to figure out what values to take from your JSON file. That's a bit of a pain, put it's well documented, so not too bad. Also not that these are optional. For example I only used 6: gcm_defaultSenderId, google_app_id, default_web_client_id, firebase_database_url, google_api_key, and google_crash_reporting_api_key.

    Anyway, after creating the XML file as described above with the keys and values mentioned then Firebase automatically initialized automatically. I did not need to call FirebaseApp.InitializeApp.

    I also found guidance from Google about how to put Firebase into debug mode to see that it is correctly logging in the console. To do that use the Tools -> Open Android SDK Command Prompt from Xamarin Studio menu and in that shell run: adb shell setprop log.tag.FA VERBOSE and then adb logcat -v time -s FA FA-SVC.

    I only just got this running so I haven't confirmed that the events I'm logging are showing my in my Firebase console yet, since that takes a few hours. I'll report back when I know more.

  • RainerMagerRainerMager JPMember ✭✭

    Good news, the analytics metrics did go through and are visible in the Firebase console.

Sign In or Register to comment.