說(shuō)在前面:
創(chuàng)新互聯(lián)從2013年創(chuàng)立,先為元寶山等服務(wù)建站,元寶山等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為元寶山企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
老項(xiàng)目、大項(xiàng)目適配Android X 注意了,一定要謹(jǐn)慎、謹(jǐn)慎、再謹(jǐn)慎。項(xiàng)目中用到的第三方庫(kù)多的話會(huì)很麻煩,有些第三方庫(kù)還沒(méi)有適配Android X。
適配Android X的兩種情況:一種是老項(xiàng)目適配Android X ,另外一種是新項(xiàng)目要求適配Android 9.0
硬核要求
Android studio 版本升級(jí)到3.2.0 以上的版本,
distributionUrl的版本升級(jí)為 4.10.1以上
targetSdkVersion 28
gradle 插件的版本升級(jí)為 3.2.0以上
classpath 'com.android.tools.build:gradle:3.2.0'
這里以AS 3.4為例
第一步:
新項(xiàng)目,這步可以跳過(guò)。
compileSdkVersion 28 defaultConfig { applicationId "gangqing.pu.xmxidaq" minSdkVersion 19 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" }
第二步:
// Top-level build file where you can add configuration options common to all sub-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: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() maven { url "https://jitpack.io" } } } task clean(type: Delete) { delete rootProject.buildDir }
第三步:
在gradle.properties 中加入如下代碼,表示支持Android X
android.useAndroidX=true android.enableJetifier=true
第四步:
Android Studio ----> Refactor----> Migrate to androidx,,一鍵轉(zhuǎn)為 androidX
第五步:
支持Java 1.8
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
第六步:
修改布局,比如:ConstraintLayout
變化之前 | AndroidX |
---|---|
<android.support.constraint.ConstraintLayout | <androidx.constraintlayout.widget.ConstraintLayout |
注意:如果是老項(xiàng)目適配AndroidX,沒(méi)有找到ConstraintLayout 的話,那么還需要在中添加如下代碼
dependencies { implementation 'androidx.constraintlayout:constraintlayout:1.1.3' }
第四步之后,
<android.support.constraint.ConstraintLayout
變?yōu)?lt;androidx.constraintlayout.ConstraintLayout 這時(shí)你需要修改為
<androidx.constraintlayout.widget.ConstraintLayout |
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
本文題目:AndroidStudio項(xiàng)目適配AndroidX(Android9.0)的方法步驟
當(dāng)前路徑:http://muchs.cn/article42/ghgphc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、ChatGPT、建站公司、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站策劃、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)