androidx迁移几个库的问题

问题描述 投票:0回答:1

我最近迁移到androidx,面临这些问题。

问题:

enter image description hereenter image description here

我的配置

build.gradle(app) :

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.crazy.tuhin.aroundme"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 5
        versionName "1.4"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.annotation:annotation:1.1.0'
    //google
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.android.gms:play-services-places:17.0.0'


}

build.gradle(project) :

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

gradle-wrapper.properties:

#Fri Apr 10 02:21:34 IST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

settings.gradle.properties : settings.gradle(app)

org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
android.enableJetifier=true

我的Android studio版本。

Android Studio 3.6.2

我的问题是,我是否必须手动更改每一个导入,但我有这样的功能 android.enableJetifier=true

能否请您指出问题所在?这里已经提到的问题和解决方案都没有帮助.谢谢。

android androidx
1个回答
0
投票

我的问题是,我必须手动更改每一个导入吗?

是的,你必须这样做。

android.enableJetifier=true 帮助迁移第三方依赖关系到使用AndroidX。Jetifier将改变这些依赖项的字节码,使它们与使用AndroidX的项目兼容。

以下是迁移的正确步骤

准备迁移

在你开始迁移到AndroidX之前,你应该。

  • 创建一个新的分支来进行迁移修改。
  • 如果可能的话,在迁移过程中暂停或尽量减少开发(至少不要尝试进行重构或拉入新功能),因为这将有助于减少可能发生的合并冲突。

迁移

在整个迁移步骤中,重点是解决错误,让你的应用程序编译,并通过所有测试。

第1步:从旧版本的支持库直接迁移到AndroidX,比如26或27,不建议这样做。

从旧版本的支持库直接迁移到AndroidX,比如26或27,并不推荐。将应用更新到最新版本。更新项目以使用支持库的最终版本。28.0.0版本. 这是因为AndroidX构件的版本为 1.0.0 是相当于支持库的二进制文件 28.0.0 工件。然后解决所有的API变化,并确保你的应用程序与28版本编译。

第2步:将第三方依赖关系更新到最新版本。

将第三方依赖关系更新到最新版本。不这样做可能会导致无法解释的编译错误。

第3步:在应用程序中启用以下标志。

启用以下标志 gradle.properties. 在Android Studio 3.2和更高版本中,你可以将现有的项目迁移到以下地方 通过选择Refactor > 迁移到AndroidX的AndroidX。 的菜单栏。

android.enableJetifier=true - Jetifier可以帮助迁移第三方的依赖关系来使用AndroidX。Jetifier将改变这些依赖项的字节码,使其与使用AndroidX的项目兼容。

android.useAndroidX=true - Android插件使用适当的AndroidX库而不是支持库。


0
投票

已解决

如果你遇到像我这样不幸的问题,请做这些。

1. 从每个类中删除所有未使用的导入(灰色的)。

enter image description here

2. 现在像这样导入所需的类。

enter image description here

3. 对每一个相关的类重复上述步骤。

© www.soinside.com 2019 - 2024. All rights reserved.