14

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?

Jason Hocker
  • 6,879
  • 9
  • 46
  • 79

2 Answers2

13

"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.

Loures
  • 433
  • 3
  • 10
  • 2
    I added compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } and that made the error go away. Is that the best way to do it? – Jason Hocker Jul 17 '14 at 18:18
  • Jason, I think that your solution is right. From Android documentation: "Default value is “1.6”. This affect all tasks compiling Java source code.". So it has to be changed to 1.7 or 1.8. – Peter Knut Jul 19 '14 at 19:40
  • After gradle synchronization, this file will be changed: .idea/misc.xml, where yo can find: – Peter Knut Jul 19 '14 at 19:48
  • 1
    @JasonHocker where did you add this? If I add it to my `android` config, the `compileDebugJava` task fails with "invalid source release: 1.7" – Christopher Pickslay Sep 05 '14 at 00:36
  • Since posting, I have upgraded Android Studio. I no longer have the sample app I used before, so I tried to recreate it. I am not getting the message I originally received. I can't swear if I am doing the exact same sample, or if an upgrade to Studio fixed it (I am on the latest canary 0.8.9 build) or if something else on my system changed. I think I added the compileOptions to the build.gradle. Do you have java 7 installed? – Jason Hocker Sep 05 '14 at 15:05
  • Thanks - In my case, Java 7 was already installed. However, removing Java 6 solved it for me. – Timothy Lee Russell Oct 18 '14 at 01:46
6

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)
Community
  • 1
  • 1
Christopher Pickslay
  • 17,523
  • 6
  • 79
  • 92