我有一个Android Maven项目,并希望在其中使用Google Guice 3.0。
有一个Guice的“No-AOP”版本,它与Android兼容。
更新1(03.05.2013 10:46 MSK):
当我在Google Guice上添加依赖项时,我会在构建期间遇到以下异常(mvn clean install
):
[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Lcom/google/inject/Abs
tractModule;
[INFO] at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:12
3)
[INFO] at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[INFO] at com.android.dx.command.dexer.Main.processClass(Main.java:490)
[INFO] at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
[INFO] at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[INFO] at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpen
er.java:245)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.j
ava:131)
[INFO] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java
:109)
[INFO] at com.android.dx.command.dexer.Main.processOne(Main.java:422)
[INFO] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
[INFO] at com.android.dx.command.dexer.Main.run(Main.java:209)
[INFO] at com.android.dx.command.dexer.Main.main(Main.java:174)
[INFO] at com.android.dx.command.Main.main(Main.java:91)
[INFO] 1 error; aborting
以下是我的依赖项:
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<classifier>no_aop</classifier>
</dependency>
<!-- Make sure this (robolectric dependency) is below the android dependencies -->
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<version>1.0-RC4</version>
</dependency>
<dependency>
<groupId>org.achartengine</groupId>
<artifactId>achartengine</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-core</artifactId>
<version>2.0M8</version>
</dependency>
<dependency>
<groupId>ru.altruix</groupId>
<artifactId>ccp-commons</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>ru.altruix</groupId>
<artifactId>commons</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.1.4</version>
</dependency>
</dependencies>
答案 0 :(得分:9)
您需要将no_aop
指定为分类器,如下所示:
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<classifier>no_aop</classifier>
</dependency>
答案 1 :(得分:2)
如果您还想摆脱aopalliance依赖关系,请使用:
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<classifier>no_aop</classifier>
<exclusions>
<exclusion>
<artifactId>aopalliance</artifactId>
<groupId>aopalliance</groupId>
</exclusion>
</exclusions>
</dependency>
答案 2 :(得分:0)
Google 不鼓励因为反射性能而在Android上使用Guice。您可以使用的最后一个 no_aop 版本是:
compile 'com.google.inject:guice:2.0-no_aop'
'com.google.inject:guice:3.0-no_aop'
不再位于maven存储库中,还有'com.google.inject:guice:4.1.0-no_aop'
。
'com.google.inject:guice:4.1.0
崩溃:
com.google.common.util.concurrent.ExecutionError: java.lang.ExceptionInInitializerError
和
compile ('com.google.inject:guice:4.1.0') {
exclude group: 'aopalliance', module: 'aopalliance'
}
与NoClassDefFoundError: org.aopalliance.intercept.MethodInterceptor