AS创建项目去掉Androidx

按照官方文档说明 AndroidX 是对 android.support.xxx 包的整理后产物。由于之前的 support 包过于混乱,所以,Google 推出了AndroidX。由于在后续版本中,会逐步放弃对 support 的升级和维护,所以,我们必须迁移到 AndroidX。

而且目前,新版本的Android Studio 在新建工程的时候,会强制使用 Android X 开发。

但是有时候,我们还是想用之前的 support 模式怎么办呢?

AS创建项目去掉Androidx_第1张图片
解决方法:

1、在 SDK 中取消 Android 10.0(Q),可以取消使用 Use androidx.*artifacts 的选项

2、如果以上方法不行,可以把 android.useAndroidX=true改为false,把 android.enableJetifier=true改为false,然后把依赖库删掉,替换为 support 即可

下面针对方法2详细说明
1、新建项目,先不用管Androidx是否勾选上,正常流程创建项目
2、创建之后,修改gradle.properties文件,把原来的true,都改为false
AS创建项目去掉Androidx_第2张图片

android.useAndroidX=false
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=false

3、修改app的build.gradle文件,把 build.gradle 中对应的sdkVersion 修改(根据需要修改为低版本即可),并把对应的依赖库,也做修改
修改后

apply plugin: 'com.android.application'

android {
     
    compileSdkVersion 28
    buildToolsVersion "29.0.2"
    defaultConfig {
     
        applicationId "com.lyw.weiyun"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
     
        release {
     
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
     
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

4、在MainActivity删掉之前AppCompatActivity导入包,重新导入即可

import android.support.v7.app.AppCompatActivity;

5、创建module的时候,会出现不能点击finish
AS创建项目去掉Androidx_第3张图片
把步骤2改成true,再创建module即可,创建完之后记得改回来
6、到此 就取消使用 Android X,换成使用 support 操作完毕

你可能感兴趣的:(Android项目开发总结,android,android,studio,java)