You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS下Android Studio Koala中firebase_core依赖引用报错求助

Flutter项目导入firebase_core提示“Target of URI doesn't exist”的解决排查方案

在MacOS系统的Android Studio Koala环境开发Flutter项目时,导入package:firebase_core/firebase_core.dart和package:firebase_core/firebase_options.dart时,IDE提示Target of URI doesn't exist错误。已完成flutterfire CLI配置登录,尝试过flutter pub get、flutter clean、flutter pub add firebase_core、flutterfire configure、切换Flutter stable通道、重启IDE并清除缓存等操作,问题仍未解决。


相关代码与终端输出

main.dart代码

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_core/firebase_options.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

flutter pub add firebase_core终端输出

(base) ryanli@Ryans-MacBook-Air testfyp_mobileapp % flutter pub add firebase_core
"firebase_core" is already in "dependencies". Will try to update the constraint.
Resolving dependencies...
Downloading packages...
collection 1.18.0 (1.19.0 available)
leak_tracker 10.0.5 (10.0.7 available)
leak_tracker_flutter_testing 3.0.5 (3.0.7 available)
material_color_utilities 0.11.1 (0.12.0 available)
string_scanner 1.2.0 (1.3.0 available)
test_api 0.7.2 (0.7.3 available)
web 0.5.1 (1.0.0 available)
Got dependencies!
7 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.

排查解决步骤

  • 检查pubspec.yaml依赖配置
    打开项目根目录的pubspec.yaml,确认firebase_core依赖格式正确无拼写错误,示例:

    dependencies:
      flutter:
        sdk: flutter
      firebase_core: ^2.24.2 # 版本号可根据flutterfire提示调整为有效版本
    

    保存后重新执行flutter pub get,等待依赖完全下载。

  • 确认firebase_options.dart文件存在
    执行flutterfire configure后,lib目录下应生成firebase_options.dart文件。若不存在,重新执行flutterfire configure,确保选择正确的项目与平台,配置过程无报错。

  • 校验Android Studio的Flutter SDK配置
    打开Android Studio偏好设置→Languages & Frameworks→Flutter,确认Flutter SDK路径正确,且为stable通道的最新版本(可执行flutter upgrade升级)。

  • 彻底清除IDE索引缓存
    执行File→Invalidate Caches...,选择Invalidate and Restart,彻底清除IDE索引缓存,重启后让IDE重新扫描项目依赖。

  • 检查依赖兼容性
    执行flutter doctor排查环境异常,执行flutter pub outdated查看依赖兼容性,尝试更新至兼容版本。

  • 手动清除pub缓存
    进入MacOS的.pub-cache目录(路径通常为~/Developer/flutter/.pub-cache或~/.pub-cache),删除firebase_core相关缓存文件夹,再重新执行flutter pub get。

  • 确认项目目录权限
    确保项目所在目录拥有读写权限,避免因权限问题导致依赖文件无法正常下载或读取。

内容的提问来源于stack exchange,提问作者LI SZE HAN RYAN

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 01:55:55