开发者

Invoke "Maven Project Builder" in Eclipse on Run As -> Android Application (or manually)

开发者 https://www.devze.com 2023-03-21 09:57 出处:网络
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, m2eclips

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 开发者_C百科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.


A new version of the Maven Integration for Android Development Tools which is faster and should hopefully resolve some of your issues is out in the next week or so.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消