maven android plugin:No Android SDK path could be found

此生再无相见时 提交于 2019-12-03 06:08:53

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.

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"

Android_kalai

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!