今天,我们发布一个新的Android扩展库(AndroidX)的早期预览版,这表示了支持库的一个新的时代。请为这些变化提出你们的反馈。既然这是一个早期的预览版本,我们并不建议放在生产环境尝试这些功能,因为它还存在一些已知的问题。

7年以来,支持库框架提供了向后的兼容。多年以来,支持库已经包含了设备特定的用户体验,调试,测试和其他工具类。支持库的普及是非常惊人的;今天大多数app都采用了支持库。我们想要加大在这一领域的投入,打下一个坚实的基础是具有决定性意义的。

我们很想和你们谈一谈。我们收到了一致的意见:支持库的已经变得令人困惑和混乱。我们“v7”的包和组件,最低支持的sdk级别是14。我们想要理清楚不同平台相关联的api之间的界限。

出于上述的考虑,say“Hello World”to“AndroidX”。如先前在Android KTX announcement提到的,我们在这个包里面添加了一些新的功能,并且更新了一些已有的功能。

android. VS androidx.* namespaces

编写android apps 需要依赖两种类:

* 一种类似于PackageManager,这个是和操作系统相关联的,可以提供不同的api,为不同的android版本提供不同的表现。

* 一种类似于AppCompatActivity或者ViewModel,这个是和操作系统没有关联的,打包进你的apk,这些库提供了单一的api,尽可能地为不同版本的android提供一致的表现。

很多时候,非捆绑式的库是更好地选择,因为这位不同的android版本提供相同的api。这个重构把非捆绑式的库-包含所有的支持库和架构组件转移到AndroidX包里,让所依赖的内容更加清楚。

Revised naming for packages and Maven artifacts

我们重新设计了包架构,鼓励更小,更聚焦的库,减小在没有使用Proguard和Multidex的测试的压力。Maven groupIds和artifactIds已经做了更新,更好的反映库的内容,我们为不同的类,groupId,maven artifact创建相同的包的前缀。

通常,你可以从老的包直接看出和新包映射关系。

old

android.support.**

android.databinding.**

android.design.**

android.support.test.**

New

androidx.@

androidx.databinding.@

com.google.android.material.@

(in a future release)androidx.text.@

架构组件库也转移到了androidx包下面,他们的包名也简化了,可以直接反映他们集成的核心库。示例如下:

Old

android.arch.**

android.arch.persistence.rom.**

android.arch.persistence.**

New

androidx.@

androidx.room.@

androidx.sqlite.@

点击AndroidX refactoring map查看完整的 28.0.0-alpha1(android.support)和1.0.0-alpha1(androidx)的对应关系。请注意,在alpha阶段,还只有较少的映射关系地修改。

Per-artifact strict semantic versioning

Starting with the AndroidX refactor, library versions have been reset from 28.0.0 to 1.0.0. Future updates will be versioned on a per-library basis, following strict semantic versioning rules where the major version indicates binary compatibility. This means, for example, that a feature may be added to RecyclerView and used in your app without requiring an update to every other library used by your app. This also means that libraries depending on androidx may provide reasonable guarantees about binary compatibility with future releases of AndroidX -- that a dependency on a 1.5.0 revision will still work when run against 1.7.0 but will likely not work against 2.0.

Migration from 28.0.0-alpha1

迁移你的app从android.support到androidx-包依赖包含两个主要的部分:

源代码重构和依赖翻译。如图

