Flutter + Golang

遇到很多坑, 很多文章都失效了, 做了很多实验后基本解决了, 记录一下。

第一个问题, gomobile报错找不到ndk-bundle, 可能是新版换了名字, 做个软连接就可以了:

ln -s ndk/21.2.6472646/ ndk-bundle


https://medium.com/stack-me-up/meet-the-coolest-tech-marriage-flutter-go-369cf11367c9 照着这篇实现完, Android Studio可以, 但是flutter run会报错:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':mylib:bundleDebugAar'.
> Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :mylib project caused this error: /Users/magicly/development/flutter-study/testgo/mylib/android/libs/num2words.aar

不能flutter run的话, hot reload就用不起来啊, 必须得解决。

搜了很多尝试后都不行, 这个解决了问题https://stackoverflow.com/a/60888941/2038404

I recently encountered the same issue, the fix was to remove the library from libs/ and import it using File -> New -> New Module -> Import .JAR/.AAR Package, then referencing it in the library module build.gradle file:

dependencies {
  implementation project(":imported_aar_module")

之前没好好看https://divan.dev/talks/2019/gdgbcn/FlutterGomobile.pdf , 应该吸取教训的。。。 Gradle need a phd!

还遇到一个坑, 哪怕是AS装了flutter插件, AS中打开flutter项目, android下的代码也是很多标红找不到, 要用AS打开项目下面的android目录!

另外开发的plugin也是没法单独打开的, 要打开example/androidhttps://flutter.dev/docs/development/packages-and-plugins/developing-packages#step-2b-add-android-platform-code-ktjava