低版本AndroidStudio项目升级到高版本

itlao6 原创 开发&源码 Android评论851字数 1657阅读5分31秒阅读模式

之前的android个人项目有一年多没有维护了,尽两年的重心也主要是小程序开发及.net,.net core相关开发,android从8以后开发比较少了,主要是维护,而因为电脑一直没换,所以维护也仅仅是解决部分bug,没有做大版本升级...

近一个月来,不管是公司电脑还是个人电脑都换了,然后重新安装了新的as及相关插件,于是,打开旧项目就有很多问题了,最初是原项目gradle版本过低,新装的5.4.1,项目中用到的是3.5.3,编译时老提示最低编译版本为26,然后又是butterknife版本用了10.2.1,然后提示对应build sdk要用28,于是,又有一大堆问题需要去解决。文章源自IT老刘-https://itlao6.com/2495.html

这里记录下Android低版本升级到高版本后的几个问题及解决方案:文章源自IT老刘-https://itlao6.com/2495.html

问题一:butterknife10.2.1与android Api 28.0.0 support-v4/v7库冲突问题

因为太久没搞android,所以这一问题花了些时间去处理,后来出现了androidx替代v4/v7包,于是找到了对应的解决方案:gradle.properties中增加下面两句(其实28新建项目会带有这两句,只是我这是老项目,所以没有,需要手动添加)文章源自IT老刘-https://itlao6.com/2495.html

android.useAndroidX=true
android.enableJetifier = true

然后gradle sync,之前用到v4/v7的地方会报错,这里我也暂时没啥好方法,只有一个个改,能想到的简单点的操作有两点:1.使用ctrl+R替换,2.用alt+enter自动添加import;这里需要注意的是不仅仅是类中需要改,布局文件中,AndroidManifest.xml中也可能要改。文章源自IT老刘-https://itlao6.com/2495.html

ps: 后来发现这里有比较轻松的解决方法,在gradle和build sdk切换为高版本后使用Migrate to Androidx自动替换v4/v7位androidx,  https://www.jianshu.com/p/f7a7a8765294文章源自IT老刘-https://itlao6.com/2495.html

问题二:butterknife的@Bind(R.id.xxx)找不到

用@BindView(R.id.xxx)替换,全局替换下即可文章源自IT老刘-https://itlao6.com/2495.html

问题三:java.lang.BootstrapMethodError: Exception from call site #0 bootstrap method问题

这里需要在build.gradle的android节点下增加文章源自IT老刘-https://itlao6.com/2495.html

compileOptions{
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

以及,Refactor菜单,点击Migrate to Androidx...文章源自IT老刘-https://itlao6.com/2495.html

问题四:Flag android.useDeprecatedNdk is no longer supported and will be removed in the next...

这里去掉gradle.properties中的android.useDeprecatedNdk=true,换成在build.gradle中使用cmake即可文章源自IT老刘-https://itlao6.com/2495.html

问题五:butterknife.bind()后,控件对象还是null

在gradle中应用butterknife,应该以下两句都有文章源自IT老刘-https://itlao6.com/2495.html

implementation 'com.jakewharton:butterknife:10.2.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'

问题六:Glide的crossfade没有该方法

使用  .transition(withCrossFade()) 替代 .crossFade()文章源自IT老刘-https://itlao6.com/2495.html

 文章源自IT老刘-https://itlao6.com/2495.html

文章源自IT老刘-https://itlao6.com/2495.html

其实还有很多其他问题,只是这几个问题是刚解决的,还留有一些记忆,就先记录下来,后续再汇总其他问题文章源自IT老刘-https://itlao6.com/2495.html

个人博客: IT老五    简书:ThinkinLiu文章源自IT老刘-https://itlao6.com/2495.html

文章源自IT老刘-https://itlao6.com/2495.html

源创不易,允许转载,来源误删,多谢合作
低版本AndroidStudio项目升级到高版本
IT老五(it-lao5):关注公众号,一起源创,一起学习!
文章源自IT老刘-https://itlao6.com/2495.html文章源自IT老刘-https://itlao6.com/2495.html
继续阅读
weinxin
我的微信公众号
微信扫一扫关注公众号,不定时更新
itlao6
  • 本文由 发表于 2020年 5月 23日 23:59:57
  • 转载请务必保留本文链接:https://itlao6.com/2495.html
评论  0  访客  0
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定