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"
            }
        }
    }
}
相關文章
相關標籤/搜索