2

我想将我的应用从使用 Android 支持库迁移到 AndroidX 组件。

这是我的 build.gradle

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.test.myapplication"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    /*
    implementation "com.android.support:appcompat-v7:28.0.0-beta01"
    implementation "com.android.support:design:28.0.0-beta01"
    implementation "com.android.support:preference-v7:28.0.0-beta01"
    implementation "com.android.support:cardview-v7:28.0.0-beta01"
    implementation "com.android.support.constraint:constraint-layout:1.1.2"
    */
    implementation "androidx.appcompat:appcompat:1.0.0-beta01"
    implementation "com.google.android.material:material:1.0.0-beta01"
    implementation "androidx.preference:preference:1.0.0-beta01"
    implementation "androidx.cardview:cardview:1.0.0-beta01"
    implementation "androidx.constraintlayout:constraintlayout:1.1.2"
    implementation "androidx.legacy:legacy-support-v4:1.0.0-beta01"

    implementation 'com.dmitrymalkovich.android:progress-fab:1.6'
    implementation 'cat.ereza:customactivityoncrash:2.2.0'

}

在依赖项部分,您可以将旧的依赖项视为注释。使用 AndroidX 依赖项时,我在构建应用程序时遇到以下错误:

AGPBI: {"kind":"error","text":"error: duplicate value for resource \u0027attr/behavior_peekHeight\u0027 with config \u0027\u0027.","sources":[{"file":"/Users/plinzen/.gradle/caches/transforms-1/files-1.1/appcompat-1.0.0-beta01.aar/5f1c73d5e36b65b3011573345597f31d/res/values/values.xml","position":{"startLine":1303,"startColumn":4,"startOffset":70911,"endColumn":68,"endOffset":70975}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource previously defined here.","sources":[{"file":"/Users/plinzen/.gradle/caches/transforms-1/files-1.1/appcompat-1.0.0-beta01.aar/5f1c73d5e36b65b3011573345597f31d/res/values/values.xml","position":{"startLine":1303,"startColumn":4,"startOffset":70911,"endColumn":68,"endOffset":70975}}],"original":"","tool":"AAPT"}

我认为这可能与我的其他两个依赖项发生某种冲突,因为它们仍在使用 Android 支持库,例如./gradlew app:dependencies状态:

implementation 'com.dmitrymalkovich.android:progress-fab:1.6'
implementation 'cat.ereza:customactivityoncrash:2.2.0'



+--- com.dmitrymalkovich.android:progress-fab:1.6
|    \--- com.android.support:design:23.3.0
|         +--- com.android.support:appcompat-v7:23.3.0 -> 27.0.1
|         |    +--- com.android.support:support-annotations:27.0.1
|         |    +--- com.android.support:support-core-utils:27.0.1
|         |    |    +--- com.android.support:support-annotations:27.0.1
|         |    |    \--- com.android.support:support-compat:27.0.1
|         |    |         +--- com.android.support:support-annotations:27.0.1
|         |    |         \--- android.arch.lifecycle:runtime:1.0.0
|         |    |              +--- android.arch.lifecycle:common:1.0.0
|         |    |              \--- android.arch.core:common:1.0.0
|         |    +--- com.android.support:support-fragment:27.0.1
|         |    |    +--- com.android.support:support-compat:27.0.1 (*)
|         |    |    +--- com.android.support:support-core-ui:27.0.1
|         |    |    |    +--- com.android.support:support-annotations:27.0.1
|         |    |    |    \--- com.android.support:support-compat:27.0.1 (*)
|         |    |    +--- com.android.support:support-core-utils:27.0.1 (*)
|         |    |    \--- com.android.support:support-annotations:27.0.1
|         |    +--- com.android.support:support-vector-drawable:27.0.1
|         |    |    +--- com.android.support:support-annotations:27.0.1
|         |    |    \--- com.android.support:support-compat:27.0.1 (*)
|         |    \--- com.android.support:animated-vector-drawable:27.0.1
|         |         +--- com.android.support:support-vector-drawable:27.0.1 (*)
|         |         \--- com.android.support:support-core-ui:27.0.1 (*)
|         +--- com.android.support:support-v4:23.3.0
|         |    \--- com.android.support:support-annotations:23.3.0 -> 27.0.1
|         \--- com.android.support:recyclerview-v7:23.3.0
|              +--- com.android.support:support-v4:23.3.0 (*)
|              \--- com.android.support:support-annotations:23.3.0 -> 27.0.1
\--- cat.ereza:customactivityoncrash:2.2.0
     \--- com.android.support:appcompat-v7:27.0.1 (*)

有没有办法解决我的问题?

我可以简单地排除我的(子)依赖项build.gradle吗?我有一些疑问,因为 AndroidX 和 Android Support 之间的包名称不同。

编辑:我按照 Commonsware 的建议在我的项目中启用gradle.properties了 Jetifier,但我仍然遇到同样的错误:

android.useAndroidX=true
android.enableJetifier=true
4

1 回答 1

3

我不知道 AndroidX 需要Android Studio 3.2作为最低版本。我还在工作Android Studio 3.1,这就是 Jetifier 不工作的原因。之后我的代码编译。

于 2018-08-06T11:52:01.977 回答