Java Android Studio:包括谷歌地图时的编译器设置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24807117/
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 Studio: what compiler settings when including Google Maps
提问by Jason Hocker
I created a new project in Android Studio and added a Google Maps activity.
我在 Android Studio 中创建了一个新项目并添加了一个 Google Maps 活动。
I get these warnings:
我收到这些警告:
warning: com/google/android/gms/maps/GoogleMap.class(com/google/android/gms/maps:GoogleMap.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
warning: com/google/android/gms/maps/SupportMapFragment.class(com/google/android/gms/maps:SupportMapFragment.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
warning: com/google/android/gms/maps/model/LatLng.class(com/google/android/gms/maps/model:LatLng.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
warning: com/google/android/gms/maps/model/MarkerOptions.class(com/google/android/gms/maps/model:MarkerOptions.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
warning: com/google/android/gms/maps/model/Marker.class(com/google/android/gms/maps/model:Marker.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
My guess is that I have a JDK miss-match or something. I installed JDK 7, and when I do javac -version I see 1.7.0_65. I changed in Android Studio's preferences the Project bytecode version but that didn't change these warnings.
我的猜测是我有一个 JDK 不匹配或其他问题。我安装了 JDK 7,当我执行 javac -version 时,我看到 1.7.0_65。我在 Android Studio 的首选项中更改了项目字节码版本,但这并没有改变这些警告。
My build.gradle has this
我的 build.gradle 有这个
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// You must install or update the Google Repository through the SDK manager to use this dependency.
compile 'com.google.android.gms:play-services:5.0.77'
compile 'com.android.support:support-v13:18.0.+'
}
What do I need to do to fix these warnings, or should I ignore them in Android Studio?
我需要做什么来修复这些警告,还是应该在 Android Studio 中忽略它们?
回答by Loures
"Major version" means Java version. Java 7 = 51, Java 6 = 50. The code is written for Java 7, and that is something that Android's dex supports. I am not sure what you are building with that is not set for Java 7, but that's the problem. The Maven build in the project works correctly. I don't see the error you mention, and it may be related to Java 6 vs 7 too.
“主要版本”是指 Java 版本。Java 7 = 51,Java 6 = 50。代码是为 Java 7 编写的,这是 Android 的 dex 支持的。我不确定您正在构建的内容不是为 Java 7 设置的,但这就是问题所在。项目中的 Maven 构建工作正常。我没有看到您提到的错误,它也可能与 Java 6 vs 7 有关。
回答by Christopher Pickslay
I was able to resolve this based on Jason Hocker's tip and this answer. Add this to your android
gradle task:
我能够根据 Jason Hocker 的提示和这个答案解决这个问题。将此添加到您的android
gradle 任务中:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
Note that you must have a Java 7 JDKinstalled. I also had to add this to my gradlew
to allow gradle to find the correct JDK:
请注意,您必须安装Java 7 JDK。我还必须将此添加到我的gradlew
以允许 gradle 找到正确的 JDK:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)