Open38

FlutterでiOSアプリリリース

Hide(ひで)Hide(ひで)

https://docs.flutter.dev/get-started/install/macos/mobile-ios

hide@hidenoMacBook-Pro ohamoni_ios % sudo softwareupdate --install-rosetta --agree-to-license
Password:
By using the agreetolicense option, you are agreeing that you have run this tool with the license only option and have read and agreed to the terms.
If you do not agree, press CTRL-C and cancel this process immediately.
2024-08-14 15:15:39.064 softwareupdate[56470:9324628] Package Authoring Error: 042-82950: Package reference com.apple.pkg.RosettaUpdateAuto is missing installKBytes attribute
Install of Rosetta 2 finished successfully
Hide(ひで)Hide(ひで)

他の起床時間記録アプリのUIを見る。
起床 記録
でapp storeで検索して3つインストールしてみた。

Hide(ひで)Hide(ひで)

起床時間を記録するアプリを作って
to Claude

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:intl/intl.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '起床時間記録アプリ',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const WakeUpTimerPage(),
    );
  }
}

class WakeUpTimerPage extends StatefulWidget {
  const WakeUpTimerPage({super.key});

  
  _WakeUpTimerPageState createState() => _WakeUpTimerPageState();
}

class _WakeUpTimerPageState extends State<WakeUpTimerPage> {
  List<String> _wakeUpTimes = [];

  
  void initState() {
    super.initState();
    _loadWakeUpTimes();
  }

  void _loadWakeUpTimes() async {
    final prefs = await SharedPreferences.getInstance();
    setState(() {
      _wakeUpTimes = prefs.getStringList('wakeUpTimes') ?? [];
    });
  }

  void _saveWakeUpTime() async {
    final now = DateTime.now();
    final formattedTime = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
    
    final prefs = await SharedPreferences.getInstance();
    setState(() {
      _wakeUpTimes.insert(0, formattedTime);
      prefs.setStringList('wakeUpTimes', _wakeUpTimes);
    });
  }

  
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('起床時間記録'),
      ),
      body: ListView.builder(
        itemCount: _wakeUpTimes.length,
        itemBuilder: (context, index) {
          return ListTile(
            title: Text(_wakeUpTimes[index]),
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _saveWakeUpTime,
        tooltip: '起床時間を記録',
        child: const Icon(Icons.add),
      ),
    );
  }
}
Hide(ひで)Hide(ひで)
theme: ThemeData(
        // This is the theme of your application.
        //
        // TRY THIS: Try running your application with "flutter run". You'll see
        // the application has a purple toolbar. Then, without quitting the app,
        // try changing the seedColor in the colorScheme below to Colors.green
        // and then invoke "hot reload" (save your changes or press the "hot
        // reload" button in a Flutter-supported IDE, or press "r" if you used
        // the command line to start the app).
        //
        // Notice that the counter didn't reset back to zero; the application
        // state is not lost during the reload. To reset the state, use hot
        // restart instead.
        //
        // This works for code too, not just values: Most code changes can be
        // tested with just a hot reload.
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),

これでも上部の色は変わるけど。

Hide(ひで)Hide(ひで)

最初は別になんでもいいや。
SharedPreferencesを使う。

パッケージのインストール方法は?

Hide(ひで)Hide(ひで)

pubspec.yamlに追加した。

dependencies:
  flutter:
    sdk: flutter
  shared_preferences: ^2.3.1
Hide(ひで)Hide(ひで)
The method 'DateFormat' isn't defined for the type '_WakeUpTimerPageState'.
Try correcting the name to the name of an existing method, or defining a method named 'DateFormat'.dartundefined_method
Type: InvalidType

https://pub.dev/packages/intl
これがいるのかな?

いけた。

Hide(ひで)Hide(ひで)

再実行したら、

Launching lib/main.dart on iPhone 15 Pro Max in debug mode...
Warning: CocoaPods not installed. Skipping pod install.
  CocoaPods is a package manager for iOS or macOS platform code.
  Without CocoaPods, plugins will not work on iOS or macOS.
  For more info, see https://flutter.dev/to/platform-plugins
For installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation

CocoaPods not installed or not in valid state.
Error launching application on iPhone 15 Pro Max.

Exited (1).
Hide(ひで)Hide(ひで)

cocoapodsがいるらしい。
https://docs.flutter.dev/get-started/install/macos/mobile-ios#install-cocoapods

エラー

hide@hidenoMacBook-Pro ohamoni_ios % sudo gem install cocoapods
省略
ERROR:  Error installing cocoapods:
        The last version of drb (>= 0) to support your Ruby & RubyGems was 2.0.6. Try installing it with `gem install drb -v 2.0.6` and then running the current command again
        drb requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
Hide(ひで)Hide(ひで)

macのrubyが古い

hide@hidenoMacBook-Pro ohamoni_ios % ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]

rbenv入れる必要あるのか?
https://www.ruby-lang.org/ja/documentation/installation/
にあるbrew install rubyした。

brew install ruby

省略
Pruned 0 symbolic links and 8 directories from /opt/homebrew
==> Caveats
==> ruby
By default, binaries installed by gem will be placed into:
  /opt/homebrew/lib/ruby/gems/3.3.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc

