Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported operation: Unsupported platform: android #6

Closed
akfaisel opened this issue Aug 2, 2020 · 3 comments
Closed

Unsupported operation: Unsupported platform: android #6

akfaisel opened this issue Aug 2, 2020 · 3 comments

Comments

@akfaisel
Copy link

akfaisel commented Aug 2, 2020

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
Copy link
Contributor

rbellens commented Aug 6, 2020

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
Copy link
Author

akfaisel commented Aug 7, 2020

Yes, it was my mistake.

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

@OttomanDeveloper
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants