Skip to content

Commit

Permalink
Merge pull request #35 from gradle/lptr/support-android-3.1.0-beta1
Browse files Browse the repository at this point in the history
Support Android 3.1.0-beta1 and Gradle 4.5
  • Loading branch information
lptr authored Jan 31, 2018
2 parents 78856ab + f1d3ffa commit 81c06b9
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cache:
android:
components:
- build-tools-26.0.2
- build-tools-27.0.1
- build-tools-27.0.3
- android-26

notifications:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

Some Android plugin versions have issues with Gradle's build cache feature. When applied to an Android project this plugin applies workarounds for these issues based on the Android plugin and Gradle versions.

* Supported Gradle versions: 4.1 to 4.4.1, 4.5-rc-2
* Supported Android versions: 3.0.0, 3.0.1, 3.1.0-alpha09
* Supported Gradle versions: 4.1 to 4.4.1, 4.5
* Supported Android versions: 3.0.0, 3.0.1, 3.1.0-beta1

**Note:** With Android 3.1.x the cache-fix plugin is only required if you are using Android's data binding feature.

## List of issues

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ version = ["git", "describe", "--match", "[0-9]*", "--dirty"].execute().text.tri

// Maps supported Android plugin versions to the versions of Gradle that support it
def supportedVersions = [
"3.1.0-alpha09": ["4.4", "4.4.1", "4.5-rc-2"],
"3.0.0": ["4.1", "4.2", "4.2.1", "4.3", "4.3.1", "4.4", "4.4.1", "4.5-rc-2"],
"3.0.1": ["4.1", "4.2", "4.2.1", "4.3", "4.3.1", "4.4", "4.4.1", "4.5-rc-2"],
"3.1.0-beta1": ["4.4", "4.4.1", "4.5"],
"3.0.0": ["4.1", "4.2", "4.2.1", "4.3", "4.3.1", "4.4", "4.4.1", "4.5"],
"3.0.1": ["4.1", "4.2", "4.2.1", "4.3", "4.3.1", "4.4", "4.4.1", "4.5"],
]

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.gradle.android

import com.android.build.gradle.AndroidConfig
import com.android.build.gradle.internal.pipeline.StreamBasedTask
import com.android.build.gradle.internal.tasks.CheckManifest
import com.android.build.gradle.internal.tasks.IncrementalTask
Expand Down Expand Up @@ -64,6 +65,14 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
LOGGER.debug("Applying Android workaround {} to {}", workaround.getClass().simpleName, project)
workaround.apply(context)
}

if (currentAndroidVersion.baseVersion >= android("3.1.0-alpha06")) {
project.afterEvaluate {
if (!project.getExtensions().getByType(AndroidConfig).dataBinding.enabled) {
LOGGER.warn("WARNING: Android cache-fix plugin is not required when using Android plugin {} or later, unless Android data binding is used.", currentAndroidVersion)
}
}
}
}

