简体   繁体   English

带私有jre / jdk的Android Studio IDE? OSX

[英]Android Studio IDE with private jre/jdk? OSX

I'm running OSX 10.8 and was trying to run the Android Studio app bundle using a private jdk rather than one that is globally installed. 我正在运行OSX 10.8并尝试使用私有jdk运行Android Studio应用程序包,而不是全局安装的。

EDIT: I don't have any java installation globally accessible. 编辑:我没有全局访问任何Java安装。

I have done this successfully in the past with Eclipse by editing the plist.info file and specifying what JRE/JDK I want to use via the eclipse.ini file. 我以前通过编辑plist.info文件并通过eclipse.ini文件指定我想要使用的JRE / JDK,在Eclipse中成功完成了这项工作。

I haven't found the magic on how to do this with Android Studio. 我还没有找到关于如何使用Android Studio执行此操作的魔力。

After editing the plist file unsuccessfully I opened a terminal and added the JDK/bin directory to the PATH and set a JAVA_HOME but that wasn't enough for the idea_applauncher to find a Java installation where I had specified. 编辑plist文件失败后,我打开了一个终端,并将JDK / bin目录添加到PATH并设置了一个JAVA_HOME,但这还不足以让idea_applauncher找到我指定的Java安装。

I'm not sure what else I could try to make this happen. 我不确定我还能尝试做些什么。 Any ideas? 有任何想法吗?

EDIT: I don't have enough rep to post a screenshot, but below that what the command-line looks like with the output. 编辑:我没有足够的代表来发布截图,但在命令行的输出下面是什么。

When I try to run the bundle I get a pop-up window saying there's no JDK installed and it has two buttons asking me to either "Install" or "Not Now" 当我尝试运行捆绑包时,我得到一个弹出窗口,说明没有安装JDK,它有两个按钮要求我“安装”或“不立即”

$ ./idea_appLauncher $ ./idea_appLauncher

No Java runtime present, requesting install. 没有Java运行时,请求安装。

Another solution for OSX: go to the Applications folder, right click on Android Studio, choose "Show Package Contents". OSX的另一个解决方案:转到Applications文件夹,右键单击Android Studio,选择“Show Package Contents”。

Open the Info.plist file. 打开Info.plist文件。 Locate the JVMVersion key, and set the string value you need. 找到JVMVersion项,然后设置所需的字符串值。

In my case, I needed to be 1.7 and up to be able to run the RoboVM plugin, and the value was 1.6*,1.7+ , so I left it only on 1.7+. 在我的情况下,我需要1.7以上才能运行RoboVM插件,值为1.6 *,1.7 + ,所以我只留下1.7+。

Restart Android Studio and it should be using the version of the JVM you need. 重新启动Android Studio,它应该使用您需要的JVM版本。

This works if you have root access on your Mac. 如果您在Mac上具有root访问权限,则此方法有效。

I just check the executable script that starts android-studio, if you are arleady familiar with intellijIdea it is the same. 我只是检查启动android-studio的可执行脚本,如果你熟悉intellijIdea它是一样的。

  # ---------------------------------------------------------------------
  # Locate a JDK installation directory which will be used to run the IDE.
  # Try (in order): STUDIO_JDK, JDK_HOME, JAVA_HOME, "java" in PATH.
  # ---------------------------------------------------------------------
  if [ -n "$STUDIO_JDK" -a -x "$STUDIO_JDK/bin/java" ]; then
    JDK="$STUDIO_JDK"
  elif [ -n "$JDK_HOME" -a -x "$JDK_HOME/bin/java" ]; then
    JDK="$JDK_HOME"
  elif [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
    JDK="$JAVA_HOME"
  else
    JAVA_BIN_PATH=`which java`
    if [ -n "$JAVA_BIN_PATH" ]; then
      if [ "$OS_TYPE" = "FreeBSD" -o "$OS_TYPE" = "MidnightBSD" ]; then
        JAVA_LOCATION=`JAVAVM_DRYRUN=yes java | "$GREP" '^JAVA_HOME' | "$CUT" -c11-`

As written in the comments of the bash scripts, just add a STUDIO_JDK environment variable with the absolute path of the desired JDK. 如bash脚本的注释中所述,只需添加一个STUDIO_JDK环境变量,其中包含所需JDK的绝对路径。

This is my ideaj.sh bash script which i stored in /etc/profile.d 这是我的ideaj.sh bash脚本,它存储在/etc/profile.d中

export IDEA_JDK=/opt/jdk1.7.0_71
export STUDIO_JDK=/opt/jdk1.7.0_71

Add to /etc/bash.bashrc to automatically set the variables at every login. 添加到/etc/bash.bashrc以在每次登录时自动设置变量。

source /opt/profile.d/ideaj.sh

All this should be applied to linux, on OS X can be a little different, but the theory is the same. 所有这些都应该应用于linux,在OS X上可能会有所不同,但理论是一样的。

$ export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk
$ open /Applications/Android\ Studio.app

here is explain link 这里是解释链接

For getting the app to start: 要启动应用程序:

In spotlight see if you have a "java preferences". 在聚光灯下看看你是否有“java偏好”。
From there you can add you own jdk/jre and let it be the one used by osx. 从那里你可以添加你自己的jdk / jre,让它成为osx使用的。
If you dont have it, you will need to install a java jre as in this question : How to get back Java Preferences in OS X with Java for OS X 2012-006? 如果你没有它,你将需要在这个问题中安装一个java jre: 如何使用Java for OS X 2012-006获取OS X中的Java Preferences?

Then you should be able to get the "java preferences" app and add your custom jdk there 然后你应该能够获得“java偏好”应用程序并在那里添加你的自定义jdk

This should help you get started with project related sdk stuff. 这应该可以帮助您开始使用项目相关的sdk。

  1. Open your project with modules 使用模块打开您的项目
  2. select a module in the project pane 在项目窗格中选择一个模块
  3. right click > " open module settings" 右键单击>“打开模块设置”
  4. select SDKs on the modal that appears 在出现的模态上选择SDK
  5. click the + icon (middle content area on the top) 单击+图标(顶部的中间内容区域)
  6. select jdk 选择jdk
  7. target the folder "to the JDK [you] have on disk" 将文件夹“定位到磁盘上的JDK [你]”
  8. hit choose 打击选择

Set the variable; 设置变量; ANDROID_STUDIO_JDK and use it for the path to your JDK. ANDROID_STUDIO_JDK并将其用作JDK的路径。

source: http://www.reddit.com/r/Android/comments/1ee2ea/google_announces_android_studio_a_new_development/c9zfklt 来源: http//www.reddit.com/r/Android/comments/1ee2ea/google_announces_android_studio_a_new_development/c9zfklt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM