Migrate to AndroidX 遇到的坑

Androidx 迁移方法:android

首先把 gradle 版本改成3.2.0以上,以及 compileSdkVersion 为28以上app

而后 Android Studio 菜单栏 Refactor -> Migrate to AndroidXide

若是是新项目,使用AndroidX相关依赖,能够在gradle.properties文件里添加配置:gradle

android.useAndroidX=true
android.enableJetifier=true

若是你只是想使用AndroidX,可是以前的不迁移,能够这样配置:ui

android.useAndroidX=true
android.enableJetifier=false

迁移完成后运行报错。。。this

Conflict with dependency 'androidx.lifecycle:lifecycle-runtime' in project ':app'. Resolved versions for runtime classpath (2.0.0-rc01) and compile classpath (2.0.0) differ. This can lead to runtime crashes. To resolve this issue follow advice at https://developer.android.com/studio/build/gradle-tips#configure-project-wide-properties. Alternatively, you can try to fix the problem by adding this snippet to ...\...\..\..\build.gradle:
​

根据提示解决:spa

subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"

    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.1"
            }else if(details.requested.group == 'androidx.lifecycle')
            {
                details.useVersion "2.0.0-rc01"
            }else if(details.requested.group == 'androidx.versionedparcelable')
            {
                details.useVersion "1.0.0-rc01"
            }else if(details.requested.group == 'androidx.core')
            {
                details.useVersion "1.0.0-rc01"
            }
        }
    }
}
相关文章
相关标签/搜索