程序类型已经存在:com.google.common.util.concurrent.ListenableFuture [英] Program type already present: com.google.common.util.concurrent.ListenableFuture

查看:107
本文介绍了程序类型已经存在:com.google.common.util.concurrent.ListenableFuture的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将项目转换为androidx,现在出现 com.google.common.util.concurrent.ListenableFuture 的程序类型已存在错误。 / p>

我浏览了多个stackoverflow解决方案和一些Gradle文档,但仍然无法正常工作。



问题在于,Gradle在这些模块中引入了两个版本的ListenableFuture:

  Gradle:com.google。 quava:quava:23.5jre@jar 
摇篮:com.google.guava:listenablefuture:1.0@jar

我想我想排除第二个,但不知道如何做。



您可以看到我在我的产品中尝试过的内容gradle文件,但到目前为止还没有喜悦。

  Apply插件:'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId com.drme.weathertest
minSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName 1.0
testInstrumentationRunner androidx.test.runner.AndroidJUnitRunner
}

//添加了1/2/19来尝试防止java.lang.NoClassDefFoundError:无法解决以下问题:
// Landroid / view / View $ OnUnhandledKeyEventListener;
configuration.all {
resolutionStrategy.eachDependency {DependencyResolveDetails details->
def请求= details.requested
if(requested.group == com.android.support){
if(!requested.name.startsWith( multidex)){
details.useVersion 26. +
}
}
}
// resolutionStrategy.force'com.google.quava.listenablefuture:1.0',
//'com.google.common.util.concurrent.listenablefuture'
}

//编译('com.google.guava:listenablefuture:1.0@jar'){
// //导致程序类型已存在编译错误
// //排除( com.google.guava:listenablefuture:1.0)
// exclude('com.google。 guava:listenablefuture')
//排除('listenablefuture-1.0.jar')
// //排除( maven.com.google.quava.listenablefuture)
//}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFi le('proguard-android.txt'),'proguard-rules.pro'
}
}
sourceSets {
main {
java.srcDirs = [' src / main / java','src / main / java / com.drme.weatherNoaa / Data','src / main / java / 2']
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}

依赖项{
//导致程序类型已存在编译错误//没有修复问题
实现('com.google.guava:listenablefuture:1.0'){
排除模块:'com.google.guava:listenablefuture'
}
实现fileTree(include :['* .jar'],dir:'libs')
testImplementation'androidx.arch.core:core-testing:2.0.0'
实现'androidx.lifecycle:lifecycle-extensions:2.1 .0-alpha01'
注解处理器 androidx.lifecycle:lifecycle-compiler:2.1.0-alpha01
注解处理器 androidx.room:room-compiler:2.1.0-alpha03
实现'androidx.legacy:遗产支持-v4:1.0.0'
实现'androidx.test.espresso:espresso-core:3.1.1'
实现'com.google。 code.gson:gson:2.8.2'
testImplementation'junit:junit:4.12'
实现'androidx.test:runner:1.1.1'
实现'androidx.preference:preference: 1.1.0-alpha02'
实现'androidx.recyclerview:recyclerview:1.1.0-alpha01'
实现'androidx.appcompat:appcompat:1.1.0-alpha01'
实现'androidx。 media:media:1.1.0-alpha01'
实现'androidx.room:room-runtime:2.1.0-alpha03'
实现'androidx.room:room-testing:2.1.0-alpha03'
实现'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
实现'com.google.android.gms:play-services-location:16.0.0'
实现'androidx。 core:core:1.1.0-alpha03'
实现'androidx.room:room-compiler:2.1.0-alpha03'
}

如果我正确地查看了依赖项,它似乎来自 androidx .core:core:1.1.0-alpha03

  +-androidx.core:核心:1.1.0-alpha03@aar 
+ --- androidx.concurrent:concurrent-futures:1.0.0-alpha02@jar
+-com.google.guava:listenablefuture:1.0 @ jar

建议。谢谢。

解决方案

找到了问题和答案。在项目视图中查看外部库,我发现了以下内容:

 等级:com.google.guava:guava:23.5- jre @ jar 
| _ guava-23.5-jre.jar
| _com.google
| _common
| _util.concurrent
| _ListenableFuture

Gradle:com.google.guava:listenablefuture:1.0@jar
| _listenablefuture-1.0.jar
| _com.google.common.util.concurrent
| _ListenableFuture

第二个条目中唯一的东西是重复的ListenableFuture。



通过在gradle构建文件中进行以下输入,此问题就消失了:

  configurations.all {
resolutionStrategy .eachDependency {DependencyResolveDetails详细信息->
def请求= details.requested
if(requested.group == com.android.support){
if(!requested.name.startsWith( multidex)){
details.useVersion 26. +
}
}
}

all *。排除组: com.google.guava,模块: 'listenablefuture'< ===这解决了问题
}

我不知道找出产生 com.google.guava:listenablefuture:1.0@jar 的原因,但解决了所产生的问题。



感谢所有审核过该问题的人。


I have just converted my project to androidx and am now getting the "Program type already present" error for com.google.common.util.concurrent.ListenableFuture.

I have looked through multiple stackoverflow solutions and some of the Gradle documentation and still can't get it to work.

The problem is that there are two versions of ListenableFuture brought in by Gradle in these modules:

Gradle: com.google.quava:quava:23.5jre@jar 
Gradle: com.google.guava:listenablefuture:1.0@jar

I would guess that I want to exclude the second one, but can not figure out how to do it.

You can see what I have tried in my gradle file, but no joy so far.

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.drme.weathertest"
        minSdkVersion 26
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

//    added 1/2/19 to try and prevent java.lang.NoClassDefFoundError: Failed resolution of:
//    Landroid/view/View$OnUnhandledKeyEventListener;
    configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
            if (requested.group == "com.android.support") {
                if (!requested.name.startsWith("multidex")) {
                    details.useVersion "26.+"
                }
            }
        }