源码重构会更新你的java代码,xml资源,gradle配置引用新的类和Maven artifacts。这个功能可以在[Android Studio Canary 14](https://developer.android.com/studio/preview/)中使用,并且app的target api 需要是Android P。

如果你的依赖的库引用了旧的Support library,Android Studio将会更新该库的引用androidx,而不是通过dependency translation。Dependency translation 在Android Gradle Plugin 3.2.0-aplha14中被自动应用,它会重写字节码和jar资源,aar依赖(还有传递性依赖)去引用新的androidx-包类和artifacts。我们也会提供单独的翻译工具作为jar。

What's next?

We understand this is a big change for existing projects and codebases. Our intention is to provide a strong foundation that sets Android library projects up for more sustainable growth, better modularity, and smaller code size.

We hope that these changes also make it easier for developers to discover features and implement high-quality apps in less time; however, we understand that migration takes time and may not fit into everyone's production schedule. For this reason, we will continue to provide parallel updates to an android.support-packaged set of libraries for the duration of the P preview SDK timeframe. These updates will continue the 28.0.0 versioning scheme that began with 28.0.0-alpha1 in March 2018, and they will continue to be source-compatible with existing projects that depend on the android.support package.

28.0.0的稳定版本将作为android.support的最后版本,后续所有新的功能都只会被加入androidx-packaged artifacts。

We'd love to hear from you as we iterate on this exciting future. Send us feedback by posting comments below, and please file any bugs you run into on AOSP.

We look forward to a new era of Android libraries!

androidx和android的区别,【译】使用AndroidX代替Android支持库相关推荐

  1. ios android 上架区别,浅谈iOS与Android的区别

    说在前面:从事UI设计的同行们关于iOS与Android的基本设计规范相信大家都已经非常了解了,以下是我针对这两种设计规范所作的一点点小总结,如果面试官问道此类问题,希望对你们有用!!! 首先设计语言 ...

  2. Android支持库

    # 支持库 支持库命名规范 引入支持库时的命名规范为:"group:name:version" 例如: implementation 'com.android.support:ap ...

  3. 【Xamarin.Android】掌握android支持库

    Android支持库是每个Android应用程序中必不可少的一部分,你会发现它们无处不在.支持库为开发人员提供了将Android的最新和最强大功能添加到应用程序的能力,同时保持与旧版本Android的 ...

  4. android support library v21,升级到支持库v21后,PreferenceActivity中没有ActionBar

    请在以下位置找到GitHub Repo: 与您自己的代码非常相似,但添加了xml以允许设置标题: 继续使用PreferenceActivity: settings_toolbar.xml : xmln ...

  5. androidx和android的区别,Android X 详解

    什么是Android X AndroidX 是 Android 团队用于在 Jetpack 中开发.测试.打包和发布库以及对其进行版本控制的开源项目. AndroidX 对原始 Android 支持库 ...

  6. Android Studio3.5及使用AndroidX的一些坑

    google的更新优化往往会牵动一大批开发者的心.去年的androidx,到今年studio3.5后都默认使用androidx了.其实对于我们开发者而言,我们都只是调用他的api,对我们的影响不大?? ...

  7. 谷歌使用AndroidX代替Android支持库

    \ 看新闻很累?看技术新闻更累?试试下载InfoQ手机客户端,每天上下班路上听新闻,有趣还有料! \ \\ 新的Android扩展库(AndroidX)取代了使用七年之久的Android支持库,旨在简 ...

  8. Android Studio项目中使用 AndroidX支持库的相关配置说明

    1. 在项目的 gradle.properties 文件中配置如下: # 启用Androidx生成支持的标志 android.useAndroidX=true # 启用Maven库转换的标志 andr ...

  9. Android解决This project uses AndroidX dependencies---The following AndroidX dependencies are detected.

    开始报错: This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled ...

最新文章

  1. python 字典操作 内存占用,python - 如何强行释放字典使用的内存? - SO中文参考 - www.soinside.com...
  2. Cocos Creator 键盘监听事件
  3. 啊!你的服务又挂了?
  4. mysql 在大型应用中的架构演变
  5. bytecode java_Java 字节码解读
  6. NYOJ 2 括号配对问题
  7. String、StringBuilder、StringBuffer的区别
  8. 牛的旅行(信息学奥赛一本通-T1343)
  9. bzoj 5302: [Haoi2018]奇怪的背包
  10. ## CSP 201509-2 日期计算(C语言)(100分)
  11. PHP学习笔记--array_map函数
  12. 犀牛书学习笔记(3):函数
  13. 重构Webpack系列之三 ----出口(output)
  14. 基恩士PLC实例笔记①--立项及编程
  15. sht21 c语言程序,SHT20,SHT21程序代码.pdf
  16. 读DL论文心得之RCNN
  17. 如何快速求一个数的所有因子数 c/c++
  18. 香港服务器怎么加速?
  19. 史上最简单的Linux内核IIO子系统入门demo_内核版本4.4.194
  20. 通过小型机液晶面板查看FSP/ASMI IP地址

热门文章

  1. 读取csv数据存到list,批量写入mysql
  2. 身份证号码的正则表达式及验证详解(JavaScript,Regex)
  3. iOS核心动画高级技术(十三) 高效绘图
  4. Logparser 分析 Exchange 日志文件
  5. 【双11背后的技术】集团AliDocker化双11总结
  6. HDU1576 A/B (解法二)【试探法】
  7. 大数据时代的网络视频营销
  8. 关于“Ambiguous match found”
  9. GroupingComparator分组
  10. 机器学习基础专题:分类