Java maven android 插件:找不到 Android SDK 路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19133913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 14:24:19  来源:igfitidea点击:

maven android plugin:No Android SDK path could be found

javaandroidmavenm2eclipse

提问by Naja

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

我使用的是maven-android-plugin3.3.2 版本。当我尝试构建我的 android 项目时,出现以下异常:

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

org.apache.maven.plugin.MojoExecutionException: 找不到 Android SDK 路径。您可以在 pom 文件的插件配置部分中使用<sdk><path>...</path></sdk><properties><android.sdk.path>...</android.sdk.path></properties>或在命令行中使用-Dandroid.sdk.path=...或通过设置环境变量来配置它ANDROID_HOME

However environment variable ANDROID_HOMEis set to android sdk path.

但是环境变量ANDROID_HOME设置为android sdk路径。

Can you please help me?

你能帮我么?

采纳答案by miko?ak

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

听起来,虽然 env var 在您运行的 shell 上可用,但它在 Maven 运行的 shell 上不可用。

Regardless, instead of working around it, it's best to create a settings filewith 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 .m2folder or set it via Eclipse in Window->Preferences...->Maven->User Settings.

将其放入您的.m2文件夹或通过 Eclipse 在Window-> Preferences...-> Maven-> 中进行设置User Settings

回答by Android_kalai

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

是的,我解决了这个问题。通过在 ~/.m2 文件夹中添加 settings.xml 文件

<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

并打开您的 android-bootstrap-master 应用程序并打开 pom.xml 文件并检查以下行

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

16 is the currently installed or not sdk level

16是当前安装与否的sdk级别

回答by Benny Neugebauer

From the documentation

从文档

You may configure it in the android-maven-pluginconfiguration section in the pom.xmlfile 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.

您可以android-maven-pluginpom.xml文件的配置部分中使用<sdk><path>...</path></sdk><properties><android.sdk.path>...</android.sdk.path></properties>或在命令行中使用-Dandroid.sdk.path=...或通过设置环境变量来配置它ANDROID_HOME

Solution 1

解决方案1

I have defined an Android SDK system variable called ANDROID_SDK(instead of ANDROID_HOME) and referenced it in my pom.xmlthis way:

我定义了一个名为ANDROID_SDK(而不是ANDROID_HOME)的 Android SDK 系统变量,并以我的pom.xml方式引用它:

  <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

解决方案2

As an alternative you can also configure it in the android-maven-pluginsection:

作为替代方案,您还可以在以下android-maven-plugin部分进行配置:

<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

解决方案3

As a third option you can set the SDK from the command line passing an argument to Maven:

作为第三个选项,您可以从命令行设置 SDK,将参数传递给 Maven:

mvn clean install -Dandroid.sdk.path="C:\\Program Files (x86)\\Android\\android-sdk"

mvn clean install -Dandroid.sdk.path="C:\\Program Files (x86)\\Android\\android-sdk"

回答by Ardi

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

最简单的方法是export ANDROID_HOME=pathToAndroidSdk从目标部署存储库设置 正确。

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

变量将只为当前 shell 和从当前 shell 启动的所有进程设置。