Android Studio:包含 Google 地图时的编译器设置

2022-09-04 02:11:12

我在Android Studio中创建了一个新项目,并添加了一个Google Maps活动。

我收到以下警告:

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.

我的猜测是我有一个JDK不匹配什么的。我安装了JDK 7,当我做javac -version时,我看到1.7.0_65。我在Android Studio的首选项中更改了Project字节码版本,但这并没有改变这些警告。

我的 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.+'
}

我需要做些什么来修复这些警告,或者我应该在 Android Studio 中忽略它们?


答案 1

“主要版本”是指 Java 版本。Java 7 = 51,Java 6 = 50。代码是为Java 7编写的,这是Android的dex支持的东西。我不确定你用什么来构建的东西不是为Java 7设置的,但这就是问题所在。项目中的 Maven 生成工作正常。我没有看到你提到的错误,它可能也与Java 6 vs 7有关。


答案 2

我能够根据Jason Hocker的提示和这个答案解决这个问题。将其添加到您的 gradle 任务中:android

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

请注意,您必须安装 Java 7 JDK。我还必须将其添加到我的中,以便 gradle 找到正确的 JDK:gradlew

export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)

推荐