android - 在 Run As -> Android Application 上调用 Eclipse 中的 "Maven Project Builder"(或手动)

标签 android eclipse maven

使用Eclipse和Maven搭建Android开发环境

我正在开发一个使用 Maven 作为构建工具的 Android 项目,并且一段时间以来一直在研究 Eclipse、Android ADT、m2eclipse、Maven Android 插件、Maven Integration for Android 开发工具和 Subclipse 的配置,但无法让它正常工作。也就是说,要么构建时间过长,要么项目没有按应有的方式重建和部署在模拟器上。

当前配置状态

目前,我大致做了以下操作,结果如下:

  • 从 Ubuntu 11.04 的默认存储库安装了 Eclipse Galileo (3.5.2)。
  • 安装了上述 Eclipse 插件和 Android SDK。
  • 通过 从 SCM 查看 Maven 项目 导入项目。
  • 为项目禁用所有构建器,Maven Project Builder 除外。
  • 确保选中自动构建

保存文件

Maven Project Builder 被调用并运行:

  • aapt [package, -m, -J, .../application/target/generated-sources/r, -M, .../application/AndroidManifest.xml, -S, .../application/target/generated-sources/combined-resources/res, -A, .../application/assets, -I, .../android-7/android.jar]
  • dx [--dex, --output=.../application/target/classes.dex, .../application/target/android-classes]
  • aapt [package, -f, -M, .../application/AndroidManifest.xml, -S, .../application/target/generated-sources/combined-resources/res, -A, .../application/target/generated-sources/combined-assets/assets, -I, .../android-7/android.jar, -F, .../target/xxx-android-project-1.0-SNAPSHOT.ap_]

Time taken: ~15 seconds, during which:

  • Eclipse is blocked for subsequent user operations, such as Save.
  • One CPU core is busy and the system gets sluggish.

On Run As -> Android Application

The application is installed and launched correctly within ~10 seconds.

Output in Console (Android):

Android Launch!
adb is running normally.
Performing com.xxx.android.activity.LoginActivity activity launch
Automatic Target Mode: Preferred AVD 'xxx_test_device' is available on emulator 'emulator-5554'
Uploading xxx-android-project.apk onto device 'emulator-5554'
Installing xxx-android-project.apk...
Success!
Starting activity com.xxx.android.activity.LoginActivity on device emulator-5554
ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.xxx.android/.activity.LoginActivity }

What I would like to happen

On file save

Only the file being saved should be compiled and placed into the configured output folder, instantly quick.

On Run As -> Android Application

  • Maven Project Builder is invoked, which performs the lengthy aapt and dx process, which is currently performed on every file save.
  • The application is installed and launched on the emulator.

Questions

  • How do I achieve what is described above?
  • Would it be possible to make Maven Project Builder run just before Run As -> Android Application but not on every file save? How?

Other approaches

I have tried to disable Build Automatically, enable all Builders and then run Project -> Build Project on the project in question, but then nothing happens and when I do Run As -> Android Application the code changes are not present.

I have tried to disable the Maven Project Builder and enable all other Builders, enable Build Automatically, but after saving the file I see this in the Console (Android):

Refreshing resource folders.
Starting incremental Pre Compiler: Checking resource changes.
Nothing to pre compile!
Starting incremental Package build: Checking resource changes.
Starting full Post Compiler.
Refreshing resource folders.
Starting incremental Pre Compiler: Checking resource changes.
Nothing to pre compile!

Run As -> Android Application 上,应用程序崩溃并出现以下错误:

java.lang.RuntimeException: Unable to instantiate application com.xxx.android.XXXApplication: java.lang.ClassNotFoundException: com.xxx.android.XXXApplication in loader dalvik.system.PathClassLoader@44bfe130

相关问题

Android compilation is slow (using Eclipse).

解释了为什么 dx 过程如此冗长,并建议从命令行使用 Ant 手动构建,并且只在必要时才构建。我实际上尝试过这个,但无法让它与 Maven 依赖项一起工作,即使在使用 Maven 插件将所有依赖项 JAR 复制到 libs/ 时也是如此。

For a maven project in eclipse can I configure menu option Project/Clean to invoke mvn clean?

解释了如何在通过 Eclipse 清理项目后运行特定目标,但我不想在模拟器上每次安装之前清理项目。

长话短说

我希望 Eclipse 仅在我执行 Run AsMaven Project Builder 运行 aaptdx 进程em> -> Android 应用程序,而不是在保存文件时。然后应在模拟器中启动该应用程序。

最佳答案

用于 Android 开发工具的 Maven 集成的新版本速度更快,有望在下周左右解决您的一些问题。

关于android - 在 Run As -> Android Application 上调用 Eclipse 中的 "Maven Project Builder"(或手动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6726564/

相关文章:

android - list 合并失败:使用cardview 25.3.1的图书馆,我的应用使用25.00.alpha1

android - 用于移动应用程序测试的 Selenium 插件或用于移动应用程序测试的任何其他更好和合适的工具

eclipse - 无法访问您的 SonarQube 服务器之一。请检查您的连接设置

java - Maven Eclipse Tomcat ClassNotFoundException 异常

java - 将.SQLJ迁移到netbeans中的maven项目

android - 生产中的谷歌地图

android - 如何对特定的 JUnit 测试用例执行 @After?

eclipse - Jersey + Spring 3 + Maven 3 + Tomcat 7 @Component 类中的 @Resource 始终为 null

android - ADT Logcat 过滤器消失并停止工作

NetBeans + Maven、类路径