Support library gradle improvements

* Define java source compatibility on all build files to avoid
issues that might be caused by compiling with Java8
* Apply the library plugin using the cannonical name
* Define a currentSdkVersion variable instead of embedded string.
We can later load this from a file so that you can checkout
an older branch of support lib and compile it on master and
it won't use master's API by mistake.
This also helps with Android Studio integration.

Bug: 26714403

Change-Id: I0e9f2770b397b761155ac8d4a40fa5fb001264e1
diff --git a/annotations/build.gradle b/annotations/build.gradle
index 2ff9980..755830f 100644
--- a/annotations/build.gradle
+++ b/annotations/build.gradle
@@ -1,5 +1,6 @@
 apply plugin: 'java'
-
+sourceCompatibility = JavaVersion.VERSION_1_7
+targetCompatibility = JavaVersion.VERSION_1_7
 archivesBaseName = 'support-annotations'
 
 sourceSets {
diff --git a/build.gradle b/build.gradle
index 174738c..56f0479 100644
--- a/build.gradle
+++ b/build.gradle
@@ -133,7 +133,7 @@
 subprojects {
     // Change buildDir first so that all plugins pick up the new value.
     project.buildDir = project.file("$project.parent.buildDir/../$project.name/build")
-
+    project.ext.currentSdk = 'current'
     apply plugin: 'maven'
 
     version = rootProject.ext.supportVersion
diff --git a/customtabs/build.gradle b/customtabs/build.gradle
index 317dd9d..4cbfb88 100644
--- a/customtabs/build.gradle
+++ b/customtabs/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'customtabs'
 
@@ -8,7 +8,7 @@
 }
 
 android {
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     sourceSets {
         main.manifest.srcFile 'AndroidManifest.xml'
diff --git a/design/build.gradle b/design/build.gradle
index 7de5f39..f7726b0 100644
--- a/design/build.gradle
+++ b/design/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'design'
 
@@ -17,7 +17,7 @@
 }
 
 android {
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     defaultConfig {
         minSdkVersion 7
diff --git a/graphics/drawable/animated/build.gradle b/graphics/drawable/animated/build.gradle
index 6a55389..beed037 100644
--- a/graphics/drawable/animated/build.gradle
+++ b/graphics/drawable/animated/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'animated-vector-drawable'
 
@@ -23,6 +23,11 @@
         androidTest.manifest.srcFile 'tests/AndroidManifest.xml'
     }
 
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_7
+        targetCompatibility JavaVersion.VERSION_1_7
+    }
+
     lintOptions {
         abortOnError true
     }
diff --git a/graphics/drawable/static/build.gradle b/graphics/drawable/static/build.gradle
index 5561d0d..f0a363f 100644
--- a/graphics/drawable/static/build.gradle
+++ b/graphics/drawable/static/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'support-vector-drawable'
 
@@ -26,6 +26,11 @@
         androidTest.manifest.srcFile 'tests/AndroidManifest.xml'
     }
 
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_7
+        targetCompatibility JavaVersion.VERSION_1_7
+    }
+
     lintOptions {
         abortOnError true
     }
diff --git a/percent/build.gradle b/percent/build.gradle
index dc8a9a8..0603ad9 100644
--- a/percent/build.gradle
+++ b/percent/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'percent'
 
