Flutterで作ったアプリに決済機能を追加する
M1 Macにflutterをインストールする
先にrosettaをインストールしておく
sudo softwareupdate --install-rosetta --agree-to-license
公式だと、zipファイルをダウンロードして、と書いているけど、homebrewにもある。
今回はhomebrewでインストールしてみる
brew install --cask flutter
flutter doctor
を実行する
Running "flutter pub get" in flutter_tools... 8.2s
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.9, on macOS 12.6.1 21G217 darwin-arm, locale ja-JP)
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
[!] Xcode - develop for iOS and macOS (Xcode 14.1)
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the
Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
✗ Unable to find bundled Java version.
[✓] Android Studio (version 2021.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3)
[✓] VS Code (version 1.74.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 3 categories.
homebrewでインストールしたflutterのバージョンが3.3.9なので、brew upgradeを行う
brew upgrade flutter
Android Studioをインストールして起動する
CocoaPodsをインストールする
sudo gem install cocoapods
cocoapodsインストールでエラーが出た
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20230121-48319-xm1r93.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
--with-ffi_c-dir
--without-ffi_c-dir
--with-ffi_c-include
--without-ffi_c-include=${ffi_c-dir}/include
--with-ffi_c-lib
--without-ffi_c-lib=${ffi_c-dir}/lib
--enable-system-libffi
--disable-system-libffi
--with-libffi-config
--without-libffi-config
--with-pkg-config
--without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:546:in `block in try_link0'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
from extconf.rb:9:in `system_libffi_usable?'
from extconf.rb:42:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.5/mkmf.log
extconf failed, exit code 1
M1 Macだからか?
この記事を参考にcocoapodsもhomebrewでインストールしてみる
brew install cocoapods
インストールできたみたい
改めて
flutter doctor
Running "flutter pub get" in flutter_tools... 8.9s
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.6.1 21G217 darwin-arm, locale ja-JP)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
✗ Unable to find bundled Java version.
[✓] Android Studio (version 2021.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3)
[✓] VS Code (version 1.74.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
Android studioのコマンドラインツールをインストールする
Android Studio -> Pereferences -> Appearance & Behavior -> Sytem Settings -> Android SDK -> SDK Tools
Android SDK Command-line ToolsをONに設定してApply
flutter doctor --android-licenses
でライセンスに同意する
Jetbrains Toolbox でインストールしたAndroid Studio 2022.1で Unable to find bundled Java version.のエラーが出ている件、StackOverflowで解決策があった。
For those having these issues with the latest Android Studio - Electric Eel version, and other canaries and preview releases, note that the bundled jre directory in the Android Studio installation folder is now renamed to jbr
To resolve this, just create a sym link jre -> jbr and Flutter won't complain.
cd ~/Library/Application\ Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/Android\ Studio.app/Contents/
ln -s jbr jre
改めて
flutter doctor
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.6.1 21G217 darwin-arm, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
[✓] VS Code (version 1.74.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
インストールできたっぽい
今回はIntellij IDEAのUltimateでFlutterアプリを実装してみる。
Intellij IDEAにflutterのプラグインをインストールしておく。
Create New ProjectでFlutterを選択する。
fullter SDKのパスを求められた。
今回はhomebrewでflutterをインストールしているので以下のStackOverflowを参考にパスを取得した。
Terminal で以下を実行する
flutter doctor -v
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.6.1 21G217 darwin-arm, locale ja-JP)
• Flutter version 3.3.10 on channel stable at /opt/homebrew/Caskroom/flutter/3.3.10/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 135454af32 (5 weeks ago), 2022-12-15 07:36:55 -0800
• Engine revision 3316dd8728
• Dart version 2.18.6
• DevTools version 2.15.0
...
この/opt/homebrew/Caskroom/flutter/3.3.10/flutterをsdkのパスとして使う。
Project Nameは flutter_sampleにした。 (ケバブケースはだめみたい)
試しにiPhone用にビルドを実行してみる
Targetをクリックして、Open iOS Simulatorをクリックする。
iOS Simulator が起動すると、TargetにiPhoneが追加される。
今回は、iPhone 14 Proがデフォルトで追加されたけど、他のTargetはどうやって選択するんだろう。。
Flutterのアプリ内課金の実装方法について
flutterの1st partyの in_app_purchaseを使うのが良さそう。
Apple iOS Developer ProgramのアカウントとApp Storeでアプリを公開していることが必要。
iOS アプリのリリースについての詳細
Androidについても同様。Google Developerアカウントを取得して、Playストアにアプリケーションを公開する必要がある。
Android アプリのリリースについての詳細