# 【Flutter Xcode】AgoraRtmKit contains bitcode エラーの解決方法

> FlutterのXcode上でAgoraパッケージを使用したビルドのエラーError: Asset validation failed (90482) Invalid Executable. The executable 'Runner.app/Frameworks/AgoraRtmKit.framework/AgoraRtmKit' contains bitcode.解決方法です。

- 公開日: 2024-10-31
- 更新日: 2024-11-01
- 著者: Matsu
- タグ: Flutter
- URL: https://tech.anycloud.co.jp/articles/xcode-agora-contains-bitcode

---

FlutterのAgoraパッケージを使用していて、iOSのBitcodeの問題でビルドに失敗する問題についてです。

## 環境

```shell
environment:
  sdk: ">=3.5.0 <4.0.0"
  flutter: 3.24.0

dependencies:
  agora_rtc_engine: ^6.3.2
  agora_rtm: ^1.5.9
```

-   Xcode16

<div class="link-card-wrap"><a class="link-card" href="https://pub.dev/packages/agora_rtc_engine" target="_blank" rel="noopener noreferrer"><span class="link-card-body"><span class="link-card-title">agora_rtc_engine | Flutter package</span><span class="link-card-description">Flutter plugin of Agora RTC SDK, allow you to simply integrate Agora Video Calling or Live Video Streaming to your app with just a few lines of code.</span><span class="link-card-meta"><img class="link-card-favicon" src="./linkcard-01-favicon.webp" alt=""><span class="link-card-domain">pub.dev</span></span></span><img class="link-card-image" src="./linkcard-01-image.webp" alt=""></a></div>

<div class="link-card-wrap"><a class="link-card" href="https://pub.dev/packages/agora_rtm" target="_blank" rel="noopener noreferrer"><span class="link-card-body"><span class="link-card-title">agora_rtm | Flutter package</span><span class="link-card-description">Flutter wrapper around the Agora Real Time Message SDKs for Android and iOS.</span><span class="link-card-meta"><img class="link-card-favicon" src="./linkcard-02-favicon.webp" alt=""><span class="link-card-domain">pub.dev</span></span></span><img class="link-card-image" src="./linkcard-02-image.webp" alt=""></a></div>

## Codemagicのビルド時にiOSで**Publishing Error**

```shell
Publishing artifact Runner.app.dSYM.zip
Publishing micoly_user_app.ipa to App Store Connect
> app-store-connect publish --path /Users/builder/clone/build/ios/ipa/app.ipa --key-id hogehoge --issuer-id hogehoge --private-key @env:APP_STORE_CONNECT_PUBLISHER_PRIVATE_KEY

Publish "/Users/builder/clone/build/ios/ipa/app.ipa" to App Store Connect
App name: App
Bundle identifier: com.app
Certificate expires: 2024-10-10T01:13:13.000+0000
Distribution type: App Store
Min os version: 14.0
Provisioned devices: N/A
Provisions all devices: No
Supported platforms: iPhoneOS
Version code: 10
Version: 1.0.10

Upload "/Users/builder/clone/build/ios/ipa/app.ipa" to App Store Connect
Running altool at path '/Applications/Xcode-16.0.app/Contents/SharedFrameworks/ContentDeliveryServices.framework/Frameworks/AppStoreService.framework/Support/altool'...
Running altool at path '/Applications/Xcode-16.0.app/Contents/SharedFrameworks/ContentDeliveryServices.framework/Frameworks/AppStoreService.framework/Support/altool'...
2024-10-21 07:32:06.525 *** Error: [ContentDelivery.Uploader.0000] Asset validation failed (90482) Invalid Executable. The executable 'Runner.app/Frameworks/AgoraRtmKit.framework/AgoraRtmKit' contains bitcode. (ID: 00000)
2024-10-21 07:32:06.681 [ContentDelivery.Uploader.0000] 
=============
UPLOAD FAILED with 1 error.
=============
{"tool-version":"8.003.16003","tool-path":"\\/Applications\\/Xcode-16.0.app\\/Contents\\/SharedFrameworks\\/ContentDeliveryServices.framework\\/Versions\\/A\\/Frameworks\\/AppStoreService.framework","os-version":"14.7.0","product-errors":[{"message":"Asset validation failed","userInfo":{"NSUnderlyingError":"Error Domain=IrisAPI Code=-19241 \\"Asset validation failed\\" UserInfo={status=409, detail=Invalid Executable. The executable 'Runner.app\\/Frameworks\\/AgoraRtmKit.framework\\/AgoraRtmKit' contains bitcode., id=0000, code=STATE_ERROR.VALIDATION_ERROR.90482, title=Asset validation failed, NSLocalizedFailureReason=Invalid Executable. The executable 'Runner.app\\/Frameworks\\/AgoraRtmKit.framework\\/AgoraRtmKit' contains bitcode., NSLocalizedDescription=Asset validation failed}","NSLocalizedDescription":"Asset validation failed","iris-code":"STATE_ERROR.VALIDATION_ERROR.90482","NSLocalizedFailureReason":"Invalid Executable. The executable 'Runner.app\\/Frameworks\\/AgoraRtmKit.framework\\/AgoraRtmKit' contains bitcode. (ID: 0000)"},"code":90482}]}

Failed to upload archive at "/Users/builder/clone/build/ios/ipa/micoly_user_app.ipa"
Failed to publish /Users/builder/clone/build/ios/ipa/app.ipa

Failed to publish app.ipa to App Store Connect.

Publishing app-release.aab to Google Play
Published app-release.aab to track production
> google-play tracks get --track production --package-name com.app
Track: production
Releases: [
	Status: completed
	Name: 1.0.10
	Version codes: [
		517
	]
]

Build failed :|

Publishing failed :|
Failed to publish app.ipa to App Store Connect.
```

