Skip to content

Commit 633c071

Browse files
authored
Merge pull request #119 from runningcode/no/4.2-alpha
Updates for 4.2 alpha
2 parents ff1bdd3 + aeb7033 commit 633c071

File tree

7 files changed

+93
-12
lines changed

7 files changed

+93
-12
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ version = ["git", "describe", "--match", "[0-9]*", "--dirty"].execute().text.tri
1212

1313
// Maps supported Android plugin versions to the versions of Gradle that support it
1414
def supportedVersions = [
15-
"4.2.0-alpha07": ["6.5.1"],
16-
"4.1.0-rc01": ["6.5.1"],
15+
"4.2.0-alpha10": ["6.6.1"],
16+
"4.1.0-rc02": ["6.5.1"],
1717
"4.0.1": ["6.1.1", "6.3", "6.4.1"],
1818
"3.6.4": ["5.6.4", "6.3", "6.4.1"],
1919
"3.5.4": ["5.4.1", "5.6.4", "6.3", "6.4.1"]

gradle/buildScanInit.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import com.gradle.scan.plugin.BuildScanPlugin
33
import org.gradle.util.GradleVersion
44

55
initscript {
6-
def pluginVersion = "3.3.3"
6+
def pluginVersion = "3.4.1"
77

88
repositories {
99
gradlePluginPortal()

src/main/groovy/org/gradle/android/AndroidCacheFixPlugin.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import com.android.build.gradle.tasks.ProcessAndroidResources
77
import com.android.builder.model.Version
88
import com.google.common.collect.ImmutableList
99
import groovy.transform.CompileStatic
10-
import org.gradle.android.workarounds.CompileLibraryResourcesWorkaround
10+
import org.gradle.android.workarounds.CompileLibraryResourcesWorkaround_4_0
1111
import org.gradle.android.workarounds.CompilerArgsProcessor
1212
import org.gradle.android.workarounds.DexFileDependenciesWorkaround
1313
import org.gradle.android.workarounds.MergeJavaResourcesWorkaround
1414
import org.gradle.android.workarounds.MergeNativeLibsWorkaround
1515
import org.gradle.android.workarounds.MergeResourcesWorkaround
16+
import org.gradle.android.workarounds.CompileLibraryResourcesWorkaround_4_2
1617
import org.gradle.android.workarounds.RoomSchemaLocationWorkaround
1718
import org.gradle.android.workarounds.Workaround
1819
import org.gradle.android.workarounds.WorkaroundContext
@@ -46,7 +47,8 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
4647
new MergeJavaResourcesWorkaround(),
4748
new MergeNativeLibsWorkaround(),
4849
new RoomSchemaLocationWorkaround(),
49-
new CompileLibraryResourcesWorkaround(),
50+
new CompileLibraryResourcesWorkaround_4_0(),
51+
new CompileLibraryResourcesWorkaround_4_2(),
5052
new MergeResourcesWorkaround(),
5153
new DexFileDependenciesWorkaround(),
5254
)

src/main/groovy/org/gradle/android/workarounds/CompileLibraryResourcesWorkaround.groovy renamed to src/main/groovy/org/gradle/android/workarounds/CompileLibraryResourcesWorkaround_4_0.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import java.lang.reflect.Field
1313
* Fixes the cacheability issue with CompileLibraryResourcesWorkaround where the mergedLibraryResourcesDir field is
1414
* treated as an input with absolute path sensitivity.
1515
*/
16-
@AndroidIssue(introducedIn = "4.0.0", fixedIn = [], link = "https://issuetracker.google.com/issues/155218379")
17-
class CompileLibraryResourcesWorkaround implements Workaround {
16+
@AndroidIssue(introducedIn = "4.0.0", fixedIn = ["4.2.0-alpha09"], link = "https://issuetracker.google.com/issues/155218379")
17+
class CompileLibraryResourcesWorkaround_4_0 implements Workaround {
1818
// This task is new in AGP 4.0.0 so use Class.forName to allow for backward compatibility with older AGP versions.
1919
static Class<?> getAndroidTaskClass() {
2020
return Class.forName('com.android.build.gradle.tasks.CompileLibraryResourcesTask')
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.gradle.android.workarounds
2+
3+
import org.gradle.android.AndroidIssue
4+
import org.gradle.api.Project
5+
import org.gradle.api.Task
6+
import org.gradle.api.file.ConfigurableFileCollection
7+
import org.gradle.api.tasks.PathSensitivity
8+
9+
import java.lang.reflect.Field
10+
11+
12+
/**
13+
* Fixes the cacheability issue with CompileLibraryResourcesWorkaround where the inputDirectories field is
14+
* treated as an input with absolute path sensitivity.
15+
* This is the same as the {@link CompileLibraryResourcesWorkaround_4_0} but the field was renamed with a new type
16+
* in 4.2.0-alpha09.
17+
*/
18+
@AndroidIssue(introducedIn = "4.2.0-alpha09", fixedIn = [], link = "https://issuetracker.google.com/issues/155218379")
19+
class CompileLibraryResourcesWorkaround_4_2 implements Workaround {
20+
// This task is new in AGP 4.0.0 so use Class.forName to allow for backward compatibility with older AGP versions.
21+
static Class<?> getAndroidTaskClass() {
22+
return Class.forName('com.android.build.gradle.tasks.CompileLibraryResourcesTask')
23+
}
24+
25+
String propertyName = "inputDirectories"
26+
27+
public void setPropertyValue(Task task, ConfigurableFileCollection directoryProperty) {
28+
Field field = task.class.getDeclaredFields().find { it.name == "__${propertyName}__" }
29+
field.setAccessible(true)
30+
field.set(task, directoryProperty)
31+
}
32+
33+
@Override
34+
void apply(WorkaroundContext context) {
35+
Project project = context.project
36+
project.tasks.withType(androidTaskClass).configureEach { Task task ->
37+
ConfigurableFileCollection originalPropertyValue
38+
// Create a synthetic input with the original property value and RELATIVE path sensitivity
39+
project.gradle.taskGraph.beforeTask {
40+
if (it == task) {
41+
originalPropertyValue = task.getProperty(propertyName)
42+
def dummyProperty = project.objects.fileCollection()
43+
// Non-existent file to give the ConfigurableFileCollection a value.
44+
dummyProperty.setFrom(project.file('/doesnt-exist'))
45+
setPropertyValue(task, dummyProperty)
46+
task.inputs.files(originalPropertyValue)
47+
.withPathSensitivity(PathSensitivity.RELATIVE)
48+
.withPropertyName("${propertyName}.workaround")
49+
.optional()
50+
}
51+
}
52+
// Set the task property back to its original value
53+
task.doFirst {
54+
setPropertyValue(task, originalPropertyValue)
55+
}
56+
}
57+
}
58+
59+
@Override
60+
boolean canBeApplied(Project project) {
61+
return true
62+
}
63+
}
64+

src/test/groovy/org/gradle/android/CrossVersionOutcomeAndRelocationTest.groovy

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class CrossVersionOutcomeAndRelocationTest extends AbstractTest {
139139
def isAndroid36xOrHigher = androidVersion >= android("3.6.0")
140140
def isAndroid40xOrHigher = androidVersion >= android("4.0.0-beta01")
141141
def isAndroid40x = androidVersion >= android("4.0.0") && androidVersion < android("4.1.0-alpha01")
142+
def isAndroid40xTo41x = androidVersion >= android("4.0.0") && androidVersion <= android("4.2.0-alpha01")
142143
def isAndroid41xOrHigher = androidVersion >= android("4.1.0-alpha01")
143144
def isAndroid42xOrHigher = androidVersion >= android("4.2.0-alpha01")
144145
def builder = new ExpectedOutcomeBuilder()
@@ -186,6 +187,10 @@ class CrossVersionOutcomeAndRelocationTest extends AbstractTest {
186187
android40xOnlyExpectations(builder)
187188
}
188189

190+
if (isAndroid40xTo41x) {
191+
android40xTo41xExpectation(builder)
192+
}
193+
189194
// Applies to anything 4.1.0 or higher
190195
if (isAndroid41xOrHigher) {
191196
android41xOrHigherExpectations(builder)
@@ -443,13 +448,16 @@ class CrossVersionOutcomeAndRelocationTest extends AbstractTest {
443448
builder.expect(':library:bundleLibCompileToJarDebug', FROM_CACHE)
444449
builder.expect(':library:bundleLibResDebug', NO_SOURCE)
445450
builder.expect(':library:bundleLibResRelease', NO_SOURCE)
446-
builder.expect(':library:bundleLibRuntimeToJarDebug', FROM_CACHE)
447451
builder.expect(':library:bundleLibCompileToJarRelease', FROM_CACHE)
448-
builder.expect(':library:bundleLibRuntimeToJarRelease', FROM_CACHE)
449452
builder.expect(':app:collectReleaseDependencies', SUCCESS)
450453
builder.expect(':app:sdkReleaseDependencyData', SUCCESS)
451454
}
452455

456+
static void android40xTo41xExpectation(ExpectedOutcomeBuilder builder) {
457+
builder.expect(':library:bundleLibRuntimeToJarDebug', FROM_CACHE)
458+
builder.expect(':library:bundleLibRuntimeToJarRelease', FROM_CACHE)
459+
}
460+
453461
static void android41xOrHigherExpectations(ExpectedOutcomeBuilder builder) {
454462
builder.expect(':library:dataBindingTriggerDebug', FROM_CACHE)
455463
builder.expect(':library:dataBindingTriggerRelease', FROM_CACHE)
@@ -479,5 +487,12 @@ class CrossVersionOutcomeAndRelocationTest extends AbstractTest {
479487
static void android42xOrHigherExpectations(ExpectedOutcomeBuilder builder) {
480488
builder.expect(':app:desugarDebugFileDependencies', FROM_CACHE)
481489
builder.expect(':app:desugarReleaseFileDependencies', FROM_CACHE)
490+
// Renamed from ToJar to ToDir
491+
builder.expect(':library:bundleLibRuntimeToDirDebug', FROM_CACHE)
492+
builder.expect(':library:bundleLibRuntimeToDirRelease', FROM_CACHE)
493+
builder.expect(':app:optimizeReleaseResources', FROM_CACHE)
494+
// New non-cacheable tasks in 4.2.0-alpha10:
495+
builder.expect(':app:writeReleaseApplicationId', SUCCESS)
496+
builder.expect(':app:analyticsRecordingRelease', SUCCESS)
482497
}
483498
}

src/test/groovy/org/gradle/android/WorkaroundTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class WorkaroundTest extends Specification {
1212
workarounds.collect { it.class.simpleName.replaceAll(/Workaround/, "") }.sort() == expectedWorkarounds.sort()
1313
where:
1414
androidVersion | expectedWorkarounds
15-
"4.2.0-alpha07" | ['RoomSchemaLocation', 'CompileLibraryResources', 'MergeResources', 'DexFileDependencies']
16-
"4.1.0-rc01" | ['RoomSchemaLocation', 'CompileLibraryResources', 'MergeResources', 'DexFileDependencies']
17-
"4.0.1" | ['MergeJavaResources', 'MergeNativeLibs', 'RoomSchemaLocation', 'CompileLibraryResources', 'MergeResources', 'DexFileDependencies']
15+
"4.2.0-alpha10" | ['RoomSchemaLocation', 'CompileLibraryResources_4_2', 'MergeResources', 'DexFileDependencies']
16+
"4.1.0-rc02" | ['RoomSchemaLocation', 'CompileLibraryResources_4_0', 'MergeResources', 'DexFileDependencies']
17+
"4.0.1" | ['MergeJavaResources', 'MergeNativeLibs', 'RoomSchemaLocation', 'CompileLibraryResources_4_0', 'MergeResources', 'DexFileDependencies']
1818
"3.6.4" | ['MergeJavaResources', 'MergeNativeLibs', 'RoomSchemaLocation', 'DexFileDependencies']
1919
"3.5.4" | ['MergeJavaResources', 'RoomSchemaLocation', 'DexFileDependencies']
2020
}

0 commit comments

Comments
 (0)