Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Having trouble building a Plugin using Android Studio

Discussion in 'Android' started by Jonathan-Bro, Aug 8, 2015.

  1. Jonathan-Bro

    Jonathan-Bro

    Joined:
    Apr 11, 2013
    Posts:
    35
    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?
     
  2. BitsAtPlayDev

    BitsAtPlayDev

    Joined:
    May 5, 2013
    Posts:
    11
    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:
    Code (gradle):
    1. apply plugin: 'com.android.library'
    2.  
    3. android
    4. {
    5.   compileSdkVersion 22
    6.   buildToolsVersion "22.0.1"
    7.   defaultConfig
    8.   {
    9.     minSdkVersion 9
    10.     targetSdkVersion 22
    11.     versionCode 1
    12.     versionName "1.0"
    13.   }
    14.   buildTypes
    15.   {
    16.     release
    17.     {
    18.       minifyEnabled false
    19.       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    20.     }
    21.   }
    22.   productFlavors
    23.   {
    24.   }
    25.   compileOptions
    26.   {
    27.     sourceCompatibility JavaVersion.VERSION_1_6
    28.     targetCompatibility JavaVersion.VERSION_1_6
    29.   }
    30. }
    31.  
    32. dependencies
    33. {
    34.   compile fileTree(dir: 'libs', include: ['*.jar'])
    35.   compile 'com.android.support:appcompat-v7:22.2.1'
    36. }
    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
     
    Last edited: Aug 9, 2015