Flutter打包apk报错:Your app isn't using AndroidX.

3,501 阅读1分钟

今天在学习Flutter开发的过程中,写了一个基本的demo,想打个正式的安装包apk,安装在手机上体验一下效果。

配置完了Android的签名文件后,运行Flutter bulid app命令行,构建一个正式(release)包,在构建的过程中出现了如下的提示,但是可以构建成功。

[!] Your app isn't using AndroidX.
    To avoid potential build failures, you can quickly migrate your app by following the steps on https://goo.gl/CP92wY.

在这里插入图片描述
构建成功后的包在Android Studio IDE上是找不到的😀, 需要进入文件目录中找到你的项目,打包好的项目就在:

打包好的APK位于/build/app/outputs/apk/app-release.apk。 但是有这个提示总是不爽的,是吧,想办法解决掉它。

根据提示应该可以看出,当前咱们的的项目没有使用AndroidX, 这个AndroidX是Android系统的极大的提升,所以说也是比较重要的。

AndroidX is a major improvement to the original Android Support Library.
​
It provides the androidx.* package libraries, unbundled from the platform API. This means that it offers backward compatibility and is updated more frequently than the Android platform.

在Flutter官网的说明中也专门提到了AndroidX Migration的迁移问题,通过问答的方式给出了一些对应的解决方案。 对于此项目构建Apk提示问题,只需要添加两行代码即可解决。 在gradle.properties中添加如下代码即可:

android.enableJetifier=true
android.useAndroidX=true

在这里插入图片描述
添加完之后,重新使用命令行:flutter build apk 就可以了,就不会出现上面那个提示了。

提示:

如果你已经在手机上安装了调试版的APP,安装正式版的APP之前要记得把原来debug的APP卸载掉。

欢迎关注我的公众号:君伟说。