flutter 升级androidX的坑记录

编程知识 更新时间:2023-05-01 23:51:36

最近使用flutter 做了一些简单的东西在练手,因为导入了一个库,爆出了:

Manifest merger failed :‘tools:replace=“android:appComponentFactory”’ to element at AndroidManifest.xml(具体错误在下面)
或者是这个错误
[!] 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.

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:36:5-364:19 to override.

其实就是项目导入的库使用了androidx,androidx和supper冲突了,一般情况的话,按照谷歌的文档就能搞定。但是android studio却弹出No Usages Found in the Project这个提示。看来自动搞不定了,手动搞一下吧。

首先在android的src目录下的build.gradle添加androidx的依赖(你也可以使用as新建支持androidx的新项目,使用新的版本)

   implementation 'androidx.appcompat:appcompat:1.1.0'
   implementation 'androidx.core:core-ktx:1.1.0'
   androidTestImplementation 'androidx.test.ext:junit:1.1.0'
   androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

然后在android目录下的gradle.properties文件下添加

android.enableJetifier=true
android.useAndroidX=true

第三步,点击Tools ->Flutter->Flutter Clean。然后跑一下项目应该是可以跑起来了。

但是我的项目之前是用dio网络框架。又报出了这个错误
Observatory server failed to start after 1 tries
[ERROR:flutter/lib/ui/ui_dart_state(148)] Unhandled Exception: DioError [DioErrorType.DEFAULT]: SocketException: Failed host

 [ERROR:flutter/lib/ui/ui_dart_state(148)] Unhandled Exception: DioError [DioErrorType.DEFAULT]: SocketException: Failed host 

这种情况在AndroidManifest申请权限网络就好了

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

有一点疑惑,为啥之前网络权限没在AndroidManifest申请,可以能访问网络。现在升级到adnroidx,就不行了。

更多推荐

flutter 升级androidX的坑记录

本文发布于:2023-04-24 15:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/ecefff3508ead51a607156847a1a0049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:flutter   androidX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 100911文章数
  • 26077阅读数
  • 0评论数