类已添加到输出中。请删除重复的副本

时间:2015-05-27 11:47:02

标签: android gradle android-gradle

我有一些应用程序,如果我在设备上运行它可以正常工作。

但是现在,我需要为这个应用程序编写单元测试,当我尝试运行一些单元测试时,我遇到了问题。

这是我的应用 build.gradle

    buildscript {
        repositories {
            jcenter()
            mavenCentral()
            maven { url 'https://maven.fabric.io/public' }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.0.0'
            classpath 'io.fabric.tools:gradle:1.+'
        }
    }
    apply plugin: 'com.android.application'
    apply plugin: 'io.fabric'

    repositories {
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
    }

    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v4'
        all*.exclude group: 'com.google.android.gms', module: 'play-services'
    }

    android {
        compileSdkVersion 21
        buildToolsVersion "19.1"

        defaultConfig {
            applicationId "com.lodoss.shopsterhood"
            minSdkVersion 9
            targetSdkVersion 21
            versionCode 15
            versionName "2.0.1"
        }
        dexOptions {
            preDexLibraries = false
            incremental = false
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }

        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/LGPL2.1'
        }

        lintOptions {
            abortOnError false
        }
    }

    dependencies {
        compile fileTree(dir: 'lib', include: ['*.jar'])
        compile project (':appcompat')
        compile project(':DragSortListView')
        compile 'com.github.chrisbanes.actionbarpulltorefresh:library:0.9.9'
    //    compile 'com.vk:androidsdk:1.3.6'
        compile project(':facebook')
    //    compile('com.crashlytics.sdk.android:crashlytics:2.2.1@aar') {
    //        transitive = true;
    //    }
        compile('com.twitter.sdk.android:twitter:1.3.0@aar') {
            transitive = true;
        }


    //    androidTestCompile 'com.squareup.assertj:assertj-android:1.0.0'
    //    androidTestCompile 'com.squareup.assertj:assertj-android-support-v4:1.0.0'
    //    androidTestCompile 'com.squareup.assertj:assertj-android-play-services:1.0.0'
        compile 'com.jayway.android.robotium:robotium-solo:5.2.1'
    //    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
    //    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.0') {
    //        exclude module: 'support-annotations'
    //    }
    //    androidTestCompile 'org.hamcrest:hamcrest-all:1.3'

    }

这是模块的 build.gradle ,当我尝试运行单元测试时会出现编译错误:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}
apply plugin: 'com.android.library'

repositories {
    jcenter()
}

