android maven plugin does not get ANDROID_HOME env variable in Eclipse

老子叫甜甜 提交于 2019-12-04 03:09:58

You need to create a system variable for ANDROID_HOME, not set it in your PATH.

Ensure your Android SDK installation contains the libraries for the same API version you have configured on your pom.xml.

For example, if your configuration XML looks like:

<plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    ...
    <configuration>
        <sdk>
            <path>${env.ANDROID_HOME}</path>
            <platform>8</platform>
        </sdk>
        ...
    </configuration>
</plugin>

then you should verify with Android SDK Manager (or directly checking on your filesystem: $ANDROID_HOME/platforms) that you have SDK API 8 installed. Of course you can also change your pom.xml to match the library installed.

tomrozb

If you are using Linux, exporting the ANDROID_HOME in the .bashrc may not work.

export ANDROID_HOME=/home/toro/etc/android-sdk-linux

For me it works only when I export ANDROID_HOME in the /etc/environment file like this:

ANDROID_HOME=/home/toro/etc/android-sdk-linux

You have to restart the computer to get it works.

You simply have to log out, and log in again for the environment variable to be applied system-wide. Optionally, you could just source it locally to test it out before you do that: $source /etc/environment

Setting an ANDROID_HOME variable in your .bashrc or whatever will work, but remember to export that variable so that it is available to subprocesses. Setting ANDROID_HOME with the other methods suggested here will get you through some initial errors, but without ANDROID_HOME exported your build will probably fail at some point.

on your command line, run:

mvn clean install -- Dandroid.sdk.path="/Applications/Android Studio.app/sdk/"

none of the other methods really worked. (setting ANDROID_HOME doesn't do anything)

Another way is to set the environment variable into run configuration for pom.xml.

Go to Run Configurations menu, select the Run configuration used for your project pom.xml and select the Environment Tab and select "New", then insert:

  • ANDROID_HOME into name Field
  • path to your sdk into value field

It works, and in that way the Variable is set only when you launch the maven configuration for selected projec, and you can also set different path for different projects, and you don't need to change your .bashrc. It work also in windows.

From the documentation

You may configure it in the android-maven-plugin configuration section in the pom.xml file using <sdk><path>...</path></sdk> or <properties><android.sdk.path>...</android.sdk.path></properties> or on command-line using -Dandroid.sdk.path=... or by setting environment variable ANDROID_HOME.

Solution 1

I have defined an Android SDK system variable called ANDROID_SDK (instead of ANDROID_HOME) and referenced it in my pom.xml this way:

  <groupId>...</groupId>
  <artifactId>...</artifactId>
  <version>...</version>
  <packaging>apk</packaging>
  <name>...</name>
  <description>...</description>

  <properties>
    <android.sdk.path>${env.ANDROID_SDK}</android.sdk.path>
    ...
  </properties>

Solution 2

As an alternative you can also configure it in the android-maven-plugin section:

<plugin>
<extensions>true</extensions>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android-maven-plugin.version}</version>
<configuration>
  <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
  <assetsDirectory>${project.basedir}/assets</assetsDirectory>
  <resourceDirectory>${project.basedir}/res</resourceDirectory>
  <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
  <sdk>
    <android.sdk.path>${env.ANDROID_SDK}</android.sdk.path>
    <platform>16</platform>
  </sdk>
  <undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
</plugin>

Solution 3

As a third option you can set the SDK from the command line passing an argument to Maven:

mvn clean install -Dandroid.sdk.path="C:\\Program Files (x86)\\Android\\android-sdk"

You need to set the Android Development Tools SDK Location path in Eclipse: click on Window -> Preferences and select Android. The SDK Location can be set under Android preferences.

Create a file called local.properties in your root directory of your project.

With the contents;

sdk.dir=c:\\path\\to\\android-sdk
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!