Android Studio不尊重环境变量 [英] Android Studio does not honor environment variables
问题描述
我试图通过设置java vm参数来将特定于环境的值传递给Android studio v 2.2.2(例如服务器url,keystore位置和密码)。到目前为止,我尝试了以下选项,但没有任何工作。
1。从studio.vmoptions设置java-vm参数(如记录的 here < a>)
我点击了帮助 - >编辑自定义VM选项...
创建一个在〜/ .AndroidStudio2.2 / studio64.vmoptions中创建的新vmoptions文件。
$ b
-DRELEASE_KEY_STORE_PATH = / home / ubuntu / ks / myapp / app-release.keystore
2。使用 gradle.properties
文件
我在同一目录中创建了一个gradle.properties文件根build.gradle文件存在。该文件包含以下内容。
RELEASE_KEY_STORE_PATH = / home / ubuntu / ks / myapp / app-release.keystore
3。编辑了studio.sh文件
我也尝试编辑studio.sh文件,添加以下行希望这些属性可用于Android Studio。 / p>
export RELEASE_KEY_STORE_PATH = / home / ubuntu / ks / myapp / app-release.keystore
我的build.gradle文件有使用此值的signingConfig部分。
signingConfigs {
release {
storeFile文件(System.env.RELEASE_KEY_STORE_PATH)
storePassword System.env.RELEASE_KEYS_STORE_PASSWORD
keyAlias System.env.RELEASE_KEY_ALIAS
keyPassword System.env.RELEASE_KEY_PASSWORD
$ / code>
当从Android Studio运行gradle项目同步/构建时,构建失败。
显示错误:路径和baseDir都不能为null或空字符串。 path ='null'basedir ='/ home / ubuntu / path-to-project'。
这意味着脚本无法解析文件路径,因为它是空的。
更新
如果我从命令行运行gradle build,它完美的工作,编译成功,我所要做的只是激发一些导出命令我希望在构建中继承所需的属性。
以下是我的开发环境:
我已经根据@DeeV和@CommonsWare的评论进行了调查,并做了一些更改以在Android Studio以及命令行上成功运行构建。
-
我在Gradle的主目录中放置了gradle.properties文件。在我的环境中(ubuntu),gradle home目录位于
〜/ .gradle
。 -
I必须从变量的用法中删除
System.env。
,这样它才能使用在gradle.properties文件中声明的属性。
通过这两项更改,我注意到Android Studio问题得到了解决。然而,这导致了另一个问题,CL构建失败,出现错误:
无法从存储/home/ubuntu/ks/myapp/app-release.keystore中读取关键的relase_key:Keystore被篡改,或者密码不正确。
这意味着从CL运行时的gradle可以解析路径,但无法从KS读取密钥。
我必须执行以下步骤来消除此错误:
- 在gradle.properties中,我有将双引号中的
RELEASE_KEY_PASSWORD
和RELEASE_KEY_STORE_PASSWORD
值删除,然后从命令行成功完成构建。
我希望这可以帮助任何面临类似情况的人。
I am trying to pass environment specific values to Android studio v 2.2.2 (such as server url, keystore location and password) by setting java vm arguments. So far I've tried following options but nothing has worked.
1. Setting the java-vm arguments from studio.vmoptions (as documented here)
I clicked Help -> Edit Custom VM Options...
to create a new vmoptions file which is created at ~/.AndroidStudio2.2/studio64.vmoptions. I have edited the file to add following line.
-DRELEASE_KEY_STORE_PATH=/home/ubuntu/ks/myapp/app-release.keystore
2. With a gradle.properties
file
I have created a gradle.properties file in the same directory where the root build.gradle file exists. The file has following contents.
RELEASE_KEY_STORE_PATH=/home/ubuntu/ks/myapp/app-release.keystore
3. Edited the studio.sh file
I have also tried editing the studio.sh file, added following line hoping these properties will be available to Android Studio.
export RELEASE_KEY_STORE_PATH=/home/ubuntu/ks/myapp/app-release.keystore
My build.gradle file has signingConfig section where this value is used.
signingConfigs {
release {
storeFile file(System.env.RELEASE_KEY_STORE_PATH)
storePassword System.env.RELEASE_KEYS_STORE_PASSWORD
keyAlias System.env.RELEASE_KEY_ALIAS
keyPassword System.env.RELEASE_KEY_PASSWORD
}
}
The build fails when gradle project sync / build runs from Android Studio.
The error is displayed: Neither path nor baseDir may be null or empty string. path='null' basedir='/home/ubuntu/path-to-project'.
This means that script is not able to resolve the file path as it is coming null.
UPDATE If I run the gradle build from command line it perfectly works, build succeeds, all I have to do is just fire some export commands for the desired properties I want to inherit in build.
Following is my dev environment:
- Gradle version used by Android Studio: 2.14.1
- Gradle plugin version: 2.3.1
- Android Studio version: 2.2.2
- Java version: oracle jdk 1.8.0_111
- OS: Ubuntu 16.04 amd64
I have done investigation based on the comments by @DeeV and @CommonsWare and have done some changes to run the build successfully on Android Studio as well as on command line.
I have placed gradle.properties file in Gradle's home directory. In my environment (ubuntu) the gradle home directory is located at
~/.gradle
.I have to remove the
System.env.
from the usage of the variables, so this way it uses the properties declared in gradle.properties file.
With these two changes, I noticed that the Android Studio problem got resolved. However this has caused another problem, the CL build was failing with error:
Failed to read key relase_key from store "/home/ubuntu/ks/myapp/app-release.keystore": Keystore was tampered with, or password was incorrect.
This means the gradle when run from CL can resolve the path but fails to read key from KS.
I have to do the following step to get rid of this error:
- In the gradle.properties, I had put the values for
RELEASE_KEY_PASSWORD
andRELEASE_KEY_STORE_PASSWORD
in double quotes, I removed the quotes and then the build completed successfully from command line.
I hope this will help anyone who face similar situation.
这篇关于Android Studio不尊重环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!