@@ -15,7 +15,7 @@
 }
 
 android {
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     defaultConfig {
         minSdkVersion 8
diff --git a/recommendation/build.gradle b/recommendation/build.gradle
index a9db906..c38fbd2 100644
--- a/recommendation/build.gradle
+++ b/recommendation/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'recommendation'
 
@@ -7,7 +7,7 @@
 }
 
 android {
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     defaultConfig {
         minSdkVersion 21
diff --git a/v13/build.gradle b/v13/build.gradle
index c1e624b..5060842 100644
--- a/v13/build.gradle
+++ b/v13/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'support-v13'
 
@@ -74,6 +74,11 @@
         // TODO: fix errors and reenable.
         abortOnError false
     }
+
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_7
+        targetCompatibility JavaVersion.VERSION_1_7
+    }
 }
 
 android.libraryVariants.all { variant ->
diff --git a/v14/preference/build.gradle b/v14/preference/build.gradle
index b5129b1..79b96cd 100644
--- a/v14/preference/build.gradle
+++ b/v14/preference/build.gradle
@@ -16,7 +16,7 @@
 
 
 
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'preference-v14'
 
@@ -28,7 +28,7 @@
 }
 
 android {
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     sourceSets {
         main.manifest.srcFile 'AndroidManifest.xml'
diff --git a/v17/leanback/build.gradle b/v17/leanback/build.gradle
index 401a5c4..eed7d6b 100644
--- a/v17/leanback/build.gradle
+++ b/v17/leanback/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'leanback-v17'
 
@@ -9,7 +9,7 @@
 
 android {
     // WARNING: should be 17
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     defaultConfig {
         minSdkVersion 17
diff --git a/v17/preference-leanback/build.gradle b/v17/preference-leanback/build.gradle
index 0ddcdd2..c72f23c 100644
--- a/v17/preference-leanback/build.gradle
+++ b/v17/preference-leanback/build.gradle
@@ -16,7 +16,7 @@
 
 
 
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'preference-leanback-v17'
 
@@ -30,7 +30,7 @@
 }
 
 android {
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     sourceSets {
         main.manifest.srcFile 'AndroidManifest.xml'
diff --git a/v4/build.gradle b/v4/build.gradle
index 5abdbb9..993eb5a 100644
--- a/v4/build.gradle
+++ b/v4/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 archivesBaseName = 'support-v4'
 
 // create a jar task for the code internal implementation
@@ -104,7 +104,7 @@
 
     testOptions {
         unitTests.returnDefaultValues = true
-        compileSdkVersion 'current'
+        compileSdkVersion project.ext.currentSdk
     }
 }
 
diff --git a/v7/appcompat/build.gradle b/v7/appcompat/build.gradle
index 060f2ae..7687733 100644
--- a/v7/appcompat/build.gradle
+++ b/v7/appcompat/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'appcompat-v7'
 
@@ -15,7 +15,7 @@
 }
 
 android {
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     defaultConfig {
         minSdkVersion 7
diff --git a/v7/cardview/build.gradle b/v7/cardview/build.gradle
index 143519c..8636474 100644
--- a/v7/cardview/build.gradle
+++ b/v7/cardview/build.gradle
@@ -1,10 +1,10 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'cardview-v7'
 
 android {
     // WARNING: should be 7
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     defaultConfig {
         minSdkVersion 7
@@ -12,6 +12,11 @@
         //targetSdkVersion 19
     }
 
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_7
+        targetCompatibility JavaVersion.VERSION_1_7
+    }
+
     sourceSets {
         main.manifest.srcFile 'AndroidManifest.xml'
         main.java.srcDirs = ['base', 'eclair-mr1', 'jellybean-mr1', 'api21', 'src']
diff --git a/v7/gridlayout/build.gradle b/v7/gridlayout/build.gradle
index 9e55c01..6e363dd 100644
--- a/v7/gridlayout/build.gradle
+++ b/v7/gridlayout/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'gridlayout-v7'
 
@@ -7,7 +7,7 @@
 }
 
 android {
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     sourceSets {
         main.manifest.srcFile 'AndroidManifest.xml'
@@ -25,6 +25,11 @@
         androidTest.manifest.srcFile 'tests/AndroidManifest.xml'
     }
 
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_7
+        targetCompatibility JavaVersion.VERSION_1_7
+    }
+
     lintOptions {
         // TODO: fix errors and reenable.
         abortOnError false
diff --git a/v7/mediarouter/build.gradle b/v7/mediarouter/build.gradle
index 48f4750..37224f0 100644
--- a/v7/mediarouter/build.gradle
+++ b/v7/mediarouter/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'mediarouter-v7'
 
@@ -41,7 +41,7 @@
 }
 
 android {
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     sourceSets {
         main.manifest.srcFile 'AndroidManifest.xml'
diff --git a/v7/palette/build.gradle b/v7/palette/build.gradle
index 8c2885b..65e298d 100644
--- a/v7/palette/build.gradle
+++ b/v7/palette/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'palette-v7'
 
diff --git a/v7/preference/build.gradle b/v7/preference/build.gradle
index a0681ed..45b4f96 100644
--- a/v7/preference/build.gradle
+++ b/v7/preference/build.gradle
@@ -14,7 +14,7 @@
  * limitations under the License
  */
 
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'preference-v7'
 
@@ -25,7 +25,7 @@
 }
 
 android {
-    compileSdkVersion 'current'
+    compileSdkVersion project.ext.currentSdk
 
     sourceSets {
         main.manifest.srcFile 'AndroidManifest.xml'
diff --git a/v7/recyclerview/build.gradle b/v7/recyclerview/build.gradle
index 3e368a1..386694d 100644
--- a/v7/recyclerview/build.gradle
+++ b/v7/recyclerview/build.gradle
@@ -1,4 +1,4 @@
-apply plugin: 'android-library'
+apply plugin: 'com.android.library'
 
 archivesBaseName = 'recyclerview-v7'
 
@@ -37,6 +37,11 @@
         androidTest.manifest.srcFile 'tests/AndroidManifest.xml'
     }
 
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_7
+        targetCompatibility JavaVersion.VERSION_1_7
+    }
+
     lintOptions {
         // TODO: fix errors and reenable.
         abortOnError false