android21-requires_compiling_with_JDK7_01

During my last project on Android 5.0 Reveal Animation, this error occurred: Error:compileSdkVersion android-21 requires compiling with JDK 7. While searching the internet I found that several people had the same error therefore I performed several tests in order to solve it. The post demonstrates how to solve the error.

Steps

  • Open your SDK Settings and check the SDK location. sdk-location
  • If you have already installed JDK 7 you can change the path and you are done. If you can’t find the path(Mac) you can just put: /usr/bin/java
  • In case you don’t have JDK 7 installed you need to download it from here and perform the above steps

Alternative way

Java 7 support was added at build tools 21. You can use now features like the diamond operator, multi-catch, try-with-resources, strings in switches, etc. Add the folowing to your build.gradle.