java.exe" exited with code 1

AS_H 41 Reputation points
2022-11-05T17:54:49.953+00:00

Hi,

I'm trying to use notifications through Firebase, but an error appeared when I created the myfirebaseiidservice class
(java.exe" exited with code 1)

This code and the packages I use

using Android.App;  
using Android.Content;  
using Android.OS;  
using Android.Runtime;  
using Android.Views;  
using Android.Widget;  
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
  
using System;  
using Android.App;  
using Firebase.Iid;  
using Android.Util;  
  
namespace notifi.Droid.Model  
{  
   
    [Service]  
    [IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]  
    public class MyFirebaseIIDService : FirebaseInstanceIdService  
    {  
        const string TAG = "MyFirebaseIIDService";  
        public override void OnTokenRefresh()  
        {  
            var refreshedToken = FirebaseInstanceId.Instance.Token;  
            Log.Debug(TAG, "Refreshed token: " + refreshedToken);  
            SendRegistrationToServer(refreshedToken);  
        }  
        void SendRegistrationToServer(string token)  
        {  
            // Add custom implementation, as needed.  
        }  
    }  
}  
  

257477-image.png

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,491 Reputation points Microsoft Vendor
    2022-11-07T08:37:52.08+00:00

    Hello,

    You used Xamarin.Firsbase.lid 121.1.0.7, it depends on the android version is 12.
    You need to edit [Services] to [Services(Exported = true)] for android 12 or later,

    Please notice: firebaseinstanceidservice is deprecated

    You could use FirebaseMessagingService.

       public class MyFirebaseIIDService : FirebaseMessagingService  
           {  
         
              public override void OnNewToken(string token)  
               {  
                   base.OnNewToken(token);  
               }  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.