ARouter icon indicating copy to clipboard operation
ARouter copied to clipboard

一个笨方法兼容androidx的方式

Open wufuqi123 opened this issue 3 years ago • 13 comments

  1. 把ARouter源码下载下来。(我目前使用 1.4版本)进行依赖到项目中 image

wufuqi123 avatar Jul 05 '21 09:07 wufuqi123

  1. 替换 v4、v7包。替换成androidx (support包主要在arouter-api中)

替换掉build.gradle下面的依赖
image

image

image

替换成 androidx image

image

wufuqi123 avatar Jul 05 '21 09:07 wufuqi123

image 替换成 androidx image

wufuqi123 avatar Jul 05 '21 09:07 wufuqi123

arouter-compiler下的Consts.java

image 替换成 androidx image

wufuqi123 avatar Jul 05 '21 10:07 wufuqi123

arouter-api build.gradle

配置: image

wufuqi123 avatar Jul 05 '21 10:07 wufuqi123

arouter-annotation build.gradle

配置: image

wufuqi123 avatar Jul 05 '21 10:07 wufuqi123

arouter-compiler build.gradle

配置: image

wufuqi123 avatar Jul 05 '21 10:07 wufuqi123

首先我声明一点 在导入“annotationProcessor”时,不能只写 “project(':arouter-compiler')” image 必须要这样写。我也不知道问什么。只知道这样写可以运行。

求知道原理的大佬在下面进行留言。

目前我用的 1.4.1版本的路由 所以compiler版本为:1.2.0.(官方源码里对应的版本)

wufuqi123 avatar Jul 05 '21 10:07 wufuqi123

使用时: image

annotationProcessor project(':arouter-compiler')
annotationProcessor 'com.alibaba:arouter-compiler:1.2.0'
api project(':arouter-annotation')

wufuqi123 avatar Jul 05 '21 10:07 wufuqi123

目前 测试 androidx 通过运行。 image image

wufuqi123 avatar Jul 05 '21 10:07 wufuqi123

image image

wufuqi123 avatar Jul 05 '21 10:07 wufuqi123

再次声明

我不清楚 为什么必须要写2个注册。 image

求知道原理的大佬在下面进行留言。

wufuqi123 avatar Jul 05 '21 10:07 wufuqi123

gradle.properties里加这两行就得了

android.useAndroidX=true

Automatically convert third-party libraries to use AndroidX

android.enableJetifier=true

ld2006203 avatar Feb 17 '22 10:02 ld2006203

有才啊

hsy1992 avatar Sep 28 '22 01:09 hsy1992