appsup-dart / firebase_admin

A pure Dart implementation of the Firebase admin sdk
Other
44 stars 51 forks source link

Unsupported operation: Unsupported platform: android #6

Closed akfaisel closed 4 years ago

akfaisel commented 4 years ago

I'm using the following dependencies in pubspec.yamp firebase_admin: ^0.1.2

I have also created the environment variable in Win10 GOOGLE_APPLICATION_CREDENTIALS=C:\Users\Faisel\Downloads\service-account.json

Added the following in build.gradle classpath 'com.google.firebase:firebase-admin:5.3.1'

I'm using the following code and I'm getting Unsupported operation: Unsupported platform: android

      var credential = Credentials.applicationDefault();
      credential ??= await Credentials.login();

      var projectId = 'mtm-res-123456';
      // create an app
      var app = FirebaseAdmin.instance.initializeApp(AppOptions(
          credential: credential ?? Credentials.applicationDefault(),
          projectId: projectId,
          storageBucket: '$projectId.appspot.com'));

If I remove the line, credential ??= await Credentials.login(); I'm getting the following error message. I/flutter (14814): Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "NoSuchMethodError: The method 'getAccessToken' was called on null.

I have also tried this code,

      var app = FirebaseAdmin.instance.initializeApp(AppOptions(
        credential: FirebaseAdmin.instance.certFromPath('/project/app/service-account.json'),
      ));

In this case, I get the following error message I/flutter (14814): FirebaseAppError(app/invalid-credential): Failed to parse certificate key file: FileSystemException: Cannot open file, path = '/project/app/service-account.json' (OS Error: No such file or directory, errno = 2)

service-account.json is located in same folder as google-services.json.

I'm trying with my emulator.

Please help me. What am I doing wrong?

rbellens commented 4 years ago

Not sure where this error "Unsupported operation: Unsupported platform: android" is thrown from. Can you maybe post the stack trace.

Anyway, as this is an implementation of the firebase admin sdk, it is not intended to be used on client applications. So, although, I don't know the reason why it is not working on android (I don't remember explicitly disallowing it), it seems to be the correct behavior that it is not working.

Secondly, this library is a pure dart implementation, so it does not need any native android library. Adding 'classpath 'com.google.firebase:firebase-admin:5.3.1' is therefore not needed. Could it be that the unsupported error is thrown from this library?

akfaisel commented 4 years ago

Yes, it was my mistake.

I was running the example code after creating Flutter App instead of plain dart file.

OttomanDeveloper commented 2 years ago

Yes, it was my mistake.

I was running the example code after creating Flutter App instead of plain dart file.

Can you explain the issue?