エラーの内容を確認すると、iOSアプリのビルド自体は成功していますが、アップロード時にApp Store Connectの検証に失敗していました。

具体的には、AgoraRtmKit.frameworkがBitcodeを含んでいることが原因で、以下のエラーメッセージが表示されています。

```shell
Asset validation failed (90482) Invalid Executable. The executable 'Runner.app/Frameworks/AgoraRtmKit.framework/AgoraRtmKit' contains bitcode.
```

## AgoraRtmKit contains bitcode エラーの解決方法3つ

BitcodeはiOSアプリにコンパイルされた中間コードで、App Store Connectにアップロードする際にBitcodeを含めない設定が必要みたいです。

具体的な解決策として以下3つがあるようです。（解決した人もいるし、解決していない人もいて曖昧）

1.  Bitcodeを無効化する
2.  Agora SDKのBitcodeを含まないバージョンの使用
3.  Podのインストール後にフレームワークのBitcodeを削除する処理を自動化

とりあえず、試していきましょう。

### 1\. Bitcodeを無効化する

以下の参考記事にもある通り、Bitcodeの設定をNOにすることで解決できるようです。

<div class="link-card-wrap"><a class="link-card" href="https://github.com/AgoraIO-Extensions/Agora-Flutter-SDK/issues/497" target="_blank" rel="noopener noreferrer"><span class="link-card-body"><span class="link-card-title">Agora is working fine on android but not building my app in ios · Issue #497 · AgoraIO-Extensions/Agora-Flutter-SDK</span><span class="link-card-description">While I am trying to run my flutter app on an ios simulator or a real device it shows an error Launching lib/main.dart on iPhone 13 in debug mode... Running Xcode build... └─Compiling, linking and ...</span><span class="link-card-meta"><img class="link-card-favicon" src="./linkcard-03-favicon.svg" alt=""><span class="link-card-domain">github.com</span></span></span><img class="link-card-image" src="./linkcard-03-image.webp" alt=""></a></div>

```shell
post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      ...省略
      config.build_settings['ONLY_ACTIVE_ARCH'] = 'YES'
      config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "i386 arm64"
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
  installer.pods_project.build_configurations.each do |config|
    config.build_settings['ENABLE_BITCODE'] = 'NO'
  end
end
```

僕の場合は、すでにXcode上でBitcodeはNOに設定済みで、GithubのissueにあるPodsの修正も対応済みですが、ビルドに失敗しているので、上記のコードを追加で対応して、明確に`ENABLE_BITCODE`を`NO`としました。

しかし、エラーは解決しなかったです。

### 2\. Agora SDKのBitcodeを含まないバージョンの使用

パッケージの変更履歴を見る限り、そもそも根本的に改善はされていないみたいです。

