maven android development configuration

Download required tools, command line tools for android sdk.

  • The official download address can be found here at  http://develop.android.com  , just download the command line tool (Android Studio is relatively large and comes with an IDE)
  • Set some environment variables
    • ANDROID_HOMENeed to point to the upper directory of the decompressed tools (required)
    • USE_SDK_WRAPPERAs long as this variable is not empty, you can use text content like yes (optional)

Upgrade the JDK (strictly speaking, only the JRE needs to be upgraded in the case of using only)

When running $ANDROID_HOME/toolsthe android command line script, an exception such as Unsupported class version number will occur when the JRE does not support it. Cut down the appropriate JDK according to the corresponding version number.

windows

After downloading the corresponding jdk, all the way to next

linux

After downloading the corresponding jdk, if you want to make it more elegant

  • You can refer to the .jinfo file under /usr/lib/jvm to write a similar one (note to remove non-existing files, such as mozilla-plugin.so)
  • Add alternative links to all the files in the .jinfo just written, and use the update-alternatives --install command
  • Select the jdk version to use with update-java-alternatives

mac

After downloading the corresponding version, go all the way to next

Use maven-android-sdk-deployer to install the corresponding version of the tool.

  • maven-android-sdk-deployer address[email protected]:simpligility/maven-android-sdk-deployer.git
  • Install maven-android-sdk-deployer using the android version number, for example, use mvn clean install -P 4.4 to install the corresponding android 4.4
  • Follow the error prompt in the previous step to make up the missing items. For example, if platforms/android-19 is missing,
    • Use under linux/mac $ANDROID_HOME/tools/bin/sdkmanager 'platforms;android-19'
    • Use under windows  %ANDROID_HOME%\tools\bin\sdkmanager "platforms;android-19" (quotes are important)
  • After completing all the things as required, a few things are needed to run a complete maven android project installation and running process:
    • emulator
    • build-tools
    • system-images
    • platform-tools

Prepare the ANDROID simulator runtime environment

Make an AVD (Android Virtual Device?)

use command

$ANDROID_HOME/tools/android create avd --name 'android-4.4' --package 'system-images;android-19;default:x86' --device 32 --sdcard 20480M

This will create an AVD named android-4.4 under $HOME/.android/avd, the device model id is 32, and an AVD with a 2G sdcard running on the android-19:x86 image will be created.

run the emulator

Use any of the following commands, fill in the parameters according to the actual situation

  • $ANDROID_HOME/tools/emulator @android-4.4
  • $ANDROID_HOME/tools/emulator -avd android-4.4

Create maven android project

Using the command  mvn archetype:generate -Dfilter=android-quickstart should have two optional items

1.  com.github.destinyd.android.achetypes:android-quickstart
2.  de.akquinet.android.archetypes:android-quickstart
  • The second one uses a higher version of the android-maven-plugin. Choose one of the top and bottom.
  • Modify the pom.xml in the project root directory, change the version number of the platform to be used correctly, or delete and add an android.sdk.platform to the properties, and fill in the corresponding number. For example, if the compilation and simulation environment of android 4.4 was installed before, you can use the 19 in platforms;android-19
  • use command mvn clean package android:undeploy android:deploy android:run
  • If you need to view the logs, you can use $ANDROID_HOME/platform-tools/adb logcat -s 'HelloAndroidActivity'such a command to view only the logs of HelloAndroidActivity.

In the case of a real machine, you can connect the real machine to the development machine, omitting the preparation of the ANDROID simulator.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326117941&siteId=291194637