support项目转成androidx

前言

第一步

调整到28及以上
compileSdkVersion 28

第二步

Refactor—Migrate to AndroidX
在这里插入图片描述
在这里插入图片描述
新版会自动在gradle.properties文件内加入
android.enableJetifier=true
android.useAndroidX=true
如果的该文件下没有自动加入上面的配置,则手动加进去即可。

第三步(非必须)

如果遇到了问题 比如:

The given artifact contains a string literal with a package reference 'android.support.v4.content' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.

在这里插入图片描述
原因:可能是代码太老,引入的第三方库也是老版本,建议更新到最新版即可:
我这里是
implementation ‘com.jakewharton:butterknife:8.8.1’
annotationProcessor ‘com.jakewharton:butterknife-compiler:8.8.1’

更新为
implementation ‘com.jakewharton:butterknife:10.2.1’
annotationProcessor ‘com.jakewharton:butterknife-compiler:10.2.1’
多说一句:如果还需要引进kotlin支持,那么把annotationProcessor改成kapt(kotlin注解工具,替换掉java的注解工具,当然也是兼容java注解的)

如果遇到了问题 比如:
Error: Static interface methods are only supported starting with Android N (–min-api 24): void butterknife.Unbinder.lambda$static$0()
解决方案:在app(主module)的build.gradle文件的android{}里面指定JDK版本,新的项目大多都已经配置,但是老项目就难说了

android {
    ......
    //指定jdk版本
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
完工

如果还遇到问题,欢迎留言。写的不对的地方也请指教

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Alex_ChuTT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值