问题
I created a new project in Android Studio and added a Google Maps activity.
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.
My build.gradle has this
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?
回答1:
"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.
回答2:
I was able to resolve this based on Jason Hocker's tip and this answer. Add this to your android
gradle task:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
Note that you must have a Java 7 JDK installed. I also had to add this to my gradlew
to allow gradle to find the correct JDK:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)
来源:https://stackoverflow.com/questions/24807117/android-studio-what-compiler-settings-when-including-google-maps