static List<Workaround> getWorkaroundsToApply(VersionNumber androidVersion) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/groovy/org/gradle/android/Versions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Versions {

static {
def versions = new JsonSlurper().parse(AndroidCacheFixPlugin.classLoader.getResource("versions.json"))
PLUGIN_VERSION = android(versions.version)
PLUGIN_VERSION = VersionNumber.parse(versions.version)

def builder = ImmutableMultimap.<VersionNumber, GradleVersion>builder()
versions.supportedVersions.each { androidVersion, gradleVersions ->
Expand Down
33 changes: 31 additions & 2 deletions src/test/groovy/org/gradle/android/PluginApplicationTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PluginApplicationTest extends AbstractTest {
@Unroll
def "does not apply workarounds with Gradle #gradleVersion"() {
def projectDir = temporaryFolder.newFolder()
new SimpleAndroidApp(projectDir, cacheDir, "3.0.0").writeProject()
new SimpleAndroidApp(projectDir, cacheDir, "3.0.0", true).writeProject()
expect:
def result = withGradleVersion(gradleVersion)
.withProjectDir(projectDir)
Expand All @@ -24,7 +24,7 @@ class PluginApplicationTest extends AbstractTest {
@Unroll
def "does not apply workarounds with Android #androidVersion"() {
def projectDir = temporaryFolder.newFolder()
new SimpleAndroidApp(projectDir, cacheDir, androidVersion).writeProject()
new SimpleAndroidApp(projectDir, cacheDir, androidVersion, true).writeProject()
expect:
def result = withGradleVersion("4.1")
.withProjectDir(projectDir)
Expand All @@ -35,4 +35,33 @@ class PluginApplicationTest extends AbstractTest {
where:
androidVersion << ["2.3.0", "3.1.0-alpha01"]
}

@Unroll
def "does #description about being useless for Android version #androidVersion (data binding: #dataBinding)"() {
def projectDir = temporaryFolder.newFolder()
new SimpleAndroidApp(projectDir, cacheDir, androidVersion, dataBinding).writeProject()
def message = "WARNING: Android cache-fix plugin is not required when using Android plugin $androidVersion or later, unless Android data binding is used."

expect:
def result = withGradleVersion("4.5")
.withProjectDir(projectDir)
.withArguments("tasks")
.withDebug(true)
.build()
if (warns) {
assert result.output.contains(message)
} else {
assert !(result.output.contains(message))
}

where:
warns | dataBinding | androidVersion
false | true | "3.0.0"
false | false | "3.0.0"
false | true | "3.0.1"
false | false | "3.0.1"
false | true | "3.1.0-beta1"
true | false | "3.1.0-beta1"
description = warns ? "warn" : "not warn"
}
}
4 changes: 2 additions & 2 deletions src/test/groovy/org/gradle/android/RelocationTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class RelocationTest extends AbstractTest {
println "> Running with $gradleVersion"

def originalDir = temporaryFolder.newFolder()
new SimpleAndroidApp(originalDir, cacheDir, androidVersion).writeProject()
new SimpleAndroidApp(originalDir, cacheDir, androidVersion, true).writeProject()

def relocatedDir = temporaryFolder.newFolder()
new SimpleAndroidApp(relocatedDir, cacheDir, androidVersion).writeProject()
new SimpleAndroidApp(relocatedDir, cacheDir, androidVersion, true).writeProject()

def expectedResults = expectedResults(androidVersion, gradleVersion)

Expand Down
18 changes: 10 additions & 8 deletions src/test/groovy/org/gradle/android/SimpleAndroidApp.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ class SimpleAndroidApp {
final File projectDir
private final File cacheDir
final VersionNumber androidVersion
private final boolean dataBindingEnabled

SimpleAndroidApp(File projectDir, File cacheDir, String androidVersion) {
this(projectDir, cacheDir, android(androidVersion))
SimpleAndroidApp(File projectDir, File cacheDir, String androidVersion, boolean dataBindingEnabled) {
this(projectDir, cacheDir, android(androidVersion), dataBindingEnabled)
}

SimpleAndroidApp(File projectDir, File cacheDir, VersionNumber androidVersion) {
SimpleAndroidApp(File projectDir, File cacheDir, VersionNumber androidVersion, boolean dataBindingEnabled) {
this.dataBindingEnabled = dataBindingEnabled
this.projectDir = projectDir
this.cacheDir = cacheDir
this.androidVersion = androidVersion
Expand All @@ -34,7 +36,7 @@ class SimpleAndroidApp {
directory = "${cacheDir.absolutePath.replace(File.separatorChar, '/' as char)}"
}
}
"""
""".stripIndent()

file("build.gradle") << """
buildscript {
Expand All @@ -50,7 +52,7 @@ class SimpleAndroidApp {
classpath "org.gradle.android:android-cache-fix-gradle-plugin:${Versions.PLUGIN_VERSION}"
}
}
"""
""".stripIndent()

writeActivity(library, libPackage, libraryActivity)
file("${library}/src/main/AndroidManifest.xml") << """<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -88,7 +90,7 @@ class SimpleAndroidApp {
file('settings.gradle') << """
include ':${app}'
include ':${library}'
"""
""".stripIndent()

file("${app}/build.gradle") << subprojectConfiguration("com.android.application") << """
android.defaultConfig.applicationId "org.gradle.android.test.app"
Expand All @@ -104,7 +106,7 @@ class SimpleAndroidApp {
configureAndroidSdkHome()
}

private static subprojectConfiguration(String androidPlugin) {
private subprojectConfiguration(String androidPlugin) {
"""
apply plugin: "$androidPlugin"
apply plugin: "org.gradle.android.cache-fix"
Expand All @@ -117,7 +119,7 @@ class SimpleAndroidApp {
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
dataBinding.enabled = true
dataBinding.enabled = $dataBindingEnabled
defaultConfig {
minSdkVersion 26
targetSdkVersion 26
Expand Down
1 change: 1 addition & 0 deletions src/test/groovy/org/gradle/android/WorkaroundTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ class WorkaroundTest extends Specification {
"3.1.0-alpha07" | ["DataBindingDependencyArtifacts"]
"3.1.0-alpha08" | ["DataBindingDependencyArtifacts"]
"3.1.0-alpha09" | ["DataBindingDependencyArtifacts"]
"3.1.0-beta1" | ["DataBindingDependencyArtifacts"]
}
}

0 comments on commit 81c06b9

Please sign in to comment.