Flutter

【Flutter】Android 12のアプリリリース時にエラーとなった場合の対処法

記事内に商品プロモーションを含む場合があります

Flutterで作成しているAndroidアプリをGoogle play consoleからリリースしようとしたところ、aabファイルをアップロードしたタイミングでconsole上に「android:exportedの設定がされていない」というエラーが発生し、リリースができないという問題に遭遇しました。(2022年1月15日ごろ確認)

Android 12(compileSdkVersion 31)に設定する場合に、android:exportedの設定を必ずしないといけなくなったようです。

以下にandroid:exportedを設定する方法を記載します。

aabファイルアップロード時にエラー発生

Flutterで作成したアプリをGoogle play console上にアップロードした際、以下のようなエラーが発生しリリースすることができませんでした。

If an activity, service, or broadcast receiver uses intent filters and doesn’t have an explicitly-declared value for android:exported, your app can’t be installed on a device that runs Android 12 or higher.

普段引っかかるようなところではなかったので驚きましたが、意訳すると以下のような感じです。

「Android 12以上の端末では、インテントフィルタを使用する場合android:exportedを宣言していないアプリをインストールできません。」

Android 12未満の人は使えるなら、エラーにしなくてもいいじゃないかと思いつつも、対応しないとリリースさせないよというGoogleの方針に従い対応するしかありません。

AndroidManifest.xmlにandroid:exportedを宣言する

修正方法は非常に簡単です。

以下に配置されている、「AndroidManifest.xml」を修正します。

android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.techgamelife.xxxxx_xxxxx_xxxxx">
   <application
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize"
            android:exported="true"><!-- これを追加! -->
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />

<activity>タグの最後に「android:exported=”true”」を追加します。

後は普段どおりaabファイルをビルドしてアップロードすると、問題なくアップロード/リリースすることができました。

まとめ

Flutterでのアプリ作成/リリースで、意外と大変なことがリリースだということを改めて実感しました。

アプリ作成は書籍や動画などで体系的に学ぶことができますが、リリースは予期せぬエラーや問題に対応しなければいけないため難易度がぐっと上がる印象です。

検索して解決策が見つかれば良いですが、見つからないときはトライアンドエラーを繰り返していかなければいけませんからね・・・

 

○Flutter中級者以上にオススメの参考書

○Flutter初学者にはやはりこの参考書がオススメ