android maven plugin does not get ANDROID_HOME env variable in Eclipse

前端 未结 9 2178
[愿得一人]
[愿得一人] 2021-02-20 11:23

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.pl

相关标签:
9条回答
  • 2021-02-20 11:58

    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.

    0 讨论(0)
  • 2021-02-20 12:01

    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

    0 讨论(0)
  • 2021-02-20 12:03

    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"

    0 讨论(0)
  • 2021-02-20 12:04

    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.

    0 讨论(0)
  • 2021-02-20 12:06

    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.

    0 讨论(0)
  • 2021-02-20 12:07

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

    0 讨论(0)
提交回复
热议问题