報錯日誌
[INFO] Checking for unexpected pre-existing outputs....
[INFO] Found 14 declared outputs which already exist on disk. This is likely because the`.dart_tool/build` folder was deleted, or you are submitting generated files to your source repository.
[SEVERE] Conflicting outputs were detected and the build is unable to prompt for permission to remove them. These outputs must be removed manually or the build can be run with `--delete-conflicting-o
utputs`. The outputs are: lib/data/http/rsp/BaseRsp.g.dart
[INFO] Generating build script...
[INFO] Generating build script completed, took 246ms
[SEVERE] Nothing can be built, yet a build was requested.
pub finished with exit code 78
複製程式碼
引發的過程
這個問題出現的挺巧的,專案給的工時不長,週六回家之後用自己電腦從git倉庫上Clone了一份程式碼,執行沒有問題。但是在用flutter packages pub run build_runner build
生成xxxx.g.dart
的時候問題出來了。日誌如上。
引發的原因
原因其實日誌也說明了。我在提交程式碼的時候把flutter packages pub run build_runner build
生成的xxxx.g.dart
也提了上去。執行flutter packages pub run build_runner build
不光生成了xxxx.g.dart
。同時還成了一個dart_tool/build目錄,入過程所說的只執行app是沒有問題的,之前xxxx.g.dart
還是可用的。但是再生成新的xxxx.g.dart
因為缺少之前生成dart_tool/build目下的檔案就會報錯。
because the`.dart_tool/build` folder was deleted, or you are submitting generated files to your source repository
複製程式碼
解決
命令列執行:
//清除之前生成的檔案,如果直接執行下面的不行。可以先嚐試執行這個
flutter packages pub run build_runner clean
//可以直接執行這個
flutter packages pub run build_runner build --delete-conflicting-outputs
複製程式碼
當然解決問題的根本方法還是提程式碼的時候不要將生成的檔案也提交到遠端倉庫