Jetpack 迁移到 androidX support MD
| Markdown版本笔记 | 我的GitHub首页 | 我的博客 | 我的微信 | 我的邮箱 |
|---|---|---|---|---|
| MyAndroidBlogs | baiqiantao | baiqiantao | bqt20094 | baiqiantao@sina.com |
目录
AndroidX
AndroidX 的变化
常用依赖库对比
常用支持库类对比
官方文档介绍
迁移到 AndroidX
后续问题处理
手动修改错误包名
修复DataBinding中的重名id错误
去除 attr.xml 中重复的属性名称
Glide中的注解不兼容androidX
规范包名
修改未自动迁移的三方库
莫名问题的解决
AndroidX
官方文档
所有 AndroidX 引用库
API文档
androidx-class-mapping.csv
androidx-artifact-mapping.csv
Google 2018 IO 大会推出了扩展库 AndroidX,AndroidX 是对 android.support.xxx 包的整理后产物。由于之前的support包过于混乱,所以,google推出了 androidX 用于替换support包。
其只是将原来的android.*替换成androidx.*,只有包名和Maven工件名受到影响,原来的类名、方法名和字段名不会更改。
由于在后续版本中,会逐步放弃对 support 的升级和维护,所以,我们必须尽快迁移到 androidX。
Jetpack components are part of the AndroidX library. Learn more about components on the Jetpack home page.
AndroidX 的变化
常用依赖库对比
详细变化内容,可以下载CSV格式映射文件:androidx-class-mapping.csv
| Old build artifact | AndroidX build artifact |
|---|---|
com.android.support:appcompat-v7:28.0.2 |
androidx.appcompat:appcompat:1.0.0 |
com.android.support:design:28.0.2 |
com.google.android.material:material:1.0.0 |
com.android.support:support-v4:28.0.2 |
androidx.legacy:legacy-support-v4:1.0.0 |
com.android.support:recyclerview-v7:28.0.2 |
androidx.recyclerview:recyclerview:1.0.0 |
com.android.support.constraint:constraint-layout:1.1.2 |
androidx.constraintlayout:constraintlayout:1.1.2 |
常用支持库类对比
详细变化内容,可以下载CSV格式映射文件:androidx-artifact-mapping.csv
| Support Library class | AndroidX class |
|---|---|
android.support.v4.app.Fragment |
androidx.fragment.app.Fragment |
android.support.v4.app.FragmentActivity |
androidx.fragment.app.FragmentActivity |
android.support.v7.app.AppCompatActivity |
androidx.appcompat.app.AppCompatActivity |
android.support.v7.app.ActionBar |
androidx.appcompat.app.ActionBar |
android.support.v7.widget.RecyclerView |
androidx.recyclerview.widget.RecyclerView |
官方文档介绍
AndroidX is the open-source project that the Android team uses to develop, test, package, version and release libraries within Jetpack.
AndroidX是Android团队用于在Jetpack中开发,测试,打包,发布和发布库的开源项目。
AndroidX is a major improvement to the original Android Support Library. Like the Support Library, AndroidX ships separately from the Android OS and provides backwards-compatibility across Android releases. AndroidX fully replaces the Support Library by providing feature parity and new libraries. In addition AndroidX includes the following features:
AndroidX是对原始Android支持库的重大改进。与支持库一样,AndroidX与Android操作系统分开提供,并提供跨Android版本的向后兼容性。 AndroidX通过提供功能奇偶校验和新库完全取代了支持库。此外,AndroidX还包括以下功能:
All packages in AndroidX live in a consistent namespace starting with the string
androidx. The Support Library packages have been mapped into correspondingandroidx.*packages. For a full mapping of all the old classes and build artifacts to the new ones, see the Package Refactoring page.AndroidX中的所有软件包都以字符串androidx开头,位于一致的命名空间中。支持库包已映射到相应的androidx。*包。有关所有旧类和构建工件的完整映射到新构件,请参阅“包重构”页面。
Unlike the Support Library, AndroidX packages are separately maintained and updated. The
androidxpackages use strict Semantic Versioning starting with version 1.0.0. You can update AndroidX libraries in your project independently.与支持库不同,AndroidX软件包是单独维护和更新的。 androidx软件包使用严格的语义版本控制,从版本1.0.0开始。您可以单独更新项目中的AndroidX库。
All new Support Library development will occur in the AndroidX library. This includes maintenance of the original Support Library artifacts and introduction of new Jetpack components.
所有新的支持库开发都将在AndroidX库中进行。这包括维护原始支持库工件和引入新的Jetpack组件。
If you want to use AndroidX in a new project, you need to set the compile SDK to Android 9.0 (API level 28) or higher and set both of the following Android Gradle plugin flags to true in your gradle.properties file.
android.useAndroidX: When set totrue, the Android plugin uses the appropriate AndroidX library instead of a Support Library. The flag isfalseby default if it is not specified.android.enableJetifier: When set totrue, the Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries. The flag isfalseby default if it is not specified.
迁移到 AndroidX
1、修改 gradle.properties
android.useAndroidX=true
android.enableJetifier=true
其中:
android.useAndroidX=true表示当前项目启用 androidxandroid.enableJetifier=true表示将依赖包也迁移到androidx。如果取值为false,表示不迁移依赖包到androidx,但在使用依赖包中的内容时可能会出现问题,当然了,如果你的项目中没有使用任何三方依赖,那么,此项可以设置为false
2、将AS更新至 AS 3.2 及以上
将 Gradle 插件版本改为 4.6 及以上
将 compileSdkVersion、buildToolsVersion 版本改为 28.0.2及以上
3、在AndroidStudio 3.2 或更高版本中执行如下操作:
Refactor > Migrate to AndroidX
如果你的项目 compileSdkVersion 低于28,点击Migrate to AndroidX...会提示:
You need to have at least have compileSdk 28 set in your module
build.gradleto refactor to androidx
在执行该操作时会提醒我们是否将当前项目打包备份。如果你提前已经做好了备份,可以忽略;如果没有备份,则先备份。
后续问题处理
参考文章
Android Support 库和 AndroidX 冲突问题
手动修改错误包名
由于 Migrate to AndroidX 执行之后,部分控件的包名/路径名转换的有问题,所以还需要我们手动调整(包括修改xml布局文件和.java/.kt文件)。
如:ViewPager、RecyclerView 等,这些内容在迁移完成之后,包名是 androidx.core.weight.xxxx,这是一个错误的包名,我们必须手动修改,否则,无法正常编译。点击绿色 Run(运行) 按钮时会详细报出哪里有错误。
注意,在 AndroidStudio 的 build 选项卡中一次最多只会报 50条错误!所以,可能在你修完第一批之后,后面还有N个50。此处要保持一个平静的
Jetpack 迁移到 androidX support MD的更多相关文章
- Android 支持库迁移到AndroidX
一.背景 Android系统版本在不断更新,从最初的Android 1.0到现在Google和各大手机厂商正在推的Android 10,平均下来每个年头都有一个大的版本更新.但用户正在用的手机上的An ...
- Jetpack 架构组件 LiveData ViewModel MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- android -------- AndroidX的迁移
Google 2018 IO 大会推出了 Android新的扩展库 AndroidX,用于替换原来的 Android扩展库,将原来的android.*替换成androidx.*:只有包名和Maven工 ...
- Android:你好,androidX!再见,android.support
1.AndroidX简介 点击查看Android文档中对androidx的简介 按照官方文档说明 androidx 是对 android.support.xxx 包的整理后产物.由于之前的suppor ...
- 迁移AndroidX
1. 前言 AndroidX replaces the original support library APIs with packages in the androidx namespace. O ...
- Androidx初尝及其新旧包对照表
x的最低实验条件 AndroidStudio 3.2.0+ gradle:gradle-4.6以上 本次实验条件: AndroidStudio 3.3 (强制要求最低gradle版本为gradle-4 ...
- 再不迁移到Material Design Components 就out啦
翻译自国外文档加自己理解 原文 我们最近宣布了 Material Design Components(MDC)1.1.0 ,这是一个库更新,为您的 Android 应用程序带来了 Material T ...
- Flutter兼容AndroidX
参考官方文档:https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility 第一步 distribu ...
- [android]com.android.support:appcompat-v7:XXX 包导入无法Build
在学习<Android编程权威指南>时,按书中要求添加com.android.support:appcompat的依赖,然后编译不通过,提示如下问题: 大概意思是,Android Pie之 ...
随机推荐
- ELK使用2-Kibana使用
一.创建kibana索引 1.es索引可以在这儿查看 2.kibana创建索引可以在这儿查看(必须es中存在相应的索引才能在kibana中创建) 点击创建然后选择es中存在的索引即可创建相应的索引 3 ...
- 数论算法 剩余系相关 学习笔记 (基础回顾,(ex)CRT,(ex)lucas,(ex)BSGS,原根与指标入门,高次剩余,Miller_Rabin+Pollard_Rho)
注:转载本文须标明出处. 原文链接https://www.cnblogs.com/zhouzhendong/p/Number-theory.html 数论算法 剩余系相关 学习笔记 (基础回顾,(ex ...
- 数据库构架设计中的Shared Everthting、Shared Nothing、和Shared Disk
Shared Everthting:一般是针对单个主机,完全透明共享CPU/MEMORY/IO,并行处理能力是最差的,典型的代表SQLServer Shared Disk:各个处理单元使用自己的私有 ...
- P1052 过河 线性dp 路径压缩
题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数 ...
- 数学建模:2.监督学习--分类分析- KNN最邻近分类算法
1.分类分析 分类(Classification)指的是从数据中选出已经分好类的训练集,在该训练集上运用数据挖掘分类的技术,建立分类模型,对于没有分类的数据进行分类的分析方法. 分类问题的应用场景:分 ...
- Shiro笔记(六)Shiro标签的使用
Shiro标签的使用 引入标签库 <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"% ...
- Qt界面设计基础
一.安装Qt相关基本组件: 在ubuntu上安装,可以直接使用如下的命令来安装: sudo apt-get install ubuntu-sdk 详细的安装方法可以参考这篇文章:https://blo ...
- 基于Keil软件的MCU环境搭建
我们在开发一款新的MCU的时候,偶尔会遇到Keil软件没有对应的Device设备选型,以下,我们以STM32F407VGT6作为实例来演示整个环境的搭建过程: 一.如下所示,我需要选择的是ST公司的S ...
- ESP8266进阶篇
ESP8266进阶篇 20170225(应需要,继续使用此模块!!!) 说一下如何通过内网和外网来控制我的ESP8266的数据模块 1.内网控制:(要求手机直接连接在ESP8266的WIFI上面,使用 ...
- 无法启动 Maya 集成的 qt designer 的解决方法和原因 以及 中英文切换
无法启动 Maya 集成的 qt designer 的解决方法和原因 以及 中英文切换 前言: Maya 集成了 PySide,同时集成了qt designer,在 Maya 的安装目录下的 bin ...