android maven 插件在 Eclipse 中没有获得 ANDROID_HOME 环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11415997/
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
android maven plugin does not get ANDROID_HOME env variable in Eclipse
提问by Mert Buran
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:
我正在开发一个 Android 应用程序项目,它是一个 Maven 项目。当我尝试以“maven install”运行时,这就是我得到的:
"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]"
“未能在项目 android-client 上执行目标 com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.1.1:generate-sources (default-generate-sources):找不到 Android SDK 路径. 您可以在 pom 文件的插件配置部分中使用 ... 或 ... 或在命令行上使用 -Dandroid.sdk.path=... 或通过设置环境变量 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 路径硬编码到 pom.xml 中,它工作正常,但我们使用 git 并且每个人可能对 android_home 有不同的路径。为什么 android-maven-plugin 在 eclipse 中没有获取 env 变量?
android_home env variable is in my PATH. i wrote ${env.ANDROID_HOME} in my pom.xml but it still didn't work.
android_home env 变量在我的 PATH 中。我在 pom.xml 中写了 ${env.ANDROID_HOME} 但它仍然不起作用。
strangely,if i use terminal (mvn install) to run as maven install,it works!
奇怪的是,如果我使用终端(mvn install)作为 maven install 运行,它可以工作!
actually this is quite optional problem for me but still i want to know why this plugin does not work in Eclipse.
实际上,这对我来说是一个非常可选的问题,但我仍然想知道为什么这个插件在 Eclipse 中不起作用。
采纳答案by nmw
You need to create a system variable for ANDROID_HOME, not set it in your PATH.
您需要为 ANDROID_HOME 创建一个系统变量,而不是在您的 PATH 中设置它。
回答by gauchofunky
Ensure your Android SDK installation contains the libraries for the same API version you have configured on your pom.xml.
确保您的 Android SDK 安装包含您在 pom.xml 上配置的相同 API 版本的库。
For example, if your configuration XML looks like:
例如,如果您的配置 XML 如下所示:
<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.
那么您应该使用 Android SDK Manager(或直接检查您的文件系统:$ANDROID_HOME/platforms)来验证您是否安装了 SDK API 8。当然,您也可以更改 pom.xml 以匹配安装的库。
回答by tomrozb
If you are using Linux, exporting the ANDROID_HOME
in the .bashrc
may not work.
如果您使用的是 Linux,则导出ANDROID_HOME
中的.bashrc
可能不起作用。
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
中/etc/environment
像这样的文件:
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 againfor 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
您只需注销,然后再次登录即可在系统范围内应用环境变量。或者,您可以在执行此操作之前仅在本地获取它以对其进行测试:$source /etc/environment
回答by David T.
on your command line, run:
在命令行上,运行:
mvn clean install -- Dandroid.sdk.path="/Applications/Android Studio.app/sdk/"
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)
其他方法都没有真正奏效。(设置ANDROID_HOME
不做任何事情)
回答by leebeckman
Setting an ANDROID_HOME variable in your .bashrc or whatever will work, but remember to exportthat 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.
在您的 .bashrc 中设置 ANDROID_HOME 变量或其他任何可以工作的变量,但请记住导出该变量以便子进程可以使用它。使用此处建议的其他方法设置 ANDROID_HOME 将帮助您解决一些初始错误,但是如果没有 ANDROID_HOME 导出,您的构建可能会在某些时候失败。
回答by Ivan
Another way is to set the environment variable into run configuration for pom.xml.
另一种方法是将环境变量设置为 pom.xml 的运行配置。
Go to Run Configurations menu, select the Run configuration used for your project pom.xml and select the EnvironmentTab and select "New", then insert:
转到运行配置菜单,选择用于项目 pom.xml 的运行配置并选择环境选项卡并选择“新建”,然后插入:
- ANDROID_HOME into name Field
- path to your sdk into value field
- ANDROID_HOME 进入 name 字段
- sdk 到 value 字段的路径
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.
它可以工作,这样只有在您为选定的项目启动 maven 配置时才设置变量,您还可以为不同的项目设置不同的路径,而无需更改您的 .bashrc。它也适用于 Windows。
回答by Benny Neugebauer
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
.
您可以android-maven-plugin
在pom.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.xml
this 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-plugin
section:
作为替代方案,您还可以在以下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 Ricardo Gladwell
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.
您需要在 Eclipse 中设置 Android Development Tools SDK Location 路径:单击 Window -> Preferences 并选择 Android。可以在 Android 首选项下设置 SDK 位置。
回答by Daniel Magnusson
Create a file called local.propertiesin your root directory of your project.
在项目的根目录中创建一个名为local.properties的文件。
With the contents;
与内容;
sdk.dir=c:\path\to\android-sdk