如何解决库冲突(apache commons-codec) [英] How to resolve a library conflict (apache commons-codec)
问题描述
我对 Android 库有疑问.
I have a problem with Android libraries.
我想使用库 org.apache.commons.codec.binary.Hex(1.6 版)中的 Hex.encodeHexString(Byte Array) 方法
I would like use the method Hex.encodeHexString(Byte Array) from the library org.apache.commons.codec.binary.Hex (version 1.6)
在我的 Android 平台 (SDK 2.3.1) 上,commons-codec 库版本 1.3 已经存在,但该版本中尚不存在该方法(仅 encodeHex() ).
On my Android platform (SDK 2.3.1), the commons-codec library version 1.3 already exist but the method doesn't exist yet in this version (only encodeHex() ).
我将 1.6 版的 jar 库添加到我的 Eclipse 项目中(进入/libs 目录),但是当我在模拟器上运行该项目时,我得到了这个:
I added the jar library of version 1.6 into my Eclipse project (into /libs directory) but when I run the project on Emulator, I get this :
E/AndroidRuntime(1632): FATAL EXCEPTION: main
E/AndroidRuntime(1632): java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Hex.encodeHexString
如何指示操作系统好库在哪里?
How can I indicate the OS where is the good library?
我在 Mac OS X 上使用 Eclipse Juno 和 Java 1.6.0
I'm using Eclipse Juno with Java 1.6.0 on Mac OS X
抱歉我的英语不好,提前致谢!
Sorry for my bad english and thanks in advance!
我的问题显然可以用 jarjar 工具解决.http://code.google.com/p/google-http-java-client/issues/detail?id=75
EDIT : My problem could be apparently solved with jarjar tool. http://code.google.com/p/google-http-java-client/issues/detail?id=75
有人可以帮我使用这个工具吗?我不知道如何创建 Ant Manifest 或 jar 文件.
Someone could help me with this tool? I don't know how to create an Ant Manifest or a jar file.
谢谢
推荐答案
迟回复但可能对某人有用.
Late reply but maybe usefull for someone.
使用Maven Shade Plugin解决的问题
这个插件允许在编译时重命名冲突库的包名.
This plugin allows to rename package names of conflicted library at compilation.
用法:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>com.example.shaded.org.apache.commons</shadedPattern>
</relocation>
</relocations>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
</configuration>
</execution>
</executions>
</plugin>
这篇关于如何解决库冲突(apache commons-codec)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!