For compilers to find ruby you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"

For pkg-config to find ruby you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/ruby/lib/pkgconfig"

~/.zshrcexport PATH="/opt/homebrew/opt/ruby/bin:$PATH"を追加して、

hide@hidenoMacBook-Pro ohamoni_ios % source ~/.zshrc
hide@hidenoMacBook-Pro ohamoni_ios % ruby -v        
ruby 3.3.4 (2024-07-09 revision be1089c8ec) [arm64-darwin22]
Hide(ひで)Hide(ひで)

再度cocoapodsインストールチャレンジ。
成功

hide@hidenoMacBook-Pro ohamoni_ios % sudo gem install cocoapods        
省略
35 gems installed

A new release of RubyGems is available: 3.5.14 → 3.5.17!
Run `gem update --system 3.5.17` to update your installation.
Hide(ひで)Hide(ひで)

https://docs.flutter.dev/get-started/install/macos/mobile-ios#install-cocoapods
に書いてあることをやって一応PC再起動したけどだめ。

main.ddartを実行するとエラー

Launching lib/main.dart on iPhone 15 Pro Max in debug mode...
Warning: CocoaPods not installed. Skipping pod install.
  CocoaPods is a package manager for iOS or macOS platform code.
  Without CocoaPods, plugins will not work on iOS or macOS.
  For more info, see https://flutter.dev/to/platform-plugins
For installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation

CocoaPods not installed or not in valid state.
Error launching application on iPhone 15 Pro Max.

Exited (1).
Hide(ひで)Hide(ひで)

debug実行時のここで選択ミスったらどうするの?

以降選択肢出ずに最初に選んだもので起動してしまう。。

Hide(ひで)Hide(ひで)

cocoapodsインストール先のディレクトリを指定したらいいのかなと思い以下のように設定してPCを再起動したら動きました。

~/.zshenv
export PATH=/opt/homebrew/lib/ruby/gems/3.3.0/bin:$PATH

インストール先はgem environmentで確認した。

Hide(ひで)Hide(ひで)

とりあえず、右下の+ボタンを押すと現在時刻が保存されて表示するようになった。

Hide(ひで)Hide(ひで)

deployGateで動かすようにしたい

https://deploygate.com/dashboard

エラーです。

curl -sSL https://deploygate.com/cli/install/3731e128 | bash

省略

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /opt/homebrew/lib/ruby/gems/3.3.0/gems/workers-0.6.1 directory.
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/installer.rb:356:in `rescue in install'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/installer.rb:305:in `install'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/resolver/specification.rb:105:in `install'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/request_set.rb:195:in `block in install'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/request_set.rb:183:in `each'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/request_set.rb:183:in `install'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/commands/install_command.rb:207:in `install_gem'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/commands/install_command.rb:223:in `block in install_gems'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/commands/install_command.rb:216:in `each'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/commands/install_command.rb:216:in `install_gems'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/commands/install_command.rb:162:in `execute'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/command.rb:326:in `invoke_with_build_args'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/command_manager.rb:255:in `invoke_command'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/command_manager.rb:194:in `process_args'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/command_manager.rb:152:in `run'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/gem_runner.rb:56:in `run'
        /opt/homebrew/opt/ruby/bin/gem:12:in `<main>'
Hide(ひで)Hide(ひで)

sudoしてもだめ

