调用“Maven项目构建器”在Eclipse中运行As - > Android应用程式(或手动) [英] Invoke "Maven Project Builder" in Eclipse on Run As -> Android Application (or manually)

查看:162
本文介绍了调用“Maven项目构建器”在Eclipse中运行As - > Android应用程式(或手动)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Eclipse和Maven安装Android开发环境



我正在使用Maven作为构建工具进行Android项目,并且一直在使用Eclipse的配置, Android ADT,m2eclipse,Maven Android插件,Maven Integration for Android开发工具和Subclipse一段时间,但无法让它工作可以接受。也就是说,构建时间不必要地长,或者项目不会在仿真器上重建并部署在应用程序中。



当前配置状态



目前,我已经做了大概以下的结果,如下所述:




  • 安装的Eclipse Galileo (3.5.2)从Ubuntu 11.04的默认存储库。

  • 安装了上述Eclipse插件和Android SDK。

  • 导入项目通过

  • 禁用项目的所有Builders,除了Maven项目构建器。

  • 确保自动生成已被检查。



文件保存



Maven Project Builder 被调用并运行:




  •  aapt [package,-m,-J,... / application / target / generated-sources / r,-M,... / application / AndroidManifest.xml,-S,... / application / targ et / 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 / generate-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 _] 




:〜15秒,在此期间:




  • Eclipse被阻止用于后续用户操作,例如保存。




运行方式 - > Android应用程序



应用程序在〜10秒内正确安装并启动。



控制台(Android)中的输出:

 Androi d启动! 
adb正常运行。
执行com.xxx.android.activity.LoginActivity活动启动
自动目标模式:首选AVD'xxx_test_device'可用于模拟器'emulator-5554'
上传xxx-android-project.apk到设备'emulator-5554'
安装xxx-android-project.apk ...
成功!
启动活动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}



我想要发生什么



文件保存



只有正在保存的文件才能被快速编译并配置到配置的输出文件夹中。



运行方式 - > Android应用程序




  • Maven Project Builder 被调用,它执行长时间的 aapt dx 进程,目前每个文件都保存。

  • 应用程序已安装并启动模拟器。



问题




  • 是否实现了上述内容?

  • 是否可以让Maven Project Builder在运行方式 - > Android之前运行应用程序,但不是每个文件保存?如何?



其他方法



我试图禁用自动构建,启用所有Builders,然后在有问题的项目上运行项目 - > 构建项目,但是没有任何反应,当我执行运行作为 - > Android应用程序代码更改不存在。



我已经尝试禁用Maven项目构建器并启用所有其他Builders,启用自动构建,但保存文件后,我在控制台(Android)中看到:

 刷新资源文件夹。 
启动增量预编译器:检查资源更改。
没有预编译!
启动增量包构建:检查资源更改。
启动完整的Post Compiler。
刷新资源文件夹。
启动增量预编译器:检查资源更改。
没有预编译!

而在运行方式 - > Android应用程序应用程序崩溃与此错误:

  java.lang.RuntimeException:无法实例化应用程序com.xxx.android.XXXApplication: java.lang.ClassNotFoundException:loader中的com.xxx.android.XXXApplication dalvik.system.PathClassLoader@44bfe130 



相关问题



Android编译很慢(使用Eclipse)



解释为什么 dx 进程如此漫长,并建议在命令行中使用Ant仅在需要时手动构建。我实际上尝试过这个,但是无法使它与Maven依赖关系使用,即使使用Maven插件将所有依赖关系JAR复制到 libs /

$ a bref = b $ b -clean-to-invok>对于eclipse中的maven项目,我可以配置菜单选项Project / Clean来调用mvn clean吗?



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



TL; DR



我希望Eclipse仅在我执行 Maven Project Builder 时才运行 aapt dx 进程>运行方式 - > Android应用程序,而不是在保存文件时。应用程序应该在仿真器中启动。

解决方案

迁移到Gradle和支持Gradle的IDE,如IntelliJ或Android Studio 。


Setup Android develop environment using Eclipse and Maven

I'm working on an Android project with Maven as build tool, and been playing around with the configuration of Eclipse, Android ADT, m2eclipse, Maven Android Plugin, Maven Integration for Android Development Tools, and Subclipse for a while now, but can't get it to work acceptable. That is, either the build time is unnecessarily long or the project is not rebuilt and deployed on the emulator as it should be.

Current configuration state

At the moment, I have done approximately the following with the result described below:

  • Installed Eclipse Galileo (3.5.2) from the default repositories of Ubuntu 11.04.
  • Installed the Eclipse plugins mentioned above and the Android SDK.
  • Imported the project through Check out Maven Projects from SCM.
  • Disabled all Builders for the project, except Maven Project Builder.
  • Made sure Build Automatically is checked.

On file save

Maven Project Builder is invoked and runs:

  • 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!

And on Run As -> Android Application the application crashes with this error:

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

Related questions

Android compilation is slow (using Eclipse).

Explains why the dx process is so lengthy and suggests using Ant from the command line to build manually and only when necessary. I actually tried this, but couldn't get it to work with the Maven dependencies, even when copying all dependency JARs to libs/ using a Maven plugin.

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

Explains how to run specific goals after cleaning the project through Eclipse, but I would not like to clean the project before every installation on the emulator.

TL;DR

I would like Eclipse to run the aapt and dx processes through Maven Project Builder only when I do Run As -> Android Application, and not when saving a file. The application should then be launched in the emulator.

解决方案

Migrate to Gradle and an IDE with Gradle support such as IntelliJ or Android Studio.

这篇关于调用“Maven项目构建器”在Eclipse中运行As - > Android应用程式(或手动)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