溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

AndroidStudio項目適配AndroidX(Android9.0)的方法教程

發(fā)布時間:2021-11-11 14:59:05 來源:億速云 閱讀:281 作者:iii 欄目:編程語言

本篇內(nèi)容介紹了“AndroidStudio項目適配AndroidX(Android9.0)的方法教程”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!

說在前面:

老項目、大項目適配Android X 注意了,一定要謹慎、謹慎、再謹慎。項目中用到的第三方庫多的話會很麻煩,有些第三方庫還沒有適配Android X。

適配Android X的兩種情況:一種是老項目適配Android X ,另外一種是新項目要求適配Android 9.0

硬核要求

Android studio 版本升級到3.2.0 以上的版本,distributionUrl的版本升級為 4.10.1以上targetSdkVersion 28gradle 插件的版本升級為 3.2.0以上

classpath 'com.android.tools.build:gradle:3.2.0'

這里以AS 3.4為例

第一步:

新項目,這步可以跳過。

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 inpidual 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=trueandroid.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

<android.support.constraint.ConstraintLayout<androidx.constraintlayout.widget.ConstraintLayout

注意:如果是老項目適配AndroidX,沒有找到ConstraintLayout 的話,那么還需要在中添加如下代碼

dependencies {   implementation 'androidx.constraintlayout:constraintlayout:1.1.3'}

第四步之后,<android.support.constraint.ConstraintLayout變?yōu)?lt;androidx.constraintlayout.ConstraintLayout 這時你需要修改為<androidx.constraintlayout.widget.ConstraintLayout |

“AndroidStudio項目適配AndroidX(Android9.0)的方法教程”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI