Skip to content

Commit 65377e5

Browse files
authored
Merge pull request #141 from gradle/no/disable-merge-native-libs
Disable caching for MergeNativeLibs.
2 parents 14571ea + 61c3705 commit 65377e5

File tree

5 files changed

+21
-62
lines changed

5 files changed

+21
-62
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.google.common.collect.ImmutableList
99
import groovy.transform.CompileStatic
1010
import org.gradle.android.workarounds.CompileLibraryResourcesWorkaround_4_0
1111
import org.gradle.android.workarounds.CompilerArgsProcessor
12-
import org.gradle.android.workarounds.DexFileDependenciesWorkaround
1312
import org.gradle.android.workarounds.MergeJavaResourcesWorkaround
1413
import org.gradle.android.workarounds.MergeNativeLibsWorkaround
1514
import org.gradle.android.workarounds.MergeResourcesWorkaround
@@ -89,8 +88,7 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
8988
new RoomSchemaLocationWorkaround(),
9089
new CompileLibraryResourcesWorkaround_4_0(),
9190
new CompileLibraryResourcesWorkaround_4_2(),
92-
new MergeResourcesWorkaround(),
93-
new DexFileDependenciesWorkaround()
91+
new MergeResourcesWorkaround()
9492
)
9593
} else {
9694
return Collections.emptyList()

src/main/groovy/org/gradle/android/workarounds/DexFileDependenciesWorkaround.groovy

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/groovy/org/gradle/android/workarounds/MergeNativeLibsWorkaround.groovy

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,19 @@ package org.gradle.android.workarounds
22

33
import com.android.build.gradle.internal.tasks.MergeNativeLibsTask
44
import org.gradle.android.AndroidIssue
5-
import org.gradle.api.Task
6-
import org.gradle.api.file.FileCollection
7-
8-
import java.lang.reflect.Field
9-
10-
/**
11-
* Fixes the cacheability issue with MergeNativeLibsTask where the projectNativeLibs field is treated as an input with
12-
* absolute path sensitivity. This mostly comes up when either native libraries are built with the application
13-
* or RenderScript files are compiled as part of the build.
14-
*
15-
* In 3.5.x, projectNativeLibs is not directly backed by state in the Task object. Instead, it is effectively a
16-
* method that calculates a new FileCollection from variantScope every time it is called. So we only
17-
* support this workaround for 3.6.x and 4.0.x.
18-
*/
19-
@AndroidIssue(introducedIn = "3.6.0", fixedIn = ["4.1.0-alpha09"], link = "https://issuetracker.google.com/issues/140602655")
20-
class MergeNativeLibsWorkaround extends AbstractAbsolutePathWorkaround {
21-
Class<?> androidTaskClass = MergeNativeLibsTask.class
22-
String propertyName = "projectNativeLibs"
5+
import org.gradle.api.Project
236

7+
@AndroidIssue(introducedIn = "3.5.0", fixedIn = [], link = "https://issuetracker.google.com/issues/153088766")
8+
class MergeNativeLibsWorkaround implements Workaround {
249
@Override
2510
void apply(WorkaroundContext context) {
26-
super.apply(context)
11+
context.project.tasks.withType(MergeNativeLibsTask).configureEach {
12+
outputs.doNotCacheIf("Caching MergeNativeLibs is unlikely to provide positive performance results.", {true })
13+
}
2714
}
2815

29-
public void setPropertyValue(Task task, FileCollection fileCollection) {
30-
// The projectNativeLibs input is a decorated field without a setter in 3.6.x and 4.0.x
31-
Field field = task.class.getDeclaredFields().find { it.name == "__${propertyName}__" }
32-
33-
if (field != null) {
34-
field.setAccessible(true)
35-
field.set(task, fileCollection)
36-
}
16+
@Override
17+
boolean canBeApplied(Project project) {
18+
return true
3719
}
3820
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,16 +418,16 @@ class CrossVersionOutcomeAndRelocationTest extends AbstractTest {
418418
builder.expect(':app:dexBuilderRelease', FROM_CACHE)
419419
builder.expect(':app:extractDeepLinksDebug', FROM_CACHE)
420420
builder.expect(':app:extractDeepLinksRelease', FROM_CACHE)
421-
builder.expect(':app:mergeDebugNativeLibs', FROM_CACHE)
422-
builder.expect(':app:mergeReleaseNativeLibs', FROM_CACHE)
421+
builder.expect(':app:mergeDebugNativeLibs', SUCCESS)
422+
builder.expect(':app:mergeReleaseNativeLibs', SUCCESS)
423423
builder.expect(':library:copyDebugJniLibsProjectAndLocalJars', FROM_CACHE)
424424
builder.expect(':library:copyDebugJniLibsProjectOnly', FROM_CACHE)
425425
builder.expect(':library:copyReleaseJniLibsProjectAndLocalJars', FROM_CACHE)
426426
builder.expect(':library:copyReleaseJniLibsProjectOnly', FROM_CACHE)
427427
builder.expect(':library:extractDeepLinksDebug', FROM_CACHE)
428428
builder.expect(':library:extractDeepLinksRelease', FROM_CACHE)
429-
builder.expect(':library:mergeDebugNativeLibs', FROM_CACHE)
430-
builder.expect(':library:mergeReleaseNativeLibs', FROM_CACHE)
429+
builder.expect(':library:mergeDebugNativeLibs', SUCCESS)
430+
builder.expect(':library:mergeReleaseNativeLibs', SUCCESS)
431431
builder.expect(':library:parseDebugLocalResources', FROM_CACHE)
432432
builder.expect(':library:parseReleaseLocalResources', FROM_CACHE)
433433
builder.expect(':library:syncDebugLibJars', FROM_CACHE)
@@ -492,8 +492,8 @@ class CrossVersionOutcomeAndRelocationTest extends AbstractTest {
492492
}
493493

494494
static void android42xOrHigherExpectations(ExpectedOutcomeBuilder builder) {
495-
builder.expect(':app:desugarDebugFileDependencies', FROM_CACHE)
496-
builder.expect(':app:desugarReleaseFileDependencies', FROM_CACHE)
495+
builder.expect(':app:desugarDebugFileDependencies', SUCCESS)
496+
builder.expect(':app:desugarReleaseFileDependencies', SUCCESS)
497497
// Renamed from ToJar to ToDir
498498
builder.expect(':library:bundleLibRuntimeToDirDebug', FROM_CACHE)
499499
builder.expect(':library:bundleLibRuntimeToDirRelease', FROM_CACHE)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ class WorkaroundTest extends Specification {
1313
workarounds.collect { it.class.simpleName.replaceAll(/Workaround/, "") }.sort() == expectedWorkarounds.sort()
1414
where:
1515
androidVersion | expectedWorkarounds
16-
"4.2.0-beta04" | ['RoomSchemaLocation', 'CompileLibraryResources_4_2', 'MergeResources', 'DexFileDependencies']
17-
"4.1.2" | ['RoomSchemaLocation', 'CompileLibraryResources_4_0', 'MergeResources', 'DexFileDependencies']
18-
"4.0.2" | ['MergeJavaResources', 'MergeNativeLibs', 'RoomSchemaLocation', 'CompileLibraryResources_4_0', 'MergeResources', 'DexFileDependencies']
19-
"3.6.4" | ['MergeJavaResources', 'MergeNativeLibs', 'RoomSchemaLocation', 'DexFileDependencies']
20-
"3.5.4" | ['MergeJavaResources', 'RoomSchemaLocation', 'DexFileDependencies']
16+
"4.2.0-beta04" | ['RoomSchemaLocation', 'CompileLibraryResources_4_2', 'MergeResources', 'MergeNativeLibs']
17+
"4.1.2" | ['RoomSchemaLocation', 'CompileLibraryResources_4_0', 'MergeResources', 'MergeNativeLibs']
18+
"4.0.2" | ['MergeJavaResources', 'MergeNativeLibs', 'RoomSchemaLocation', 'CompileLibraryResources_4_0', 'MergeResources']
19+
"3.6.4" | ['MergeJavaResources', 'MergeNativeLibs', 'RoomSchemaLocation']
20+
"3.5.4" | ['MergeJavaResources', 'RoomSchemaLocation', 'MergeNativeLibs']
2121
}
2222
}

0 commit comments

Comments
 (0)