Android Studio项目适配AndroidX(Android 9.0)的方法步骤
说在前面:
老项目、大项目适配AndroidX注意了,一定要谨慎、谨慎、再谨慎。项目中用到的第三方库多的话会很麻烦,有些第三方库还没有适配AndroidX。
适配AndroidX的两种情况:一种是老项目适配AndroidX,另外一种是新项目要求适配Android9.0
硬核要求
Androidstudio版本升级到3.2.0以上的版本,
distributionUrl的版本升级为4.10.1以上
targetSdkVersion28
gradle插件的版本升级为3.2.0以上
classpath'com.android.tools.build:gradle:3.2.0'
这里以AS3.4为例
compileSdkVersion28
defaultConfig{
applicationId"gangqing.pu.xmxidaq"
minSdkVersion19
targetSdkVersion28
versionCode1
versionName"1.0"
testInstrumentationRunner"androidx.test.runner.AndroidJUnitRunner"
}
第二步:
//Top-levelbuildfilewhereyoucanaddconfigurationoptionscommontoallsub-projects/modules.
buildscript{
repositories{
google()
jcenter()
}
dependencies{
classpath'com.android.tools.build:gradle:3.4.0'
classpath'com.jakewharton:butterknife-gradle-plugin:10.1.0'
//NOTE:Donotplaceyourapplicationdependencieshere;theybelong
//intheindividualmodulebuild.gradlefiles
}
}
allprojects{
repositories{
google()
jcenter()
maven{url"https://jitpack.io"}
}
}
taskclean(type:Delete){
deleterootProject.buildDir
}
第三步:
在gradle.properties中加入如下代码,表示支持AndroidX
android.useAndroidX=true android.enableJetifier=true
compileOptions{
sourceCompatibilityJavaVersion.VERSION_1_8
targetCompatibilityJavaVersion.VERSION_1_8
}
第六步:
修改布局,比如:ConstraintLayout
| 变化之前 | AndroidX |
|---|---|
注意:如果是老项目适配AndroidX,没有找到ConstraintLayout的话,那么还需要在
dependencies{
implementation'androidx.constraintlayout:constraintlayout:1.1.3'
}
第四步之后, 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。 声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。