hide@hidenoMacBook-Pro 3.3.0 % sudo curl -sSL https://deploygate.com/cli/install/3731e128 | bash
Password:
Welcome to DeployGate!

         _            _                       _
        | |          | |                     | |
      __| | ___  ___ | | ___ _   ,____   ___ | |_ ___
     / _` |/ _ \' _ \| |/ _ \ \ / / _ \ / _ `| __/ _ \
    | (_| |  __/ |_) | | (_) \ v / (_| | (_| | |_' __/
     \___, \___| .__/|_|\___/ ` / \__, |\__,_|\__\___`
               |_|           /_/  |___/

Installing dg with "gem install deploygate --no-document".

This may take a while. It's a good time to grab some coffee ☕️

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /opt/homebrew/lib/ruby/gems/3.3.0/gems/aws-eventstream-1.3.0 directory.
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/installer.rb:356:in `rescue in install'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/installer.rb:305:in `install'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/resolver/specification.rb:105:in `install'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/request_set.rb:195:in `block in install'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/request_set.rb:183:in `each'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/request_set.rb:183:in `install'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/commands/install_command.rb:207:in `install_gem'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/commands/install_command.rb:223:in `block in install_gems'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/commands/install_command.rb:216:in `each'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/commands/install_command.rb:216:in `install_gems'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/commands/install_command.rb:162:in `execute'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/command.rb:326:in `invoke_with_build_args'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/command_manager.rb:255:in `invoke_command'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/command_manager.rb:194:in `process_args'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/command_manager.rb:152:in `run'
        /opt/homebrew/Cellar/ruby/3.3.4/lib/ruby/3.3.0/rubygems/gem_runner.rb:56:in `run'
        /opt/homebrew/opt/ruby/bin/gem:12:in `<main>'
hide@hidenoMacBook-Pro 3.3.0 %
Hide(ひで)Hide(ひで)

システムのrubyだと権限なくてインストールできないのでrbenv使うことに。

rbenvでシステムのruby使うようにした。

hide@hidenoMacBook-Pro ~ % which ruby
/Users/hide/.rbenv/shims/ruby

deploygateインストール成功

Hide(ひで)Hide(ひで)

プロジェクトでdg deploy
エラー

hide@hidenoMacBook-Pro ohamoni_ios % dg deploy
Error: undefined method `exists?' for class File

------------------------
DeployGate Error Report 

Title: undefined method `exists?' for class File
dg version: 0.10.0
Xcode version: 15.0.1

Stack trace:
/Users/hide/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/deploygate-0.10.0/lib/deploygate/android/gradle_project.rb:9:in `root_dir?'
/Users/hide/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/deploygate-0.10.0/lib/deploygate/project.rb:14:in `android?'
/Users/hide/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/deploygate-0.10.0/lib/deploygate/commands/deploy/build.rb:23:in `run'
/Users/hide/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/deploygate-0.10.0/lib/deploygate/commands/deploy.rb:16:in `run'
/Users/hide/.rbenv/versions/3.3.4/lib/ruby/gems/3.3.0/gems/deploygate-0.10.0/lib/deploygate/command_builder.rb:77:in `block (2 levels) in run'
and more ...
------------------------
Do you want to this error report to DeployGate? (y/n) |y| n

Flutterだとdeploygate使えないか、なにかする必要があるのか?

Hide(ひで)Hide(ひで)

アイコンを設定っする

flutter_launcher_icons: "^0.13.1"
https://pub.dev/packages/flutter_launcher_icons

hide@hidenoMacBook-Pro ohamoni_ios % flutter pub run flutter_launcher_icons
Deprecated. Use `dart run` instead.
Building package executable... 
Built flutter_launcher_icons:flutter_launcher_icons.
  ════════════════════════════════════════════
     FLUTTER LAUNCHER ICONS (v0.13.1)                               
  ════════════════════════════════════════════
  
• Overwriting default iOS launcher icon with new icon
No platform provided

✓ Successfully generated launcher icons

アイコン変わった!

Hide(ひで)Hide(ひで)

https://zenn.dev/flutteruniv_dev/articles/afca2b8136b705
flutter build ipaしてアップしてらDGで使える?

hide@hidenoMacBook-Pro ohamoni_ios % flutter build ipa
Resolving dependencies... 
Downloading packages... 
  collection 1.18.0 (1.19.0 available)
  material_color_utilities 0.11.1 (0.12.0 available)
  string_scanner 1.2.0 (1.3.0 available)
  test_api 0.7.2 (0.7.3 available)
Got dependencies!
4 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.
 
Archiving com.example.ohamoni...
Automatically signing iOS for device deployment using specified development team in Xcode project: ZF87CQX97T
Running pod install...                                             602ms
Running Xcode build...                                                  
 └─Compiling, linking and signing...                      2,975ms
Xcode archive done.                                         20.9s
✓ Built build/ios/archive/Runner.xcarchive (67.8MB)

[!] App Settings Validation
    • Version Number: 1.0.0
    • Build Number: 1
    • Display Name: Ohamoni
    • Deployment Target: 12.0
    • Bundle Identifier: com.example.ohamoni
    ! Your application still contains the default "com.example" bundle identifier.

[!] App Icon and Launch Image Assets Validation
    ! Launch image is set to the default placeholder icon. Replace with unique launch image.

To update the settings, please refer to https://flutter.dev/to/ios-deploy

Building App Store IPA...                                          17.4s
Encountered error while creating the IPA:
error: exportArchive: Communication with Apple failed
error: exportArchive: No signing certificate "iOS Distribution" found
error: exportArchive: Communication with Apple failed

略

エラーでビルドできず

Hide(ひで)Hide(ひで)

とりあえずApple Developer Programに登録しよ。どうせ必ず必要になるので。

macからやった。
本人確認に何回も失敗した。

そもそもアカウントの名前が漢字なのがよくないかも?と思い大文字始まりのローマ字にした。
すると、Apple Developer Programの登録時の名と氏にデフォルトでアカウントの名前が入った。
写真は運転免許書で進めた。
その後住所入力すると、

になった。

Hide(ひで)Hide(ひで)

問い合わせ返ってくるまで開発を進める。

Scaffoldってなに?

ウィジェット。
用意されたレイアウトを使えるイメージ?

Hide(ひで)Hide(ひで)

お問い合わせ返ってきてた


現在のご状況を確認いたしましたところ、Apple Developer App を使って送信していただいた個人識別情報に問題があるようです。



再度ご登録いただけるようアカウントを調整させていただきましたので、個人の本人確認に関する必要条件をご確認いただき、個人情報の再提出をお願いいたします。 

もう1回登録してみてとのこと。

Hide(ひで)Hide(ひで)

XCodeでarchiveしてupload成功
証明書?なんか昔に用意してたやつがあった。改めて整理しておきたい