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.
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.
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
You need to create a system variable for ANDROID_HOME, not set it in your PATH.
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:
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With