Get the App
SLTechnology News&Howtos  ›  Development  › 

Method tutorial of adapting AndroidStudio Project to AndroidX (Android9.0)

Shulou Source: shulou.com Published: 2022-06-02 16:11:22 11月14日 Update

This article introduces the relevant knowledge of "AndroidStudio Project adaptation AndroidX (Android9.0) method tutorial". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Say in front:

Old projects, large projects adapt to Android X attention, must be cautious, cautious, and then cautious. It can be troublesome if many third-party libraries are used in the project, and some third-party libraries have not yet been adapted to Android X.

There are two situations of adapting to Android X: one is that the old project adapts to Android X, and the other is that the new project requires adaptation to Android 9.0.

Hard core requirement

Android studio version upgraded to 3.2.0 or above, distributionUrl version upgraded to 4.10.1 or above, targetSdkVersion 28gradle plug-in version upgraded to 3.2.0 or above

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

Take AS 3.4 as an example.

Step one:

New project, this step can be skipped.

CompileSdkVersion 28 defaultConfig {applicationId "gangqing.pu.xmxidaq" minSdkVersion 19 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"}

Step 2:

/ / 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}

Step 3:

Add the following code to gradle.properties to indicate support for Android X

Android.useAndroidX=trueandroid.enableJetifier=true

Step 4:

Android Studio-> Refactor---- > Migrate to androidx, one click to androidX

Step 5:

Support for Java 1.8

CompileOptions {sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8}

Step 6:

Modify the layout, such as ConstraintLayout

Tags: Adaptation project version upgrade tutorial method code content situation new project more knowledge third party support practical successful learning next in use dilemma practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Apple Shulou Technology Redmi Docker