If you are an Android application developer who wants to start with a skeleton Android project, you can use the android-quickstart
archetype developed by akquinet, which is shown in the following code:
$ mvn archetype:generate -B -DarchetypeGroupId=de.akquinet.android.archetypes -DarchetypeArtifactId=android-quickstart -DarchetypeVersion=1.0.4 -DgroupId=com.packt.samples -DartifactId=my-android-app -Dversion=1.0.0
This command produces the following skeleton project:
my-android-app |-pom.xml |-AndroidManifest.xml |-android.properties |-src/main/java/com/packt/samples/HelloAndroidActivity.java |-res/drawable-hdpi/icon.png |-res/drawable-ldpi/icon.png |-res/drawable-mdpi/icon.png |-res/layout/main.xml |-res/values/strings.xml |-assets
To build the Android skeleton project, run the following Maven command from the my-android-app
directory:
$ mvn clean install -Dandroid.sdk.path=/path/to/android/sdk
The previous command looks straightforward, but based on your Android SDK version, you might encounter certain issues. Some of the possible issues and solutions are as follows:
android.sdk.path
argument:[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:maven-android-plugin:2.8.3:generate-sources (default-generate-sources) on project my-android-app: Execution default-generate-sources of goal com.jayway.maven.plugins.android.generation2:maven-android-plugin:2.8.3:generate-sources failed: Path "/Users/prabath/Downloads/adt-bundle-mac-x86_64-20140702/platforms" is not a directory.
The path should point to the Android sdk
directory, and right under it, you should find the platforms
directory. By setting android.sdk.path
to the correct path, you can avoid this error.
android-quickstart
archetype assumes the Android platform to be 7. You will see the following error if the Android platform installed in your local machine is different from this:[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:maven-android-plugin:2.8.3:generate-sources (default-generate-sources) on project my-android-app: Execution default-generate-sources of goal com.jayway.maven.plugins.android.generation2:maven-android-plugin:2.8.3:generate-sources failed: Invalid SDK: Platform/API level 7 not available.
To fix this, open the pom.xml
file and set the right platform version with <sdk><platform>20</platform></sdk>
.
android-quickstart
archetype assumes that the aapt
tool is available under sdk/platform-tools
directory. However, with the latest sdk
, it has been moved to sdk/build-tools/android-4.4W
, and you will get the following error:[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:maven-android-plugin:2.8.3:generate-sources (default-generate-sources) on project my-android-app: Execution default-generate-sources of goal com.jayway.maven.plugins.android.generation2:maven-android-plugin:2.8.3:generate-sources failed: Could not find tool 'aapt'.
To fix the error, you need to update the maven-android-plugin
version and artifactId
.
Open up the pom.xml
file inside the my-android-app
directory and find the following plugin configuration. Change artifactId
to android-maven-plugin
and version
to 4.0.0-rc.1
, which is shown as follows:
<plugin> <groupId> com.jayway.maven.plugins.android.generation2 </groupId> <artifactId>android-maven-plugin</artifactId> <version>4.0.0-rc.1</version> <configuration></configuration> <extensions>true</extensions> </plugin>
Once the build is completed, android-maven-plugin
will produce the my-android-app-1.0.0.apk
and my-android-app-1.0.0.jar
artifacts inside the target
directory.
To deploy the skeleton Android application (apk) to the connected device, use the following Maven command:
$ mvn android:deploy -Dandroid.sdk.path=/path/to/android/sdk
18.118.137.67