【问题标题】:Gradle build fails with "Program type already present: "Gradle 构建失败并显示“程序类型已存在:”
【发布时间】:2019-05-27 16:38:42
【问题描述】:

我正在尝试将大脑树服务添加到我的 Unity 应用程序中,因为我需要购买真实物品。

我能够在一个空白的 android 项目中使用 ui 并创建一个处理它的模块。但是,每当我尝试添加必要的 aar 文件时,我都会遇到 gradle build 问题。

我已将我的项目导出到 android studio 以获得更全面的错误代码和对 gradle 的细粒度控制。

但是任何 gradle 配置仍然给我一个程序类型已经存在。

这是我的 Gradle 文件的依赖项

apply plugin: 'com.android.application'


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation(name: 'android-maps-utils-0.5', ext:'aar')
implementation(name: 'google-maps-view-lib-release', ext:'aar')
implementation(name: 'play-services-base-11.0.2', ext:'aar')
implementation(name: 'play-services-basement-11.0.2', ext:'aar')
implementation(name: 'play-services-maps-11.0.2', ext:'aar')
implementation(name: 'play-services-tasks-11.0.2', ext:'aar')
implementation(name: 'support-compat-25.2.0', ext:'aar')
implementation(name: 'support-core-ui-25.2.0', ext:'aar')
implementation(name: 'support-core-utils-25.2.0', ext:'aar')
implementation(name: 'support-fragment-25.2.0', ext:'aar')
implementation(name: 'support-media-compat-25.2.0', ext:'aar')
implementation 'com.braintreepayments.api:braintree:2.20.0'


implementation ('com.braintreepayments.api:drop-in:3.2.1')

{
        exclude group: 'com.android.support.annotation'
        exclude module: 'com.android.support.v4.app'
        exclude module: 'com.android.support.v4.media'
        exclude module: 'com.android.support:support-v4:28.0.0'
        exclude group: 'support-v4'
        exclude module: 'support-v13'
    }
 //implementation(name: 'support-v4-25.2.0', ext:'aar')
}

我得到的是:

错误:程序类型已存在:android.support.v4.media.MediaBrowserCompat$MediaBrowserImplApi21$1

【问题讨论】:

标签: android android-studio unity3d


【解决方案1】:

使用以下命令分析重复项的依赖项。

./gradlew app:dependencies 

注意到implementation 'com.braintreepayments.api:braintree:2.20.0' 也依赖于android.support.v4。所以,也尽量排除它。

对于冲突依赖版本,可以指定强制版本如下:

configurations.all {
    resolutionStrategy { 
        force "com.android.support:support-v4:26.0.0"
    }
} 

【讨论】:

    【解决方案2】:

    找到了解决办法!

    只需要编辑播放服务解析器以添加到 Braintree 插件中,而不是手动添加它们或使用 gradle。它设法分离出所有单独的组件并解决冲突!

    感谢您的回复。

    我遵循了这个解决方案Gradle dependencies on Unity

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-27
      • 2017-01-30
      • 1970-01-01
      相关资源
      最近更新 更多