//        resolutionStrategy.force 'com.google.quava.listenablefuture:1.0',
//                'com.google.common.util.concurrent.listenablefuture'
    }

//    compile('com.google.guava:listenablefuture:1.0@jar') {
//        // causing "Program type already present" compile errors
//        //exclude("com.google.guava:listenablefuture:1.0")
//        exclude('com.google.guava:listenablefuture')
//        exclude('listenablefuture-1.0.jar')
//        //exclude("maven.com.google.quava.listenablefuture")
//    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            java.srcDirs = ['src/main/java', 'src/main/java/com.drme.weatherNoaa/Data', 'src/main/java/2']
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

dependencies {
    // causing "Program type already present" compile errors // did not fix problem
    implementation('com.google.guava:listenablefuture:1.0') {
        exclude module: 'com.google.guava:listenablefuture'
    }
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'androidx.arch.core:core-testing:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha01'
    annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.1.0-alpha01"
    annotationProcessor "androidx.room:room-compiler:2.1.0-alpha03"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'com.google.code.gson:gson:2.8.2'
    testImplementation 'junit:junit:4.12'
    implementation 'androidx.test:runner:1.1.1'
    implementation 'androidx.preference:preference:1.1.0-alpha02'
    implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
    implementation 'androidx.media:media:1.1.0-alpha01'
    implementation 'androidx.room:room-runtime:2.1.0-alpha03'
    implementation 'androidx.room:room-testing:2.1.0-alpha03'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'androidx.core:core:1.1.0-alpha03'
    implementation 'androidx.room:room-compiler:2.1.0-alpha03'
}

If I am looking at the dependencies correctly, it looks like it comes from androidx.core:core:1.1.0-alpha03.

+--- androidx.core:core:1.1.0-alpha03@aar
+--- androidx.concurrent:concurrent-futures:1.0.0-alpha02@jar
+--- com.google.guava:listenablefuture:1.0@jar   

Suggestions would be appreciated. Thanks.

解决方案

Found the problem and the answer. Looking at the External Libraries in the Project view I found the following:

Gradle: com.google.guava:guava:23.5-jre@jar 
 |_ guava-23.5-jre.jar 
    |_com.google
      |_common 
        |_util.concurrent
          |_ListenableFuture

Gradle: com.google.guava:listenablefuture:1.0@jar
 |_listenablefuture-1.0.jar
   |_com.google.common.util.concurrent
     |_ListenableFuture

The only thing in the second entry was the duplicate ListenableFuture.

By making the following entry in the gradle build file, this problem went away:

configurations.all {
        resolutionStrategy.eachDependency { DependencyResolveDetails details ->
            def requested = details.requested
            if (requested.group == "com.android.support") {
                if (!requested.name.startsWith("multidex")) {
                    details.useVersion "26.+"
                }
            }
        }

        all*.exclude group: 'com.google.guava', module: 'listenablefuture' <===This fixed the problem
    }

I could not figure out what was generating the com.google.guava:listenablefuture:1.0@jar, but the resulting problem was solved.

Thanks for all who reviewed the problem.

这篇关于程序类型已经存在:com.google.common.util.concurrent.ListenableFuture的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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