gpt4 book ai didi

java - 由于多个 dex 文件,Android Gradle 构建失败

转载 作者:搜寻专家 更新时间:2023-11-01 08:00:10 26 4
gpt4 key购买 nike

我的 Android Gradle 项目有很多外部依赖项。在某个时候,我决定提取一些功能来分离库以及一些依赖项,我使用 maven-assembly-plugin 打包了这些依赖项。 。然后我将新创建的库作为依赖项包括在内 + 删除一些已经 bundle 在我的库中的依赖项。

问题是,在构建时我遇到了这个我不明白的错误:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/squareup/okhttp/Address;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
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)

这是以前直接包含的依赖项 (okhttp) 之一,现在与我的新库一起打包。我创建的库可以找到here .

这是我的构建文件:

Android 应用构建配置:

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'

repositories {
mavenCentral()
mavenRepo urls: "https://github.com/mkorszun/okrest/raw/master/repo"
}

android {
compileSdkVersion 15
buildToolsVersion "19.0.2"

defaultConfig {
minSdkVersion 8
targetSdkVersion 15
}

packagingOptions {
exclude 'META-INF/LICENSE.txt'
}

}

dependencies {
compile 'com.android.support:appcompat-v7:19.0.1'
// compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.11'
// compile 'com.sun.jersey:jersey-client:1.8'
// compile 'com.sun.jersey:jersey-core:1.8'
// compile 'com.squareup.okhttp:okhttp:1.2.1'
// compile 'com.google.guava:guava:15.0'
compile 'com.google.android.gms:play-services:4.0.30'
compile files('libs/GraphView-3.0.jar')
compile 'com.okrest:okrest:0.0.3'
}

库构建配置:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.okrest</groupId>
<artifactId>okrest</artifactId>
<version>0.0.3</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<distributionManagement>
<repository>
<id>local.repo</id>
<name>Internal Repository</name>
<url>file://repo</url>
</repository>
</distributionManagement>

<dependencies>

<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>

<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.18.1</version>
</dependency>

<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>1.5.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.rest-driver</groupId>
<artifactId>rest-client-driver</artifactId>
<version>1.1.37</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
<format>xml</format>
<maxmem>256m</maxmem>
<aggregate>true</aggregate>
<check/>
</configuration>
</plugin>

<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>2.1.0</version>
</plugin>

</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</reporting>

</project>

这是我的 android 应用程序的依赖关系树:

+--- com.android.support:appcompat-v7:19.0.1
| \--- com.android.support:support-v4:19.0.1
+--- com.google.android.gms:play-services:4.0.30
| \--- com.android.support:support-v4:13.0.0 -> 19.0.1
\--- com.okrest:okrest:0.0.3
+--- org.codehaus.jackson:jackson-mapper-asl:1.9.13
| \--- org.codehaus.jackson:jackson-core-asl:1.9.13
+--- com.sun.jersey:jersey-client:1.18.1
\--- com.squareup.okhttp:okhttp:1.5.0

最佳答案

这意味着该类被两次包含在 APK 中,这是不允许的。一定是您有两个到该库的依赖路径。检查它们并删除多余的。如果您找不到它,请将您的构建文件附加到您的问题。

关于java - 由于多个 dex 文件,Android Gradle 构建失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22305409/

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