【问题标题】:How to resolve "TransformException: duplicate entry" error?如何解决“TransformException:重复条目”错误?
【发布时间】:2017-07-01 09:15:40
【问题描述】:

Gradle 同步在运行时未显示任何错误,但当我尝试运行应用程序时却显示错误。

我尝试删除重复的库并在我的MainActivity 中添加了MultiDex.install(this);,并尝试清理和运行该项目,但没有成功。

错误:

错误:任务 ':app:transformClassesWithJarMergingForDebug' 执行失败。 com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/fathzer/soft/javaluator/demo/DemoApplet.class

我的毕业代码:

 apply plugin: 'com.android.application'
 android {
 compileSdkVersion 26
 buildToolsVersion "26.0.0"
 defaultConfig {
 applicationId "com.example.kanwal.calculator_test"
 minSdkVersion 14
 targetSdkVersion 26
 versionCode 1
 versionName "1.0"
 testInstrumentationRunner                                                                    "android.support.test.runner.AndroidJUnitRunner"
 multiDexEnabled true }
 buildTypes {
 release {
 minifyEnabled false
 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-
 rules.pro'} } }
 dependencies {
 compile fileTree(include: ['*.jar'], dir: 'libs')
 compile 'com.android.support:multidex:1.0.1'
 androidTestCompile('com.android.support.test.espresso:espresso 
 core:2.2.2',{
 exclude group: 'com.android.support', module: 'support-annotations'
 })
 compile 'com.android.support:appcompat-v7:26.+'
 compile 'com.android.support.constraint:constraint-layout:1.0.2'
 testCompile 'junit:junit:4.12'
 compile files('libs/javaluator-3.0.1.jar')}

【问题讨论】:

  • 请将您的代码包含为 文本 而不是图像。无法搜索图像,对某些用户而言难以阅读,并且外部图像可能会消失。
  • 好的,我在这里发布我的 gradle 代码:
  • dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:multidex:1.0.1' androidTestCompile('com.android. support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support annotations'}) compile 'com.android.support:appcompat-v7:26.+ ' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' 编译文件('libs/javaluator-3.0.1.jar')}
  • 请编辑您的问题,而不是发布在 cmets 中,这样会更容易找到和阅读!
  • 我刚刚更新了我的问题。

标签: java android xml android-studio


【解决方案1】:

您已将此行添加到您的gradle

compile fileTree(include: ['*.jar'], dir: 'libs')

您可以删除冗余线或删除上面的线本身。

通过删除上面的行

【讨论】:

  • 我也试过了。删除了上面那一行,但它没有解决错误,而是显示了许多其他错误。
【解决方案2】:

从 jar 中排除重复的包:

compile('libs/javaluator-3.0.1.jar') {
exclude module: 'demo';}

尝试在项目根目录的终端上运行它:

./gradlew clean

【讨论】:

  • 我在终端中运行该命令并显示:'。'未被识别为内部或外部命令、可运行程序或批处理文件。删除 (.) 后显示:'/gradlew' 不被识别为内部或外部命令、可运行程序或批处理文件。
  • 转到 Android Studio 右侧的 gradle 选项卡,然后从那里运行 clean 命令。 imgur.com/a/FYL6j
  • 我按照您的说明进行了清理,现在没有错误,但仍未在我的设备中运行该应用程序。另外,在运行应用程序后,它会将 MainActivity 中的所有 R 变为红色。
  • 现在发生了什么?尽可能多地描述问题
  • 该应用程序现在没有错误,但是在运行该应用程序后,MainActivity 中的所有 R 都变成了红色。并且应用程序没有在我的设备中运行。
猜你喜欢
  • 2017-03-14
  • 2015-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-13
  • 2016-06-02
  • 2023-03-27
相关资源
最近更新 更多