我正在尝试将 cocos2d 包含到一个预先存在的应用程序中。我已经以 Eclipse 的方式完成了一些事情,例如设置“isLibrary”并将库项目添加到 Eclipse 中的构建路径,并且我在应用程序的 pom.xml
中具有以下依赖项:
<dependency>
<groupId>cocos2d_android</groupId>
<artifactId>cocos2d_android</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
我以为这会解决这个问题,但是当我构建时,这个库似乎没有包含在内。我知道这一点是因为当我启动一个 Activity,SimpleGame
,引用 cocos2d 源中的一个类时,Activity 结束,我在 DDMS 中得到这个堆栈跟踪:
E/AndroidRuntime(10621): 致命异常: main
E/Android运行时(10621): java.lang.NoClassDefFoundError: org.cocos2d.opengl.CCGLSurfaceView
E/AndroidRuntime(10621): 在 com.xyz.game.SimpleGame.onCreate(SimpleGame.java:22)
...
我在寻找两件事:
1) 一种查看某个类/jar/任何东西是否打包到我的 apk 中的可靠方法,因为现在在我的应用程序中达到这一点的步骤又长又复杂
2) 主应用程序或库项目的 Manifest 或 pom.xml 中似乎缺少某些内容 - 需要向 Maven 发出信号以选择另一个项目的内容 - 它是什么?
我正在使用插件的 Maven 3.0.4 和 3.0.0-alpha-13,为 8 级及更高级别构建。
最佳答案
1) a reliable way to see if a certain class/jar/whatever was packaged up into my apk, as the steps to get to this point in my app are long and complicated right now
从命令行构建项目(即 mvn clean install),maven 将在构建的每个阶段/目标期间输出详细日志,在 dex 目标中,您可以看到如下内容:
[INFO] --- android-maven-plugin:3.1.1:dex (default-dex) @ myproject ---
[INFO] C:\Program Files\Java\jdk1.6.0_21\jre\bin\java [-Xmx1024M, -jar, C:\Progr am Files\Android\android-sdk-r16\platform-tools\lib\dx.jar, --dex, --output=C:\workspace\myproject\target\classes.dex, C:\workspace\myproject\target\classes, C:\maven\repository\cocos2d_android\cocos2d_android\1.0.0-SNAPSHOT\cocos2d_android-1.0.0-SNAPSHOT.apklib, C:\maven\repository\com\google\code\gson\gson\1.7.1\gson-1.7.1.jar, ... ...]
Android 库项目实际上被 dex-ed 为 cocos2d_android-1.0.0-SNAPSHOT.apklib 和一些其他常规的 jar 库存档。
2) Something in the Manifest or pom.xml for either the main app or the library project seems to be missing - something needed to signal to Maven to pick up this other project - what is it?
它是 ApkLib,它只是 Android 库项目(src/、res/、AndroidManifest.xml 等)的 zip 存档。我们通常会创建/实现自己的 Android Library Project,并将依赖的 Android Project 作为多模块 maven 项目,但是,如果您需要引用其他开发人员编写的 Android Library Project,则没有必要这样做。感谢开发者,android-maven-plugin 已经支持非 Maven Android 库项目,查看 Compatible with non-Maven Android Library Projects :
The generated .apklib file will have the layout of a standard Android/Eclipse library project. This means that regardless of your Maven layout, the layout inside the .apklib file will be that source code is in "src/" instead of "src/main/java/", but still interpreted correctly when used in an Android/Maven application project. This is to be compatible with non-Maven developers' library projects, which is important to grow the Android developer community.
Use other non-Maven developers' libraries
It also means we can take any external Android library project zip file (from non-Maven developers) and do mvn install:install-file ... on it and simply start using it as a dependency.
Share your .apklib with non-Maven developers
To share your .apklib file with a non-Maven developer, they will probably feel more comfortable if you rename it to .zip. They can then simply unpack it in a directory and use it from there.
所以解决方法是:
将您的 Android Library 项目正确打包到 zip 存档中,然后将其重命名为 something.apklib。
使用 mvn install:install-file 将 something.apklib 安装到您的 Maven 本地存储库中。
在任何需要依赖库的 Android 项目中,只需使用:
<dependency> <groupId>cocos2d_android</groupId> <artifactId>cocos2d_android</artifactId> <version>1.0.0-SNAPSHOT</version> <type>apklib</type> </dependency>
查看 Samples在 android-maven-plugin 网站上查看如何正确使用 apklib。
关于android - 添加 Eclipse "Android Library"项目并通过 Maven 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9931039/