Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 584
Mert Buran Avatar asked Jul 10 '12 14:07

Mert Buran


7 Answers

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.

like image 160
gauchofunky Avatar answered Oct 13 '22 18:10

gauchofunky


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

like image 29
tomrozb Avatar answered Oct 13 '22 19:10

tomrozb


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

like image 33
nmw Avatar answered Oct 13 '22 19:10

nmw


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.

like image 32
leebeckman Avatar answered Oct 13 '22 17:10

leebeckman


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)

like image 28
David T. Avatar answered Oct 13 '22 17:10

David T.


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.

like image 37
Ivan Avatar answered Oct 13 '22 18:10

Ivan


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"

like image 32
Benny Neugebauer Avatar answered Oct 13 '22 17:10

Benny Neugebauer