Mert Buran
Mert Buran

Reputation: 3017

android maven plugin does not get ANDROID_HOME env variable in Eclipse

i'm working on an Android app project and it is a Maven project. when i try to run as "maven install" this is what i get:

"Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.1.1:generate-sources (default-generate-sources) on project android-client: No Android SDK path could be found. You may configure it in the plugin configuration section in the pom file using ... or ... or on command-line using -Dandroid.sdk.path=... or by setting environment variable ANDROID_HOME -> [Help 1]"

if i hardcode my android_home path into pom.xml,it works fine but we use git and everyone may have different paths for android_home.why doesn't android-maven-plugin get env variable in eclipse?

android_home env variable is in my PATH. i wrote ${env.ANDROID_HOME} in my pom.xml but it still didn't work.

strangely,if i use terminal (mvn install) to run as maven install,it works!

actually this is quite optional problem for me but still i want to know why this plugin does not work in Eclipse.

Upvotes: 10

Views: 20966

Answers (9)

Benny Code
Benny Code

Reputation: 54832

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"

Upvotes: 1

tomrozb
tomrozb

Reputation: 26261

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

Upvotes: 5

David T.
David T.

Reputation: 23379

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)

Upvotes: 3

Ivan
Ivan

Reputation: 4234

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.

Upvotes: 1

leebeckman
leebeckman

Reputation: 136

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.

Upvotes: 3

gauchofunky
gauchofunky

Reputation: 527

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.

Upvotes: 5

Daniel  Magnusson
Daniel Magnusson

Reputation: 9674

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

With the contents;

sdk.dir=c:\\path\\to\\android-sdk

Upvotes: 0

Ricardo Gladwell
Ricardo Gladwell

Reputation: 3785

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.

Upvotes: 0

nmw
nmw

Reputation: 6764

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

Upvotes: 4

Related Questions