Flutter誤刪除android/ios目錄怎麼辦?

jarvanmo發表於2018-09-27

最近有朋友遇到了這樣的一個問題:在Flutter開發中誤刪android/ios該如何挽救?。很多朋友會嘗試從回收站中恢復,但如果無法從回收站中恢復怎麼辦?還有辦法拯救一下自己嗎。答案是肯定的。我們可以通過flutter create命令拯救自己。看一下flutter create:

flutter help create
Create a new Flutter project.

If run on a project that already exists, this will repair the project, recreating any files that are missing.

Usage: flutter create <output directory>
-h, --help                     Print this usage information.
    --[no-]pub                 Whether to run "flutter packages get" after the project has been created.
                               (defaults to on)

    --[no-]offline             When "flutter packages get" is run by the create command, this indicates whether to run it in offline mode or not. In offline mode, it will need to have all dependencies already available in the pub cache to succeed.
    --[no-]with-driver-test    Also add a flutter_driver dependency and generate a sample `flutter drive` test.
-t, --template=<type>          Specify the type of project to create.

          [app] (default)      (default) Generate a Flutter application.
          [package]            Generate a shareable Flutter project containing modular Dart code.
          [plugin]             Generate a shareable Flutter project containing an API in Dart code
                               with a platform-specific implementation for Android, for iOS code, or for both.

    --description              The description to use for your new Flutter project. This string ends up in the pubspec.yaml file.
                               (defaults to "A new Flutter project.")

    --org                      The organization responsible for your new Flutter project, in reverse domain name notation.
                               This string is used in Java package names and as prefix in the iOS bundle identifier.
                               (defaults to "com.example")

-i, --ios-language             [objc (default), swift]
-a, --android-language         [java (default), kotlin]

幫助說的很清楚,如果在一個既存專案中執行這個命令,那麼這將會修復當前專案,重新建立丟失的檔案。簡單示例程式碼:

flutter create  -i objc .

引數解釋:

  • -i 是表示iOS專案開發語言,objc和swift兩個選項,其中objc是預設的。
  • -a 是表示Android專案開發語言,java和kotlin兩個選項,其中java是預設的。

當然了create命令還給我們提供了一些其他選項:

  • -t , –template=<type> 模板。共三個可選項:app,package,plugin。其中app是預設的。
  • –org 組織名稱。這個引數將作為java包名以及iOS的BundleID字首。預設是“com.example”。
  • –description 描述。這將用於描述當前的工程,也會在pubspec.yaml中有所體現。預設是”A new Flutter project.“。

到此為止,create命令就算介紹完了。有的同學可能會有疑問,這個修復到底有什麼用?沒有版本管理工具嗎?實際上,這個命令非常有用。很多時候,寫一個demo是沒版本管理工具的,或者原來的專案是oc寫的,突然又改變了主意,想改用swift了,這時候就該用create了。
希望本文對你有所幫助。歡迎加入 OpenFlutter交流群:892398530。
版本所有,轉載請註明出處


相關文章