gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 06:16:14 30 4
gpt4 key购买 nike

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

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

这是我的应用程序 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 错误。

第一个错误 :

Error:Gradle: Execution failed for task ':appcompat:dexDebugTest'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/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 /home/alexander/projects/shopster-gradle/appcompat/build/intermediates/classes/test/debug /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 Error Code: 1 Output: UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v7/widget/SearchView$OnSuggestionListener; at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122) at com.android.dx.dex.file.DexFile.add(DexFile.java:161) at com.android.dx.command.dexer.Main.processClass(Main.java:685) at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634) at com.android.dx.command.dexer.Main.access$600(Main.java:78) at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572) at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284) at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) at com.android.dx.command.dexer.Main.processOne(Main.java:596) at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103) UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Landroid/support/v4/util/TimeUtils; at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122) at com.android.dx.dex.file.DexFile.add(DexFile.java:161) at com.android.dx.command.dexer.Main.processClass(Main.java:685) at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634) at com.android.dx.command.dexer.Main.access$600(Main.java:78) at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572) at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284) at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) at com.android.dx.command.dexer.Main.processOne(Main.java:596) at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103) 2 errors; aborting



第二错误:

Error:Gradle: Class android.support.v7.widget.SearchView.OnSuggestionListener has already been added to output. Please remove duplicate copies.



第三错误:

Error:Gradle: Class android.support.v4.util.TimeUtils has already been added to output. Please remove duplicate copies.



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

/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



如果我正确理解,gradle 添加到该库的构建目录,然后尝试将其与原始库进行 dex 并引发异常。

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

另外,我不能从模块中删除这个库(jars),因为它是非常旧的项目,并且这个库已经指定了修订/版本。只有这个 jar 与这个 appcompat 模块兼容。当我删除它并添加为 gradle 依赖 ,从 appcompat 模块中消失了一些资源。换句话说, 将此库添加为 gradle 依赖项是 Not Acceptable 决定。

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

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

已编辑

我的 的哈希值支持-v4 图书馆: 7C2158F2ABA8503DF83F92C934508E2F
的哈希值v7-appcompat 图书馆: 75B6D02AA52729CA3F7B62DB1AF465EE

最佳答案

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

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

而是尝试
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'

关于android - 类已添加到输出。请删除重复的副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30481549/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com