using android studio,Using Android Studio with Java 1.7

问题

I was trying to get Android Studio to use Java 1.7 on Mac OS X (Mountain Lion)

I went to File > Project Structure... and then tried to add a JDK with the + button and then selecting JDK.

I navigated to /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home and selected that, but nothing happens. (this is where Oracle's Java updater installed Java 7 automatically)

How do I use Java 1.7 with Android Studio?

回答1:

For those wonder how you start the actual program Android Studio with Java 7: edit the plist located in /Applications/Android Studio.app/Contents/Info.plist

Change the xml key JVMVersion which is 1.6* to 1.7* (Java 7) or 1.6+ (latest version)

I don't know if there are any problems by doing this so take it easy.

回答2:

There is simple way to do this. Please add following lines in build.gradle in android section:

compileOptions {

sourceCompatibility JavaVersion.VERSION_1_7

targetCompatibility JavaVersion.VERSION_1_7

}

and sync project with Gradle files. Android Studio will detect change (language Level) and ask to reload the project.

回答3:

I went to Java SE Downloads and downloaded Java 7 again. The method mentioned above worked for Eclipse.

Running the installer from this manual download placed the JDK in /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home, which was accepted by Android Studio.

回答4:

On a mac, check your java version by running this command:

java -version

And you should see a version higher than 1.7. If not, then just run your system updates to get the latest version of java. (Click the "Apple" logo in the upper left and choose About this Mac then click the Software Update... button and install the latest java from there.) In other words, get your latest java from Apple's Updates, if you can–it's easier that way.

Once you have the latest version, then simply run the following command:

/usr/libexec/java_home

This will tell you your Java Home location, which is what Android Studio wants. For me, this value was

/Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home

If you'd like to set this as a default for all projects, follow the instructions in this related answer (which deals with how to set your Android SDK but the Java SDK is set in the same screen). In a nutshell, close all projects to get to the Welcome to Android Studio screen then select > Configure > Project Defaults > Project Structure > Android SDK and then input your JDK location, given by the java_home utility.

I just took these steps while creating a project targeting "Lollipop" and it worked like a charm.

回答5:

Similar to Perty's answer above, edit /Applications/Android Studio.app/Contents/Info.plist, but change the xml key JVMVersion from 1.6* to 1.6+. As per Apple's Docs, a star (*) means exactly the named version, whereas a plus (+) means at least that version.

The "exactly 6" setting was implemented after AS 0.5.0 was released, when per the release notes some users had trouble opening AS with Java 7.

回答6:

I have the same problem on Android Studio 2.1 and I have java 6 and 7 installed.

When I run java -version or javac -version it shows 1.7.0_79, but Android Studio insists using 1.6.

I had to change the info.plist from 1.6*,1.7+ to 1.7+. Now it works and stop complaining about download updates securely.

回答7:

In Mac, you can choose from within IDE interface by ⌘-Shift-a and find Switch IDE boot JDK...

来源:https://stackoverflow.com/questions/16636146/using-android-studio-with-java-1-7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值