Having trouble building a Plugin using Android Studio

Background
I’m new to Android Studio and native plugins in general, so I am following this tutorial trying to make a basic plugin:

Problem
According to Unity documentation, I should be using JDK 6 (v1.6). I downloaded JDK 6 and set Android Studio to point to it (File->Project Structure).

But when Gradle tries to sync the project, it spits out the error:
“compileSdkVersion android-22 requires compiling with JDK 7)”

I’m confused, does that mean I can’t create native plugins for Unity with the latest Android version then?

You should be able to use the most recent version of the Android SDK - I have not had any issues doing so.

On my Mac, javac -version returns “javac 1.8.0_45”

Here is the Android Studio generated gradle script for one of my plugins:

apply plugin: 'com.android.library'

android
{
  compileSdkVersion 22
  buildToolsVersion "22.0.1"
  defaultConfig
  {
    minSdkVersion 9
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
  }
  buildTypes
  {
    release
    {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  productFlavors
  {
  }
  compileOptions
  {
    sourceCompatibility JavaVersion.VERSION_1_6
    targetCompatibility JavaVersion.VERSION_1_6
  }
}

dependencies
{
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:22.2.1'
}

Maybe updating to a more recent version of Java, but making sure to set the source and target compatibility to 1.6 might work?

HTH