[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$fwWykwf_z8cLk6IHq08g5X9E8gwFhyliUekNPa27XmCQ":3},{"code":4,"message":5,"data":6},200,"成功",{"id":7,"createdAt":8,"title":9,"content":10,"summary":11,"image":12,"uid":13,"user":14,"categoryId":21,"category":22,"subCategoryId":24,"subCategory":25,"comments":27,"status":17,"reason":28,"notice":28,"visitCount":29,"commentCount":30,"keywords":31},165,"2025-08-15T08:34:21.937Z","flutter compileDebugKotlin的报错：Unresolved reference 'Registrar'","## 报错信息\n\n> Launching lib/main.dart on sdk gphone64 arm64 in debug mode...\nRunning Gradle task 'assembleDebug'...\nWarning: Flutter support for your project's Android Gradle Plugin version (Android Gradle Plugin version 8.1.0) will soon be dropped. Please upgrade your Android Gradle Plugin version to a version of at least Android Gradle Plugin version 8.3.0 soon.\nAlternatively, use the flag \"--android-skip-build-dependency-validation\" to bypass this check.\nPotential fix: Your project's AGP version is typically defined in the plugins block of the `settings.gradle` file (/Users/xxx/android/settings.gradle), by a plugin with the id of com.android.application. \nIf you don't see a plugins block, your project was likely created with an older template version. In this case it is most likely defined in the top-level build.gradle file (/Users/xxx/android/build.gradle) by the following line in the dependencies block of the buildscript: \"classpath 'com.android.tools.build:gradle:\u003Cversion>'\".\nwarning: [options] source value 8 is obsolete and will be removed in a future release\nwarning: [options] target value 8 is obsolete and will be removed in a future release\nwarning: [options] To suppress warnings about obsolete options, use -Xlint:-options.\n3 warnings\ne: file:///Users/han/.pub-cache/hosted/pub.dev/image_gallery_saver-2.0.1/android/src/main/kotlin/com/example/imagegallerysaver/ImageGallerySaverPlugin.kt:18:48 Unresolved reference 'Registrar'.\ne: file:///Users/xxx/plugin/FlutterToast/android/src/main/kotlin/io/github/ponnamkarthik/toast/fluttertoast/FlutterToastPlugin.kt:9:48 Unresolved reference 'Registrar'.\nFAILURE: Build completed with 2 failures.\n1: Task failed with an exception.\n> * What went wrong:\nExecution failed for task ':image_gallery_saver:compileDebugKotlin'.\n> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction\n   > Compilation error. See log for more details\n> * Try:\n> Run with --stacktrace option to get the stack trace.\n> Run with --info or --debug option to get more log output.\n> Run with --scan to get full insights.\n> Get more help at https://help.gradle.org.\n> ==============================================================================\n> 2: Task failed with an exception.\n> -----------\n> * What went wrong:\nExecution failed for task ':fluttertoast:compileDebugKotlin'.\n> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction\n   > Compilation error. See log for more details\n> * Try:\n> Run with --stacktrace option to get the stack trace.\n> Run with --info or --debug option to get more log output.\n> Run with --scan to get full insights.\n> Get more help at https://help.gradle.org.\n==============================================================================\nBUILD FAILED in 29s\nError: Gradle task assembleDebug failed with exit code 1\n>\n\n## 报错截图：\n![](https://image.xinwei.ltd/12231755241266073.png)\n![](https://image.xinwei.ltd/image1755241307976.png)\n![](https://image.xinwei.ltd/image1755241336036.png)\n\n\n## 分析\n从上述的编译信息可以看出，报错在于：fluttertoast:compileDebugKotlin 和 image_gallery_saver:compileDebugKotlin，导致问题出现的真正原因在于`e: file://`这2个报错语句中，关键信息是：`Unresolved reference 'Registrar'`。\n\n这个`Registrar`类，在早期flutter版本更新中已经提到过，可以查看flutter官方解释：[https://docs.flutter.dev/release/breaking-changes/plugin-api-migration](https://docs.flutter.dev/release/breaking-changes/plugin-api-migration)\n![](https://image.xinwei.ltd/image1755241744337.png)\n\n那么我们根据报错信息中去看对应的file文件，可以看到(以imagegallerysaver为例):\n![](https://image.xinwei.ltd/image1755241840637.png)\n\n总而言之一句话，flutter已经让大多数的插件发布者发布新的不含`Registrar`的新版本了，开发者可以去官网: pub.dev去查看是否有新版本或者plus的插件。\n![](https://image.xinwei.ltd/image1755242083655.png)\n\n那么问题也就好办了，办法有三：\n- 1. 去pub.dev看看报错的库是否发布了新版本，且新版本中已经去掉`Registrar`；\n- 2. 如果新版本中还是没有去掉`Registrar`依赖，那么寻找其他新库替代；\n- 3. 如果也找不到新库，直接fork原来的库，在库里面去掉`Registrar`的依赖，并且按照下面引用话中使用基于`FlutterPlugin`的引用，然后改造成本地依赖的plugin，也是可以的。\n> but we encourage you to migrate to the new APIs based on FlutterPlugin.\n\n那么针对我这里的报错，对于`fluttertoast`这个库，是我本地的plugin库，我直接在本地的plugin中删掉`Registrar`的引用即可；对于`image_gallery_saver`，查了一下，最新的版本也没有解决这个问题，那么使用了另一个库替换它，新库是`image_gallery_saver_plus: ^4.0.1`，然后在使用的地方改成新库的API即可。\n\n至此，编译报错可以解决了。\n\n\n另外编译信息中提到了gradle版本的问题，最好是要升级一下，下一篇我们来详细描述如何去做。\n\n","这篇文章记录我的flutter工程，在升级flutter版本时遇到的Android编译报错问题。","https://image.xinwei.ltd/12231755241266073.png",499668042977349,{"phone":15,"userId":13,"nickName":16,"vipType":17,"avatar":18,"sign":19,"createdAt":20},"13121171998","全栈老韩",1,"https://image.xinwei.ltd/images/IMG_5430.JPG","全栈工程师，擅长iOS App开发、前端（vue、react、nuxt、小程序&Taro）开发、Flutter、React Native、后端（midwayjs、golang、express、koa）开发、docker容器、seo优化等。","2024-01-01T16:14:30.305Z",2,{"id":21,"name":23},"IT技术",11,{"id":24,"name":26,"parentId":21},"Flutter",[],"",34,0,"fluttertoast,compileDebugKotlin,Unresolved reference 'Registrar',image_gallery_saver,flutter android"]