android {
    compileSdkVersion 21
    buildToolsVersion "19.1"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    dexOptions {
        preDexLibraries = false
        incremental = false
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

这是我的测试:

package com.lodoss.shopsterhood.activity;

import android.test.ActivityInstrumentationTestCase2;
import com.lodoss.shopsterhood.Activity_Main;
import com.robotium.solo.Solo;

/**
 * Created by Boris on 27.05.15.
 */
public class EmailRegistrationTest extends ActivityInstrumentationTestCase2<Activity_Main> implements ActivityTestCaseConstants {

    private Solo solo;

    public EmailRegistrationTest() {
        super(Activity_Main.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());
    }

    @Override
    protected void tearDown() throws Exception{
        solo.finishOpenedActivities();
    }

    public void testEmailRegistrationWithCorrectData(){
        // check that we have the right activity
        solo.assertCurrentActivity("Wrong activity", Activity_Main.class);

        Activity_Main activity = (Activity_Main) solo.getCurrentActivity();
    }
}

我知道,它没有任何用处,但它没有运行。

我有 3 错误。

第一个错误

  

错误:Gradle:任务执行失败&#39;:appcompat:dexDebugTest&#39;。

     
    

com.android.ide.common.internal.LoggedErrorException:无法运行命令:
      /opt/adt-bundle-linux/adt-bundle-linux-x86_64-20140702/sdk/build-tools/19.1.0/dx     --dex --no-optimize --output / home / alexander / projects / shopster-gradle / appcompat / build / intermediates / dex / test / debug     /家庭/亚历山大/项目/ shopster-gradle产出/程序兼容性/编译/中间体/班/测试/调试     /home/alexander/projects/shopster-gradle/appcompat/build/intermediates/bundles/debug/classes.jar     /home/alexander/projects/shopster-gradle/appcompat/libs/android-support-v7-appcompat.jar     /home/alexander/projects/shopster-gradle/appcompat/build/intermediates/bundles/debug/libs/android-support-v7-appcompat.jar     /home/alexander/projects/shopster-gradle/appcompat/libs/android-support-v4.jar     /home/alexander/projects/shopster-gradle/appcompat/build/intermediates/bundles/debug/libs/android-support-v4.jar     错误代码:1输出:意外的顶级异常:
      java.lang.IllegalArgumentException:已添加:     Landroid /支持/ V7 /空间/搜索查看$ OnSuggestionListener;               在com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)               在com.android.dx.dex.file.DexFile.add(DexFile.java:161)               在com.android.dx.command.dexer.Main.processClass(Main.java:685)               在com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)               在com.android.dx.command.dexer.Main.access $ 600(Main.java:78)               在com.android.dx.command.dexer.Main $ 1.processFileBytes(Main.java:572)               在com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)               在com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)               在com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)               在com.android.dx.command.dexer.Main.processOne(Main.java:596)               在com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)               在com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)               在com.android.dx.command.dexer.Main.run(Main.java:230)               在com.android.dx.command.dexer.Main.main(Main.java:199)               在com.android.dx.command.Main.main(Main.java:103)意外的顶级异常:java.lang.IllegalArgumentException:已经     补充:Landroid / support / v4 / util / TimeUtils;               在com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)               在com.android.dx.dex.file.DexFile.add(DexFile.java:161)               在com.android.dx.command.dexer.Main.processClass(Main.java:685)               在com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)               在com.android.dx.command.dexer.Main.access $ 600(Main.java:78)               在com.android.dx.command.dexer.Main $ 1.processFileBytes(Main.java:572)               在com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)               在com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)               在com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)               在com.android.dx.command.dexer.Main.processOne(Main.java:596)               在com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)               在com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)               在com.android.dx.command.dexer.Main.run(Main.java:230)               在com.android.dx.command.dexer.Main.main(Main.java:199)               在com.android.dx.command.Main.main(Main.java:103)2个错误;中止

  

第二次错误:

  

错误:Gradle:Class   android.support.v7.widget.SearchView.OnSuggestionListener已经   已添加到输出中。请删除重复的副本。

第三次错误:

  

错误:Gradle:类android.support.v4.util.TimeUtils已经存在   添加到输出。请删除重复的副本。

在研究第一个堆栈跟踪之后,我发现了这一行:

  

/home/alexander/projects/shopster-gradle/appcompat/libs/android-support-v7-appcompat.jar

     

/家庭/亚历山大/项目/ shopster-gradle这个/程序兼容性/的建立/中间体/捆绑/调试/库/机器人支撑-V7-appcompat.jar

     

/home/alexander/projects/shopster-gradle/appcompat/libs/android-support-v4.jar   /home/alexander/projects/shopster-gradle/appcompat/build/intermediates/bundles/debug/libs/android-support-v4.jar

如果我理解正确,gradle会将 build 目录添加到此库中,然后尝试使用原始库来设置它并抛出异常。

我试图手动移除它,但它没有帮助......

另外,我无法从模块中删除这些库(jar),因为它是一个非常古老的项目,而且这个库已经指定了版本/版本。只有这个罐子与这个 appcompat 模块兼容。当我删除它并添加为 gradle dependecy 时,消失了来自 appcompat 模块的一些资源。换句话说,将此库添加为gradle dependecies是不可接受的决定。

我尝试使用 Intellij IDEA 14 运行测试。

有谁知道如何解决这个问题?

EDITED

哈希的 support-v4 7C2158F2ABA8503DF83F92C934508E2F

v7-appcompat 的哈希:75B6D02AA52729CA3F7B62DB1AF465EE

1 个答案:

答案 0 :(得分:0)

Robotium是一个测试库,不应该像这样包含

compile 'com.jayway.android.robotium:robotium-solo:5.2.1'

而是尝试

androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'