maven-android-plugin 客官°小女子只卖身不卖艺 2022-04-10 05:23 187阅读 0赞 原文:http://code.google.com/p/maven-android-plugin/wiki/GettingStarted Documentation in book form is available with the Android chapter of the free book Maven: The complete Reference in HTML and PDF format:[http://www.sonatype.com/books/mvnref-book/reference/android-dev.html][http_www.sonatype.com_books_mvnref-book_reference_android-dev.html] # Getting Started # ## Prerequisites ## 1. JDK 1.6+ installed as required for Android development 2. Android SDK (r17 or later, latest is best supported) installed, preferably with all platforms, see [http://developer.android.com/sdk/index.html][http_developer.android.com_sdk_index.html] 3. Maven 3.0.3+ installed, see [http://maven.apache.org/download.html][http_maven.apache.org_download.html] 1. Set environment variable ANDROID\_HOME to the path of your installed Android SDK and add $ANDROID\_HOME/tools as well as $ANDROID\_HOME/platform-tools to your $PATH. (or on Windows %ANDROID\_HOME%\\tools and %ANDROID\_HOME%\\platform-tools). 2. MacOS users: Note that for the path to work on the commandline and in IDE's started by launchd you have to set it in /etc/launchd.conf and NOT in .bashrc or something else ## Recommended: Test your development environment ## If you want to test your environment, download and run the [Samples][]\*. ## Create your own Android application (apk) easily ## The easiest way to create you own Android application project for Maven, is to use these Maven Archetypes: [https://github.com/akquinet/android-archetypes/wiki][https_github.com_akquinet_android-archetypes_wiki] ## Create your own Android application (apk) manually ## Alternatively, these are the steps to create an Android project manually: 1. > * Create a project using the android tool: > > * [http://developer.android.com/guide/developing/other-ide.html\#CreatingAProject][http_developer.android.com_guide_developing_other-ide.html_CreatingAProject] > * Create a pom.xml in your project, using the sample helloflashlight/pom.xml as template. (See [Samples][]\*.) > > * Make these changes: > * Change <groupId>, <artifactId> and <name> to your own. (Some tips: [Maven - Guide to Naming Conventions][]) > * Set a <version> tag for your project, for example <version>0.1.0-SNAPSHOT</version>. > * Update the Android dependency to the platform version you want to be compatible with as a minimum: <dependency> <groupId>com.google.android</groupId> <artifactId>android</artifactId> <version>1.5_r4</version> <scope>provided</scope> </dependency> Check [http://search.maven.org/\#search%7Cga%7C1%7Ca%3A%22android%22][http_search.maven.org_search_7Cga_7C1_7Ca_3A_22android_22] for available versions. Use one of these depending on the platform version you are developing against. * In the android-maven-plugin configuration, set the correct platform number which corresponds to the version you declared for the android dependency, for example: <platform>7</platform>. You can use API level (e.g. 7) or platform version (e.g. 2.1) > * You won't need these files/directories with Android Maven Plugin, so you can remove them: > > rm -r bin build.xml build.properties libs > > > *The default.properties file is currently not used by Android Maven Plugin, but will be, so leave that in place for now.default.properties and the gen folder are used by the ADT plugin in Eclipse, if you use that. > > > > (Also leave the "test" folder for now. You can later move it out to its own project. If you want, you can then look at theapidemos-15-instrumentationtest sample project.)* > * To build your apk, simply: > > mvn clean install > * To deploy your apk to the connected device: > > mvn android:deploy *See [TipsAndTricks][] for instruction on how to use the android plugin name even when not in a android project directory.* Notes: 1. Do not put tests in src/test/java that you want to be run by the Android Maven Plugin. If you put your tests there, Maven runs them as normal JUnit tests in the JVM, with the JAR files that are accessible on the classpath, which includes the android.jar. Because the android.jar only contains empty methods that throw exceptions, you get exceptions of the form java.lang.RuntimeException: Stub!. Instead, the tests need to go in src/main/java, where they will not be run by Maven as tests during compilation, but will be included in the apk and deployed and run on the device (where the android.jar has method implementations instead of stubs). 2. If you have JUnit tests that don't call any Android APIs (directly or transitively), put them in src/test/java so JUnit runs them locally and more quickly than if run on the device. 3. Make sure the Android Maven goal is set to <goal>jar-no-fork</goal> instead of <goal>test-jar-no-fork</goal>. Do this even for projects that only contain tests. ## Run instrumentation tests on device ## Check out the apidemos-15-instrumentationtest project in [Samples][]\*. You can create a project like that, by moving your "test" folder out and renaming it to for example "myproject-instrumentationtest". Then rearrange the folders within it like above, and use the pom.xml from apidemos-15-instrumentationtest as template. For a sample project with more feature features like jarsigning, zipaligin, release profile and proguard look at the morseflash example. ## More documentation ## There is some more documentation on the [Documentation][] page. ### (\*) Samples ### Always use the version of samples linked from the [Samples][] page, so that you get a usable version of its configuration. [http_www.sonatype.com_books_mvnref-book_reference_android-dev.html]: http://www.sonatype.com/books/mvnref-book/reference/android-dev.html [http_developer.android.com_sdk_index.html]: http://developer.android.com/sdk/index.html [http_maven.apache.org_download.html]: http://maven.apache.org/download.html [Samples]: http://code.google.com/p/maven-android-plugin/wiki/Samples [https_github.com_akquinet_android-archetypes_wiki]: https://github.com/akquinet/android-archetypes/wiki [http_developer.android.com_guide_developing_other-ide.html_CreatingAProject]: http://developer.android.com/guide/developing/other-ide.html#CreatingAProject [Maven - Guide to Naming Conventions]: http://maven.apache.org/guides/mini/guide-naming-conventions.html [http_search.maven.org_search_7Cga_7C1_7Ca_3A_22android_22]: http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22android%22 [TipsAndTricks]: http://code.google.com/p/maven-android-plugin/wiki/TipsAndTricks [Documentation]: http://code.google.com/p/maven-android-plugin/wiki/Documentation
还没有评论,来说两句吧...