雷火电竞-中国电竞赛事及体育赛事平台

歡迎來到入門教程網(wǎng)!

Android

當前位置:主頁 > 軟件編程 > Android >

Android Studio項目適配AndroidX(Android 9.0)的方法步驟

來源:本站原創(chuàng)|時間:2020-01-10|欄目:Android|點擊:

說在前面:

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

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

硬核要求

Android studio 版本升級到3.2.0 以上的版本,
distributionUrl的版本升級為 4.10.1以上
targetSdkVersion 28
gradle 插件的版本升級為 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 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

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

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

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

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持我們。

上一篇:Android使用美團多渠道打包方案詳解

欄    目:Android

下一篇:Android實現(xiàn)折線走勢圖

本文標題:Android Studio項目適配AndroidX(Android 9.0)的方法步驟

本文地址:http://www.jygsgssxh.com/a1/Android/9066.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有