我无法在Mac OS上启动我的Android Studio进行Android开发(10.10.1 - Yosemite)


当前回答

注意,最后一个变量允许你在OSX上运行带有Java 7的Android Studio(通常从Info.plist中指定的版本中选择Java 6):

$ export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk

$ open /Applications/Android\ Studio.app

为我工作

其他回答

AndroidStudio将从文件~/Library/Preferences/AndroidStudio/idea.properties中读取设置。我创建了这个文件,其中有我的jdk的路径:

STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk

不编辑信息。plist必要!

在Info.plist中更改此键

我从

<key>JVMVersion</key>
<string>1.6*</string>

to

<key>JVMVersion</key>
<string>1.8*</string>

现在它工作得很好。

编辑: 根据hasternet和aried3r上面提到的官方声明,Antonio Jose的解决方案是正确的。

谢谢!

编辑android工作室的信息。plist文件,以便它使用1.7或任何您已经安装的JVMVersion。将JVMVersion更改为1.6+而不是如上所述的hassternet回答的1.6*应该也可以工作。

上述工作,但不建议参阅RC3发行说明

As of RC 3, we have a better mechanism for customizing properties for the launchers on all three platforms. You should not edit any files in the IDE installation directory. Instead, you can customize the attributes by creating your own .properties or .vmoptions files in the following directories. (This has been possible on some platforms before, but it required you to copy and change the entire contents of the files. With the latest changes these properties are now additive instead such that you can set just the attributes you care about, and the rest will use the defaults from the IDE installation).

Android Studio无法在Mac OSX上加载JVM (Mavericks)

安装最新的JDK (8u102 current) 设置环境变量STUDIO_JDK (java_home输出Java主目录,sed剥离两个文件夹以获得jdk目录) /usr/libexec/java_home -version 1.8 | sed 's/\/Contents\/Home//g' ' 像往常一样启动Android Studio

在每次重启时设置STUDIO_JDK

以上步骤仅适用于当前会话。下面是如何在/Library/LaunchDaemons中创建一个plist文件,在每次引导时运行上面的命令:

sudo defaults write /Library/LaunchDaemons/com.google.studiojdk Label STUDIO_JDK
sudo defaults write /Library/LaunchDaemons/com.google.studiojdk ProgramArguments -array /bin/launchctl setenv STUDIO_JDK `/usr/libexec/java_home | sed 's/\/Contents\/Home//g'`
sudo defaults write /Library/LaunchDaemons/com.google.studiojdk RunAtLoad -bool TRUE

要知道plist的诀窍,请访问http://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-mac-os-x-launchd-plist/

您可以使用用户的启动代理来实现STUDIO_JDK解决方案。这涉及到在您的LaunchAgents目录中创建一个plist文件,位于~/Library/LaunchAgents

创建一个新文件~/Library/LaunchAgents/UNIQUE_KEY。其中UNIQUE_KEY只是一个标识符。我使用com.username.androidstudio。

将以下文本复制到新的plist文件中,并根据下面的说明修改它。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>UNIQUE_KEY</string>
   <key>ProgramArguments</key>
   <array>
      <string>sh</string>
      <string>-c</string>
      <string>launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
</dict>
</plist>

你需要做两个修改:

更改UNIQUE_KEY以匹配您的文件名(不带.plist扩展名)。 验证您的JDK路径是否正确,并在必要时进行更改。在本例中,我使用7u71。

这和安东尼奥·何塞的答案是一样的。它根据Android Studio版本1.0 RC3发布说明设置STUDIO_JDK环境变量。这个解决方案使用LaunchAgents目录而不是AppleScript来设置环境变量。因此,这主要是您如何安排和组织系统和环境变量的差异。