Open10

fastlane

ImaelImael

xcode-select --install
すでにインストールさていると表示
xcode-select: note: Command line tools are already installed. Use "Software Update" in System Settings or the softwareupdate command line interface to install updates

RubyGemsをつかってfastlaneインストール
sudo gem install fastlane -NV
パスワード入力して実行

エラーがでた
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory.
/Library/Ruby/Site/2.6.0/rubygems/installer.rb:712:in verify_gem_home' /Library/Ruby/Site/2.6.0/rubygems/installer.rb:902:in pre_install_checks'
/Library/Ruby/Site/2.6.0/rubygems/installer.rb:302:in install' /Library/Ruby/Site/2.6.0/rubygems/resolver/specification.rb:104:in install'
/Library/Ruby/Site/2.6.0/rubygems/request_set.rb:194:in block in install' /Library/Ruby/Site/2.6.0/rubygems/request_set.rb:182:in each'
/Library/Ruby/Site/2.6.0/rubygems/request_set.rb:182:in install' /Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:214:in install_gem'
/Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:230:in block in install_gems' /Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:223:in each'
/Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:223:in install_gems' /Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:169:in execute'
/Library/Ruby/Site/2.6.0/rubygems/command.rb:323:in invoke_with_build_args' /Library/Ruby/Site/2.6.0/rubygems/command_manager.rb:251:in invoke_command'
/Library/Ruby/Site/2.6.0/rubygems/command_manager.rb:191:in process_args' /Library/Ruby/Site/2.6.0/rubygems/command_manager.rb:149:in run'
/Library/Ruby/Site/2.6.0/rubygems/gem_runner.rb:51:in run' /usr/bin/gem:21:in <main>'

System/Library/Frameworks/Ruby.framewoに対する書き込み権限がありませんとのこと。

ChatGPTにきいた
Homebrewを使ってFastlaneをインストール
brew install fastlane

以下コマンドでfastlaneが利用できることを確認
fastlane --version


fastlane installation at path:

/opt/homebrew/Cellar/fastlane/2.222.0/libexec/gems/fastlane-2.222.0/bin/fastlane

[✔] 🚀
fastlane 2.222.0
fastlane導入できました。

ImaelImael

対象プロジェクトのルートディレクトリに移動して、initコマンドで雛形生成
fastlane init

[✔] 🚀
[✔] Looking for iOS and Android projects in current directory...
[08:45:57]: Created new folder './fastlane'.
[08:45:57]: Detected an iOS/macOS project in the current directory: 'WikiSurprise.xcodeproj'
[08:45:57]: -----------------------------
[08:45:57]: --- Welcome to fastlane 🚀 ---
[08:45:57]: -----------------------------
[08:45:57]: fastlane can help you with all kinds of automation for your mobile app
[08:45:57]: We recommend automating one task first, and then gradually automating more over time
[08:45:57]: What would you like to use fastlane for?

  1. 📸 Automate screenshots
  2. 👩‍✈️ Automate beta distribution to TestFlight
  3. 🚀 Automate App Store distribution
  4. 🛠 Manual setup - manually setup your project to automate your tasks
    ?

今回は4を入力

08:48:35: --- Setting up fastlane so you can manually configure it ---
08:48:35: ------------------------------------------------------------
08:48:35: Installing dependencies for you...
08:48:35: $ bundle update
[08:48:56]: --------------------------------------------------------
[08:48:56]: --- ✅ Successfully generated fastlane configuration ---
[08:48:56]: --------------------------------------------------------
[08:48:56]: Generated Fastfile at path ./fastlane/Fastfile
[08:48:56]: Generated Appfile at path ./fastlane/Appfile
[08:48:56]: Gemfile and Gemfile.lock at path Gemfile
[08:48:56]: Please check the newly generated configuration files into git along with your project
[08:48:56]: This way everyone in your team can benefit from your fastlane setup
[08:48:56]: Continue by pressing Enter ⏎

Enterキー入力を3回実行

08:49:41: --- Where to go from here? ---
08:49:41: ------------------------------
08:49:41: 📸 Learn more about how to automatically generate localized App Store screenshots:
08:49:41: https://docs.fastlane.tools/getting-started/ios/screenshots/
08:49:41: 👩‍✈️ Learn more about distribution to beta testing services:
08:49:41: https://docs.fastlane.tools/getting-started/ios/beta-deployment/
08:49:41: 🚀 Learn more about how to automate the App Store release process:
08:49:41: https://docs.fastlane.tools/getting-started/ios/appstore-deployment/
08:49:41: 👩‍⚕️ Learn more about how to setup code signing with fastlane
08:49:41: https://docs.fastlane.tools/codesigning/getting-started/
08:49:41:
08:49:41: To try your new fastlane setup, just enter and run
08:49:41: $ fastlane custom_lane

プロジェクトのディレクトリに
fastlane
Gemfile
Gemfile.lock
が生成される

fastlaneに2つのファイルが生成
fastlane % ls
Appfile Fastfile

Fastfileに自動化タスクを記述する
AppfileはAppleID等を記述ファイル

ImaelImael

Fastfileを編集
default_platform(:ios)

platform :ios do
desc "こんにちは"
lane :hello do
# add actions here: https://docs.fastlane.tools/actions
puts("Hello, fastlane!")
end
end

コマンド実行
fastlane
どのレーンを実行するか、選択
[✔] 🚀
[13:41:00]: fastlane detected a Gemfile in the current directory
[13:41:00]: However, it seems like you didn't use bundle exec
[13:41:00]: To launch fastlane faster, please use
[13:41:00]:
[13:41:00]: $ bundle exec fastlane hello
[13:41:00]:
[13:41:00]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[13:41:01]: ------------------------------
[13:41:01]: --- Step: default_platform ---
[13:41:01]: ------------------------------
+------------------------+
| Lane Context |
+------------------+-----+
| DEFAULT_PLATFORM | ios |
+------------------+-----+
[13:41:01]: Could not find lane 'ios hello'. Available lanes: ios holle

+---------------------------------------+
| fastlane summary |
+------+------------------+-------------+
| Step | Action | Time (in s) |
+------+------------------+-------------+
| 1 | default_platform | 0 |
+------+------------------+-------------+

[13:41:01]: fastlane finished with errors

[!] Could not find lane 'ios hello'. Available lanes: ios holle
koalapanda@MacBook-Air-2 fastlane % fastlane
[✔] 🚀
[13:41:53]: fastlane detected a Gemfile in the current directory
[13:41:53]: However, it seems like you didn't use bundle exec
[13:41:53]: To launch fastlane faster, please use
[13:41:53]:
[13:41:53]: $ bundle exec fastlane
[13:41:53]:
[13:41:53]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[13:41:55]: ------------------------------
[13:41:55]: --- Step: default_platform ---
[13:41:55]: ------------------------------
[13:41:55]: Welcome to fastlane! Here's what your app is set up to do:
+------------------------------------------+
| Available lanes to run |
+--------+-----------+---------------------+
| Number | Lane Name | Description |
+--------+-----------+---------------------+
| 1 | ios hello | こんにちは |
| 0 | cancel | No selection, exit |
| | | fastlane! |
+--------+-----------+---------------------+
[13:41:55]: Which number would you like to run?

1を入力

1
[13:42:23]: Running lane ios hello. Next time you can do this by directly typing fastlane ios hello 🚀.
[13:42:23]: Driving the lane 'ios hello' 🚀
[13:42:23]: Hello, fastlane!

+---------------------------------------+
| fastlane summary |
+------+------------------+-------------+
| Step | Action | Time (in s) |
+------+------------------+-------------+
| 1 | default_platform | 0 |
+------+------------------+-------------+

[13:42:23]: fastlane.tools finished successfully 🎉

CI/CD環境では
レーンを直接指定して実行
fastlane hello

