LoginSignup
0
1

More than 1 year has passed since last update.

Your Flutter application is created using an older version of the Android embedding. It's being deprecated in favor of Android embedding v2. のエラーの解決方法

Posted at

環境

-> %  sw_vers
ProductName:    macOS
ProductVersion: 12.0.1
BuildVersion:   21A559

-> % flutter --version
Flutter 2.5.3  channel stable  https://github.com/flutter/flutter.git
Tools  Dart 2.14.4

エラー内容

Flutterのチュートリアルを学習中、下記のエラーが発生しました。


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. Its being deprecated in favor of Android embedding v2. Follow the
steps at

https://flutter.dev/go/android-project-migration

to migrate your project.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This app is using a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, 
try to migrate this app to the V2 embedding.
Take a look at the docs for migrating an app: 

https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects

Android projectが1.12以前なのに、それ以降に作成されたプラグインを利用したい場合は
互換性の観点から、エラーが発生する仕組みのようです。

解決方法

エラー文に記載してくれているURLに飛び、書いてある内容通りに修正すれば解決できます。

MainActivity.java の修正

修正前
package co.appbrewery.clima;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    GeneratedPluginRegistrant.registerWith(this);
  }
}
修正後

package co.appbrewery.dicee;
import io.flutter.embedding.android.FlutterActivity;

public class MainActivity extends FlutterActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  GeneratedPluginRegistrant.registerWith(this);
}
}

MainActivity.kt の修正

私が使用していたプロジェクトにはMainActivity.ktのファイルが存在しなかったので
以下の内容のファイルを作成しました。

FlutterActivity() の{}内はUrlLauncherを使用したかったので記載しています!
(使用しない場合は記載しなくて大丈夫です)

import io.flutter.app.FlutterActivity
import io.flutter.plugins.urllauncher.UrlLauncherPlugin

class MainActivity: FlutterActivity() {
    UrlLauncherPlugin.registerWith(registrarFor("io.flutter.plugins.urllauncher.UrlLauncherPlugin"))
    }
}

AndroidManifest.xmlの修正

AndroidManifest.xml と同名のファイルが複数あるので
android/app/src/main/AndroidManifest.xml のパスであることに注意。

ファイルの一番最後にmeta-data の項目を追加します。

修正前

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="パッケージ名">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:label="dicee"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

修正後
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="パッケージ名">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:label="dicee"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
    <meta-data
    android:name="flutterEmbedding"
    android:value="2" />
</manifest>


以上です。

Flutterはエラー文が丁寧で、じっくり読めばエラーの原因がわかることが多いので、
英語だからと思考停止せず、確認するのが大事ですね。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1