为什么android.arch.navigation导致程序类型已经存在:android.support.v4.os.ResultReceiver $ 1? [英] Why does android.arch.navigation cause Program type already present: android.support.v4.os.ResultReceiver$1?

查看:64
本文介绍了为什么android.arch.navigation导致程序类型已经存在:android.support.v4.os.ResultReceiver $ 1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android Studio版本

I am using Android Studio version

Android Studio 3.2 Canary 14
Build #AI-181.4668.68.32.4763614, built on May 4, 2018
JRE: 1.8.0_152-release-1136-b02 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.11.6

在研究新的建筑导航组件android.arch.navigation时,我遇到了此构建失败.

While investigating the new Architectural navigation components android.arch.navigation I have encountered this build failure.

AGPBI: {"kind":"error","text":"Program type already present: android.support.v4.os.ResultReceiver$1","sources":[{}],"tool":"D8"}
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: ...
...
  Program type already present: android.support.v4.os.ResultReceiver$1

我的应用程序gradle构建类似于:-

My app gradle build resembles:-

apply plugin: 'com.android.application'
apply plugin: "androidx.navigation.safeargs"

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

dependencies {
    def nav_version = "1.0.0-alpha01"

    implementation "android.arch.navigation:navigation-fragment:$nav_version"
    implementation "android.arch.navigation:navigation-ui:$nav_version"

    // optional - Test helpers
    androidTestImplementation "android.arch.navigation:navigation-testing:$nav_version"

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'

    implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1'
    testImplementation 'junit:junit:4.12'

    androidTestImplementation 'androidx.test:runner:1.1.0-alpha2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha2'
}

和项目级别的gradle构建:-

and project level gradle build:-

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
        classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha01"
    }
}

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

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

我曾尝试过重构为AndroidX,但是却收到一条消息,指出在项目中找不到用法,那么为什么仍然提到此"v4"类呢?

I have tried refactoring to AndroidX, however I get a message stating No usages found in project, so why is this "v4" class still being mentioned?

推荐答案

我一直在研究此问题,并且在将依赖项添加到库中时排除支持包来对主要问题进行了排序,方法是:

I've been looking at this issue and I have sorted the main issue here by excluding the support package when adding the dependency to the library, doing this:

implementation("android.arch.navigation:navigation-fragment:$nav_version") {
  exclude group: 'com.android.support'
}

这将允许您运行应用程序.但是,此工件使用的是支持工件,而不是androidx工件.查看文档,我们可以看到NavHostFragment正在扩展support.v4.Fragment https://developer.android.com/reference/androidx/navigation/fragment/NavHostFragment

That would allow you to run the application. However, this artifact is using the support artifacts rather than the androidx artifacts. Looking at the documentation, we can see that NavHostFragment is extending support.v4.Fragment https://developer.android.com/reference/androidx/navigation/fragment/NavHostFragment

因此,简而言之,据我所知,您将看到三个选项.第一个是删除androidx工件并使用支持对象,这最终取决于您的应用程序的大小.

So, in short, you are presented with three options, as far as I can see. The first one is to drop the androidx artifacts and use the support ones which eventually depends on how big your app is.

第二个选择是删除导航库,并返回到经典的导航方法,我想这可能对您来说是不可取的.

The second option is to drop the navigation library and go back to the classic way of dealing with navigation which, I guess, is probably undesirable for you.

第三个选项是实现您自己的导航主机,我不知道它将做多少工作.

The third option is to implement a navigation host of your own which I don't know how much work it would be.

在Google发布该库的androidx版本之前,此响应将一直保持准确,令我惊讶的是他们还没有.

This response will remain accurate until Google releases the androidx version of the library which I am surprised they haven't already.

希望是有帮助的.

这篇关于为什么android.arch.navigation导致程序类型已经存在:android.support.v4.os.ResultReceiver $ 1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