maven android plugin:No Android SDK path could be

2020-06-03 02:33发布

问题:

I use the maven-android-plugin version 3.3.2. When I try to build my android project I have the following exception:

org.apache.maven.plugin.MojoExecutionException: No Android SDK path could be found. You may configure it in the plugin configuration section in the pom 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

However environment variable ANDROID_HOME is set to android sdk path.

Can you please help me?

回答1:

It sounds like, while the env var is available on the shell you run, it isn't available on the shell Maven runs.

Regardless, instead of working around it, it's best to create a settings file with the property set. A minimal one would look like this (writing off the top of my head, as I don't have my settings file available now) :

<settings>
  <profiles>
    <profile>
        <id>android-settings</id>
        <properties>
            <android.sdk.path>/path/to/android/sdk</android.sdk.path>
        </properties>
    </profile>
  </profiles>
  <activeProfiles>
        <activeProfile>android-settings</activeProfile>
  </activeProfiles>
</settings>

Throw it into your .m2 folder or set it via Eclipse in Window->Preferences...->Maven->User Settings.



回答2:

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"



回答3:

Yes i solved this issue.By adding settings.xml file in ~/.m2 folder

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <profiles>
        <profile>
            <id>android</id>
            <properties>
                <android.sdk.path>
                  ANDROID SDK PATH
                </android.sdk.path>
            </properties>
        </profile>
    </profiles>
    <activeProfiles> <!--make the profile active all the time -->
        <activeProfile>android</activeProfile>
    </activeProfiles> 
</settings>

and open your android-bootstrap-master app and open pom.xml file and check the following line

<sdk>
    <platform>16</platform>
</sdk>

16 is the currently installed or not sdk level



回答4:

The easiest way is to set export ANDROID_HOME=pathToAndroidSdk right from the target deploy repository.

Variable will be set only for current shell and all processes started from current shell.