[✔] 🚀
[13:43:10]: fastlane detected a Gemfile in the current directory
[13:43:10]: However, it seems like you didn't use bundle exec
[13:43:10]: To launch fastlane faster, please use
[13:43:10]:
[13:43:10]: $ bundle exec fastlane hello
[13:43:10]:
[13:43:10]: Get started using a Gemfile for fastlane https://docs.fastlane.tools/getting-started/ios/setup/#use-a-gemfile
[13:43:11]: ------------------------------
[13:43:11]: --- Step: default_platform ---
[13:43:11]: ------------------------------
[13:43:11]: Driving the lane 'ios hello' 🚀
[13:43:11]: Hello, fastlane!

+---------------------------------------+
| fastlane summary |
+------+------------------+-------------+
| Step | Action | Time (in s) |
+------+------------------+-------------+
| 1 | default_platform | 0 |
+------+------------------+-------------+

ImaelImael

default_platform(:ios)

platform :ios do

desc "Debugビルド"
lane :build do

# アクションの呼び出し
build_ios_app(
    workspace: "App.xcworkspace",
    sheme: "MyScheme",
    configureation: "Debug",
    clean: true,
    output_directory: "build",
    output_name: "myapp_debug.ipa"
)

end
end

プロジェクトのパターン
default_platform(:ios)

platform :ios do

desc "Debugビルド"
lane :build do

# アクションの呼び出し
build_ios_app(
    project: "WikiSurprise.xcodeproj",
    scheme: "WikiSurprise",
    configuration: "Debug",
    clean: true,
    output_directory: "build",
    output_name: "myapp_debug.ipa"
)

end
end

Xcodeのメニューから「Product」→「Scheme」→「Manage Schemes...」を選択し、スキームを確認

fastlane build

ImaelImael

テストの実行
desc "単体テストの実行"
lane :unittest do

# アクションの呼び出し
run_tests(
    project: "WikiSurprise.xcodeproj",
    scheme: "WikiSurprise",
    configuration: "Debug",
    clean: true,
    devices: ["iPhone 15 Pro"],
    open_report: true,
    output_types: "html",
    output_directory: "test"
)

end

htmlにテスト結果が出力されない

xcprettyかxcbeautify

https://ikesyo.hatenablog.com/entry/2024/06/17/153954

xcbeautifyをインストール
brew install xcbeautify

which xcbeautify
/opt/homebrew/bin/xcbeautify

    run_tests(
        project: "WikiSurprise.xcodeproj",
        scheme: "WikiSurprise",
        configuration: "Debug",
        clean: true,
        devices: ["iPhone 15 Pro"],
        open_report: true,
        output_types: "html,junit",
        result_bundle: true,
        output_directory: "fastlane/test_output",
        xcodebuild_formatter: "xcpretty"  # xcprettyを使用
    )

エラーは出ず、テストは成功しているけど
HTMLに出力されない。。。。

ImaelImael

メタデータの更新
desc "メタデータの更新"
lane :update_metadata do

    upload_to_app_store(
        username: "君のappleID",
        app_identifier: "バンドルID",
        force: false
    )

end

ImaelImael

https://stackoverflow.com/questions/74210927/fastlane-altool-error-unable-to-upload-archive-failed-to-get-authorization

Error uploading ipa file:
[Application Loader Error Output]: Exception caught. *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil (-1010)
[Application Loader Error Output]: The call to the altool completed with a non-zero exit status: 1. This indicates a failure.
https://github.com/fastlane/fastlane/issues/21060

app_store_connect_api_keyアクションに切り替え

ImaelImael

[16:48:54]: Authentication credentials are missing or invalid. - Provide a properly configured and signed bearer token, and make sure that it has not expired. Learn more about Generating Tokens for API Requests https://developer.apple.com/go/?id=api-generating-tokens

[17:22:33]: The provided entity includes an attribute with a value that has already been used - The version number has been previously used. - /data/attributes/versionString

Precheck cannot check In-app purchases with the App Store Connect API Key (yet). Exclude In-app purchases from precheck, disable the precheck step in your build step, or use Apple ID login

ImaelImael

fastlane finished with errors

[!] Your current version () does not respect the format A or A.B or A.B.C
解決
<key>CFBundleShortVersionString</key>
<string>1.0.27</string>
<key>CFBundleVersion</key>
<string>1</string>