构建 Flutter 应用程序时“由于使用已弃用的 Android v1 嵌入而导致构建失败”

Ali*_*san 74 android flutter

to migrate your project. You may also pass the --ignore-deprecation flag to\nignore this check and continue with the deprecated v1 embedding. However,\nthe v1 Android embedding will be removed in future versions of Flutter.\n\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\nThe detected reason was:\n\n  C:\\Users\\ALI HASSAN\\OneDrive\\Desktop\\New folder\\arcore_app\\example\\android\\app\\src\\main\\AndroidManifest.xml uses\n  `android:name="io.flutter.app.FutterApplication"`\n\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\xe2\x94\x81\n\nBuild failed due to use of deprecated Android v1 embedding.\n
Run Code Online (Sandbox Code Playgroud)\n

Ahm*_*uti 148

您需要更改android\app\src\main\AndroidManifest.xml文件。

从 :

<application
    android:name="io.flutter.app.FlutterApplication"
    ...
Run Code Online (Sandbox Code Playgroud)

到 :

<application
        android:name="${applicationName}"
        ...
Run Code Online (Sandbox Code Playgroud)

如果不存在则添加这三行:

<meta-data
        android:name="flutterEmbedding"
        android:value="2" />
          ...
Run Code Online (Sandbox Code Playgroud)

Flutter 工具使用它来生成 generatedPluginRegistrant.java。

  • 这只是 Full-Flutter 应用程序迁移的第 3 步 https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects#full-flutter-app-migration (4认同)

小智 17

更改 AndroidAndroidManifest.xml 文件

<application
    android:name="io.flutter.app.FlutterApplication"
...
 </application>
Run Code Online (Sandbox Code Playgroud)

android:name="${applicationName}"
Run Code Online (Sandbox Code Playgroud)

还添加了这两行

<meta-data
                android:name="flutterEmbedding"
                android:value="2" />
Run Code Online (Sandbox Code Playgroud)


小智 9

根据您正在执行的操作,您可以选择忽略该错误。

例如,我正在学习一个在线课程,该课程为每节课提供了模板代码。但是,模板代码已经过时,我实际上不需要迁移它才能继续。

--ignore-deprecation在 Android Studio 中,这可以通过将标志添加到“Additional run args:”字段来实现:即

从主菜单中,转到“运行”->“编辑配置”,然后将 --ignore -deprecation 添加到“附加运行参数”字段 忽略弃用


Ale*_*Pad 5

如果您很久以前离开项目并现在返回,则需要更改一些内容,但如果您了解它们,它们就很简单:

清单 更改您之前在此处编写的任何内容:

<application android:name="${applicationName}"
Run Code Online (Sandbox Code Playgroud)

添加<应用程序..

<application android:exported="true"...>
<meta-data
    android:name="flutterEmbedding"
    android:value="2" />..
Run Code Online (Sandbox Code Playgroud)

在Activity的主主题中主要注意正确搭配:

<meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="your theme" />
Run Code Online (Sandbox Code Playgroud)

希望您有kotlin类作为参考,这样您就可以以MainActivity.kt为例:

package com.yourpackage.....
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
 //If you have some native code put it back
}
Run Code Online (Sandbox Code Playgroud)

如果您有Java Activity Main:

package com.yourpackage.....

import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {
// You can keep this empty class or remove it.  
}
Run Code Online (Sandbox Code Playgroud)

还值得更新targetSdkVersioncompileSdkVersion,在我的例子中为:31


小智 5

只需删除 android 平台并重新添加 android 即可。

消除

rm -r android
Run Code Online (Sandbox Code Playgroud)

添加平台

flutter create --platforms=android . 
Run Code Online (Sandbox Code Playgroud)