升级AndroidX

很多人在升级Android Studio之后,发现项目疯狂报错,经过一番搜索,结论是你的项目需要进行AndroidX升级了。

如何对老的项目进行AndroidX升级了,下面是几个步骤:

1、修改gradle.properties

android.useAndroidX=true
android.enableJetifier=true
  • android.useAndroidX=true 表示当前项目启用 androidx
  • android.enableJetifier=true 表示将依赖包也迁移到androidx 。如果取值为false,表示不迁移依赖包到androidx,但在使用依赖包中的内容时可能会出现问题,当然了,如果你的项目中没有使用任何三方依赖,那么,此项可以设置为false

2、Refactor > Migrate to AndroidX

升级AndroidX_第1张图片

3、升级为28.0.0以上

apply plugin: 'com.android.application'
apply plugin: 'project-report'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.0'

    defaultConfig {
        applicationId "com.example.mapdemo"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-maps:12.0.1'
    implementation 'com.android.support:support-v4:28.0.0'
    // Needed for the LiteListDemo
    implementation "com.android.support:recyclerview-v7:28.0.0"
}



你有可能会报这个错

Didn't find class "org.apache.http.ProtocolVersion

原因分析

Android P Developer Preview的bug

解决办法

在AndroidManifest.xml文件中标签里面加入


你可能感兴趣的:(Android基础)