当我添加 firebase admin 和 json 文件的路径时, 有一个错误无法修复:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
var cred = FirebaseAdmin.instance.certFromPath('admin-services.json');
print(cred.toString());
FirebaseAdmin.instance.initializeApp(
AppOptions(
credential: cred,
databaseUrl: databaseURL,
),
);
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
这里的错误:
E/flutter (16111): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FirebaseAppError(app/invalid-credential): Failed to parse certificate key file: PathNotFoundException: Cannot open file, path = 'admin-services.json' (OS Error: No such file or directory, errno = 2)
E/flutter (16111): #0 new ServiceAccountCredential credential.dart:97
E/flutter (16111): #1 FirebaseAdmin.certFromPath admin.dart:113
E/flutter (16111): #2 main main.dart:14
E/flutter (16111): #3 _runMain.<anonymous closure> (dart:ui/hooks.dart:131:23)
E/flutter (16111): #4 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:296:19)
E/flutter (16111): #5 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
我尝试移动文件,甚至使用 json 文件的绝对路径或其他方式,但也收到错误:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
var cred = FirebaseAdmin.instance.cert(projectId: projectId,
clientEmail: clientEmail,
privateKey: privateKey);
print(cred.toString());
FirebaseAdmin.instance.initializeApp(
AppOptions(
credential: cred,
databaseUrl: databaseURL,
),
);
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
错误:
E/flutter (15745): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: UnimplementedError
E/flutter (15745): #0 FirebaseAdmin.cert admin.dart:108
E/flutter (15745): #1 main main.dart:14
E/flutter (15745): #2 _runMain.<anonymous closure> (dart:ui/hooks.dart:131:23)
E/flutter (15745): #3 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:296:19)
E/flutter (15745): #4 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)