使用maven-android-plugin不能将第三方jar包含到Android应用程序中

时间:2011-04-16 14:34:25

标签: java android maven

我正在尝试使用提供的示例,但是当我添加另一个用POJO创建的jar时,我无法再编译应用程序

            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>maven-android-plugin</artifactId>
                <version>2.8.4</version>
                <configuration>
                    <sdk>
                        <platform>9</platform>
                    </sdk>
                    <emulator>
                        <avd>23</avd>
                        <wait>10000</wait>
                        <!--<options>-no-skin</options>-->
                    </emulator>
                    <zipalign>
                        <verbose>true</verbose>
                    </zipalign>
                    <deleteConflictingFiles>true</deleteConflictingFiles>
                    <undeployBeforeDeploy>true</undeployBeforeDeploy>
                </configuration>
            </plugin>

当我使用我创建的jar时,我收到此OOM错误

    [INFO] solution is to recompile the class from source, using an up-to-date compiler
    [INFO] and without specifying any "-target" type options. The consequence of ignoring
    [INFO] this warning is that reflective operations on this class will incorrectly
    [INFO] indicate that it is *not* an inner class.
    [INFO]
    [INFO] UNEXPECTED TOP-LEVEL ERROR:
    [INFO] java.lang.OutOfMemoryError: Java heap space
    [INFO]  at com.android.dx.rop.code.RopMethod.calcPredecessors(RopMethod.java:153)
    [INFO]  at com.android.dx.rop.code.RopMethod.labelToPredecessors(RopMethod.java:95)
    [INFO]  at com.android.dx.dex.code.RopTranslator.pickOrder(RopTranslator.java:345)
    [INFO]  at com.android.dx.dex.code.RopTranslator.translateAndGetResult(RopTranslator.java:205)
    [INFO]  at com.android.dx.dex.code.RopTranslator.translate(RopTranslator.java:102)
    [INFO]  at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:289)
    [INFO]  at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:131)
    [INFO]  at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:85)
    [INFO]  at com.android.dx.command.dexer.Main.processClass(Main.java:369)
    [INFO]  at com.android.dx.command.dexer.Main.processFileBytes(Main.java:346)
    [INFO]  at com.android.dx.command.dexer.Main.access$400(Main.java:59)
    [INFO]  at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:294)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:134)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:190)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:122)
    [INFO]  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108)
    [INFO]  at com.android.dx.command.dexer.Main.processOne(Main.java:313)
    [INFO]  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:233)
    [INFO]  at com.android.dx.command.dexer.Main.run(Main.java:185)
    [INFO]  at com.android.dx.command.dexer.Main.main(Main.java:166)
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO]
    [INFO] Chapter 06: Mobile Device Parent .................. SUCCESS [0.359s]
    [INFO] Chapter 06: Mobile Device Application ............. FAILURE [1:27.859s]

我甚至试过提高内存

 set JAVA_OPTS="%JAVA_OPTS% -Xmx512m -XX:MaxPermSize=768m"

但由于某种原因仍然用完了。

现在,当我尝试使用其他人的另一个jar时,请说Crest声称它可以与Android开箱即用:

    <dependency>
        <groupId>org.codegist.crest</groupId>
        <artifactId>codegist-crest</artifactId>
    </dependency>

然后我尝试构建并得到此错误:

    [INFO] trouble processing "javax/xml/bind/annotation/adapters/CollapsedStringAdapter.class":
    [INFO]
    [INFO] Ill-advised or mistaken usage of a core class (java.* or javax.*)
    [INFO] when not building a core library.
    [INFO]
    ...
    [INFO] If you are legitimately using some code that happens to be in a
    [INFO] core package, then the easiest safe alternative you have is to
    [INFO] repackage that code. That is, move the classes in question into
    [INFO] your own package namespace. This means that they will never be in
    [INFO] conflict with core system classes. JarJar is a tool that may help
    [INFO] you in this endeavor. If you find that you cannot do this, then
    [INFO] that is an indication that the path you are on will ultimately
    [INFO] lead to pain, suffering, grief, and lamentation.

所以

  1. 如何确定我可以在Android应用程序中使用哪些类?

  2. 如何构建

  3. 的公共域jar

1 个答案:

答案 0 :(得分:2)

关于OOM: 尝试设置MAVEN_OPTS =“ - Xmx512m”而不是JAVA_OPTS

关于核心课程:您获得的信息非常丰富。你包含的jar包含核心命名空间中的一些类,这是不允许的。您可以按照建议使用jarjar。

  1. 您可以使用此处列出的课程:http://developer.android.com/reference/packages.html
  2. 似乎不完整的问题