<div class="link-card-wrap"><a class="link-card" href="https://pub.dev/packages/agora_rtc_engine" target="_blank" rel="noopener noreferrer"><span class="link-card-body"><span class="link-card-title">agora_rtc_engine | Flutter package</span><span class="link-card-description">Flutter plugin of Agora RTC SDK, allow you to simply integrate Agora Video Calling or Live Video Streaming to your app with just a few lines of code.</span><span class="link-card-meta"><img class="link-card-favicon" src="./linkcard-04-favicon.webp" alt=""><span class="link-card-domain">pub.dev</span></span></span><img class="link-card-image" src="./linkcard-04-image.webp" alt=""></a></div>

<div class="link-card-wrap"><a class="link-card" href="https://pub.dev/packages/agora_rtm" target="_blank" rel="noopener noreferrer"><span class="link-card-body"><span class="link-card-title">agora_rtm | Flutter package</span><span class="link-card-description">Flutter wrapper around the Agora Real Time Message SDKs for Android and iOS.</span><span class="link-card-meta"><img class="link-card-favicon" src="./linkcard-05-favicon.webp" alt=""><span class="link-card-domain">pub.dev</span></span></span><img class="link-card-image" src="./linkcard-05-image.webp" alt=""></a></div>

### 3\. Podのインストール後にフレームワークのBitcodeを削除する処理を自動化

Podファイルに以下コードを追加します。

今回は、2つの`Agora`パッケージ（`agora_rtc_engine`と`agora_rtm`）を使用しているので、それぞれに含まれる`Framework`のビットコードを削除する必要があります。

よって、`Podfile`で対応する`framework_paths`には、両方のSDKを含めましょう。

```shell
post_install do |installer|
  ...省略

  bitcode_strip_path = `xcrun --find bitcode_strip`.chop!

  def strip_bitcode_from_framework(bitcode_strip_path, framework_relative_path)
    framework_path = File.join(Dir.pwd, framework_relative_path)
    command = "#{bitcode_strip_path} #{framework_path} -r -o #{framework_path}"
    puts "Stripping bitcode: #{command}"
    system(command)
  end

  framework_paths = [
    # Agora SDKのフレームワークパスを指定（Podsディレクトリ確認してパスをコピーすればOK）
    "Pods/AgoraRtcEngine_iOS/AgoraRtcKit.xcframework/ios-arm64_armv7/AgoraRtcKit.framework/AgoraRtcKit",
    "Pods/AgoraRtm_iOS/AgoraRtmKit.xcframework/ios-arm64_armv7/AgoraRtmKit.framework/AgoraRtmKit"
  ]

  framework_paths.each do |framework_relative_path|
    strip_bitcode_from_framework(bitcode_strip_path, framework_relative_path)
  end
end
```

僕はこちらの対応をすることで、エラーは解消されて、Xcode上でビルド・アーカイブ・バリデーション（検証）まで合格することができました！

## Bitcodeを削除することに問題はない

ビットコードを手動で削除する影響で、以下理由から技術的にはアプリの動作に影響を与えないケースが多いです。

-   ビットコードは、AppleがApp Store上で将来的にアプリを再最適化できるようにするための中間バイトコードで、アプリの実行には影響を与えないため、ビットコードを削除しても通常は問題なく動作する
-   Appleはビットコードを含まないバイナリも受け入れているため、削除してアップロードすることに問題はない
-   今後のSDKアップデート時に再度同じ対応が必要になる場合がある

## 参考記事

-   [https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes](https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes)
-   [https://qiita.com/pugiemonn/items/dd7c88205b72b3bcdb5a](https://qiita.com/pugiemonn/items/dd7c88205b72b3bcdb5a)
-   [https://note.com/resan0725/n/n49c2f5ce67e6](https://note.com/resan0725/n/n49c2f5ce67e6)
-   [https://stackoverflow.com/questions/79045739/error-during-app-distribution-asset-validation-failed-due-to-bitcode-in-agora-f](https://stackoverflow.com/questions/79045739/error-during-app-distribution-asset-validation-failed-due-to-bitcode-in-agora-f)
-   [https://www.linkedin.com/posts/abdallah-mohamed-🇵🇸-0b4270183\_flutter-bitcodeabrproblem-activity-7253361610935681027-9LaP?utm\_source=share&utm\_medium=member\_desktop](https://www.linkedin.com/posts/abdallah-mohamed-🇵🇸-0b4270183_flutter-bitcodeabrproblem-activity-7253361610935681027-9LaP?utm_source=share&utm_medium=member_desktop)
