android -------- AndroidX的迁移
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android -------- AndroidX的迁移,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2259字,纯文字阅读大概需要4分钟。
内容图文
Google 2018 IO 大会推出了 Android新的扩展库 AndroidX,用于替换原来的 Android扩展库,将原来的android.*
替换成androidx.*
;只有包名和Maven工件名受到影响,原来的类名,方法名和字段名不会更改。接下来我们来看看使用 AndroidX的扩展库需要哪些配置。
1. AndroidX变化
1)常用依赖库对比:
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格式映射文件;
2)常用支持库类对比:
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
|
?更多详细变化内容,可以下载CSV格式映射文件。
2. AndroidX配置
1)更新升级插件
- 将AS更新至 AS 3.2及以上;
- Gradle 插件版本改为 4.6及以上;
项目下gradle/wrapper/gradle-wrapper.propertie
文件中的distributionUrl
改为:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
- compileSdkVersion 版本升级到 28及以上;
- buildToolsVersion 版本改为 28.0.2及以上。
2)开启迁移AndroidX
?在项目的gradle.properties
文件里添加如下配置:
android.useAndroidX=true
android.enableJetifier=true
?表示项目启用 AndroidX 并迁移到 AndroidX。
3)替换依赖库
?修改项目app目录下的build.gradle
依赖库:
implementation ‘com.android.support:appcompat-v7:28.0.2‘ → implementation ‘androidx.appcompat:appcompat:1.0.0‘ implementation ‘com.android.support:design:28.0.2‘ → implementation ‘com.google.android.material:material:1.0.0‘ implementation ‘com.android.support.constraint:constraint-layout:1.1.2‘ → implementation ‘androidx.constraintlayout:constraintlayout:1.1.2‘ ...
4)修改支持库类
?将原来import
的android.**
包删除,重新import
新的androidx.**
包;
public abstract class BaseActivity extends AppCompatActivity {}
导入的包名是:
import androidx.appcompat.app.AppCompatActivity;
参考AndroidX 官方文档,开启传送门
https://developer.android.google.cn/jetpack/androidx/migrate
原文:https://www.cnblogs.com/zhangqie/p/11321917.html
内容总结
以上是互联网集市为您收集整理的android -------- AndroidX的迁移全部内容,希望文章能够帮你解决android -------- AndroidX的迁移所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。