Merge stage-aosp-master into pi-dev-plus-aosp
am: a7af9ae1f1

Change-Id: I13426d0d59e99d01f8396938f09f047fdb0b15b2
diff --git a/.gitignore b/.gitignore
index 639cdd5..cd8d22c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,5 @@
 local.properties
+.gradle
+.idea
+*.iml
+library
diff --git a/build.gradle b/build.gradle
index c30a000..45d505b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,34 +19,28 @@
 buildscript {
     repositories {
         maven { url '../../prebuilts/gradle-plugin' }
-        maven { url '../../prebuilts/tools/common/m2/repository' }
-        maven { url '../../prebuilts/tools/common/m2/internal' }
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.3.0'
+        classpath 'com.android.tools.build:gradle:3.0.1'
     }
 }
 
 apply from: 'version.gradle'
 
-final String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux'
-System.setProperty('android.dir', "${rootDir}/../../")
-final String fullSdkPath = "${rootDir}/../../prebuilts/fullsdk-${platform}"
-if (file(fullSdkPath).exists()) {
-    gradle.ext.currentSdk = 26
-    ext.buildToolsVersion = '26.0.0'
-    project.ext.androidJar = files("${fullSdkPath}/platforms/android-${gradle.currentSdk}/android.jar")
-    System.setProperty('android.home', "${rootDir}/../../prebuilts/fullsdk-${platform}")
-    File props = file("local.properties")
-    props.write "sdk.dir=${fullSdkPath}"
-} else {
-    gradle.ext.currentSdk = 'current'
-    ext.buildToolsVersion = '26.0.0'
-    project.ext.androidJar = files("${project.rootDir}/../../prebuilts/sdk/current/public/android.jar")
-    File props = file("local.properties")
-    props.write "android.dir=../../"
+String platform = OperatingSystem.current().isMacOsX() ? 'darwin' : 'linux'
+File fullSdkPath = file("${rootDir}/../../prebuilts/fullsdk-${platform}")
+if (!fullSdkPath.exists()) {
+    throw GradleException("missing fullsdk")
 }
 
+gradle.ext.currentSdk = 28
+ext.buildToolsVersion = '27.0.3'
+project.ext.fullSdkPath = fullSdkPath
+project.ext.androidJar = files("${fullSdkPath}/platforms/android-${gradle.currentSdk}/android.jar")
+
+File props = file("local.properties")
+props.write "sdk.dir=${fullSdkPath.getAbsolutePath()}"
+
 /*
  * With the build server you are given two env variables.
  * The OUT_DIR is a temporary directory you can use to put things during the build.
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..2b49a88
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,6 @@
+org.gradle.jvmargs=-Xmx4g
+org.gradle.daemon=true
+org.gradle.configureondemand=true
+org.gradle.parallel=true
+org.gradle.caching=true
+android.builder.sdkDownload=false
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 84939b4..3d7397a 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=../../../../tools/external/gradle/gradle-3.3-bin.zip
+distributionUrl=../../../../tools/external/gradle/gradle-4.8-bin.zip
diff --git a/instrumentation/build.gradle b/instrumentation/build.gradle
index 1e6fd98..fe6d8ee 100644
--- a/instrumentation/build.gradle
+++ b/instrumentation/build.gradle
@@ -21,7 +21,7 @@
 }
 
 android {
-    compileSdkVersion 4
+    compileSdkVersion gradle.currentSdk
 
     defaultConfig {
         minSdkVersion 4
diff --git a/library/build.gradle b/library/build.gradle
index 1f17008..fe707f0 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -55,15 +55,21 @@
             manifest.srcFile 'AndroidManifest.xml'
         }
     }
-
-    lintOptions {
-        // TODO: fix errors and reenable.
-        abortOnError false
-    }
 }
 
-android.libraryVariants.all {
-    v -> v.getJavaCompiler().dependsOn(makeVersionFile)
+android.libraryVariants.all { variant ->
+    variant.getJavaCompiler().dependsOn(makeVersionFile)
+
+    if (!name.equals(com.android.builder.core.BuilderConstants.RELEASE)) {
+        return // Skip non-release
+    }
+
+
+    def sourceJar = project.tasks.create(name: "sourceJarRelease", type: Jar) {
+        classifier = 'sources'
+        from android.sourceSets.main.java.srcDirs
+    }
+    artifacts.add("archives", sourceJar)
 }
 
 uploadArchives {
diff --git a/settings.gradle b/settings.gradle
index 7fffc9b..f4605ce 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -16,6 +16,3 @@
 
 include ':multidex'
 project(':multidex').projectDir = new File(rootDir, 'library')
-
-include ':multidex-instrumentation'
-project(':multidex-instrumentation').projectDir = new File(rootDir, 'instrumentation')