Skip to content

Commit da0badc

Browse files
authored
Disable caching of LibraryJniLibs task (#207)
1 parent 676249f commit da0badc

File tree

6 files changed

+49
-14
lines changed

6 files changed

+49
-14
lines changed

.github/dco.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Disable sign-off chcecking for members of the Gradle GitHub organization
1+
# Disable sign-off checking for members of the Gradle GitHub organization
22
require:
33
members: false

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ room {
125125
* There can only be a single schema export directory for the project - you cannot configure variant-specific export
126126
directories. Schemas exported from different variants will be merged in the directory specified in the "room" extension.
127127

128-
### MergeNativeLibs, StripDebugSymbols, MergeJavaResources, MergeSourceSetFolders, BundleLibraryClassesJar and DataBindingMergeDependencyArtifacts Workarounds
128+
### MergeNativeLibs, StripDebugSymbols, MergeJavaResources, MergeSourceSetFolders, BundleLibraryClassesJar, DataBindingMergeDependencyArtifacts and LibraryJniLibs Workarounds
129129

130-
It has been observed that caching the `MergeNativeLibsTask`, `StripDebugSymbols`, `MergeJavaResources`, `MergeSourceSetFolders`, `BundleLibraryClassesJar` and `DataBindingMergeDependencyArtifacts` tasks rarely provide any significant positive avoidance savings. In fact, they frequently provide negative savings, especially when fetched from a remote cache node. As such, these workarounds actually disable caching for these tasks.
130+
It has been observed that caching the `MergeNativeLibsTask`, `StripDebugSymbols`, `MergeJavaResources`, `MergeSourceSetFolders`, `BundleLibraryClassesJar`, `DataBindingMergeDependencyArtifacts` and `LibraryJniLibs` tasks rarely provide any significant positive avoidance savings. In fact, they frequently provide negative savings, especially when fetched from a remote cache node. As such, these workarounds actually disable caching for these tasks.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.gradle.android.workarounds.CompileLibraryResourcesWorkaround_4_0
88
import org.gradle.android.workarounds.CompileLibraryResourcesWorkaround_7_0
99
import org.gradle.android.workarounds.CompilerArgsProcessor
1010
import org.gradle.android.workarounds.DataBindingMergeDependencyArtifactsWorkaround
11+
import org.gradle.android.workarounds.LibraryJniLibsWorkaround
1112
import org.gradle.android.workarounds.MergeJavaResourcesWorkaround
1213
import org.gradle.android.workarounds.MergeNativeLibsWorkaround
1314
import org.gradle.android.workarounds.MergeResourcesWorkaround
@@ -49,7 +50,8 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
4950
new StripDebugSymbolsWorkaround(),
5051
new BundleLibraryClassesWorkaround(),
5152
new BundleLibraryClassesWorkaround_4_2(),
52-
new DataBindingMergeDependencyArtifactsWorkaround()
53+
new DataBindingMergeDependencyArtifactsWorkaround(),
54+
new LibraryJniLibsWorkaround()
5355
)
5456
} else {
5557
return Collections.emptyList()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.gradle.android.workarounds;
2+
3+
import groovy.transform.CompileStatic;
4+
import org.gradle.android.AndroidIssue;
5+
import org.gradle.api.Project
6+
import org.gradle.api.Task;
7+
8+
/**
9+
* Disables caching of the LibraryJniLibsTask task which is mostly disk bound and
10+
* unlikely to provide positive performance benefits.
11+
*/
12+
@AndroidIssue(introducedIn = "3.6.0", fixedIn = [], link = "https://issuetracker.google.com/issues/200002454")
13+
@CompileStatic
14+
class LibraryJniLibsWorkaround implements Workaround {
15+
// This task is new in AGP 3.6.0 so use Class.forName to allow for backward compatibility with older AGP versions.
16+
static Class<?> getAndroidTaskClass() {
17+
return Class.forName('com.android.build.gradle.internal.tasks.LibraryJniLibsTask')
18+
}
19+
20+
private static final String CACHING_ENABLED_PROPERTY = "org.gradle.android.cache-fix.LibraryJniLibs.caching.enabled"
21+
22+
@Override
23+
void apply(WorkaroundContext context) {
24+
context.project.tasks.withType(androidTaskClass).configureEach {Task task ->
25+
task.outputs.doNotCacheIf("Caching LibraryJniLibs is unlikely to provide positive performance results.", { true })
26+
}
27+
}
28+
29+
@Override
30+
boolean canBeApplied(Project project) {
31+
return !SystemPropertiesCompat.getBoolean(CACHING_ENABLED_PROPERTY, project)
32+
}
33+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,10 @@ class CrossVersionOutcomeAndRelocationTest extends AbstractTest {
454454
builder.expect(':app:dexBuilderRelease', FROM_CACHE)
455455
builder.expect(':app:extractDeepLinksDebug', FROM_CACHE)
456456
builder.expect(':app:extractDeepLinksRelease', FROM_CACHE)
457-
builder.expect(':library:copyDebugJniLibsProjectAndLocalJars', FROM_CACHE)
458-
builder.expect(':library:copyDebugJniLibsProjectOnly', FROM_CACHE)
459-
builder.expect(':library:copyReleaseJniLibsProjectAndLocalJars', FROM_CACHE)
460-
builder.expect(':library:copyReleaseJniLibsProjectOnly', FROM_CACHE)
457+
builder.expect(':library:copyDebugJniLibsProjectAndLocalJars', SUCCESS)
458+
builder.expect(':library:copyDebugJniLibsProjectOnly', SUCCESS)
459+
builder.expect(':library:copyReleaseJniLibsProjectAndLocalJars', SUCCESS)
460+
builder.expect(':library:copyReleaseJniLibsProjectOnly', SUCCESS)
461461
builder.expect(':library:extractDeepLinksDebug', FROM_CACHE)
462462
builder.expect(':library:extractDeepLinksRelease', FROM_CACHE)
463463
builder.expect(':library:parseDebugLocalResources', FROM_CACHE)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class WorkaroundTest extends Specification {
1212
workarounds.collect { it.class.simpleName.replaceAll(/Workaround/, "") }.sort() == expectedWorkarounds.sort()
1313
where:
1414
androidVersion | expectedWorkarounds
15-
"7.1.0-alpha11" | ['DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_7_0']
16-
"7.0.2" | ['DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_7_0']
17-
"4.2.2" | ['DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_2', 'MergeResources']
18-
"4.1.3" | ['DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
19-
"4.0.2" | ['DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
20-
"3.6.4" | ['DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs']
15+
"7.1.0-alpha11" | ['LibraryJniLibs', 'DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_7_0']
16+
"7.0.2" | ['LibraryJniLibs', 'DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_7_0']
17+
"4.2.2" | ['LibraryJniLibs', 'DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_2', 'MergeResources']
18+
"4.1.3" | ['LibraryJniLibs', 'DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
19+
"4.0.2" | ['LibraryJniLibs', 'DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
20+
"3.6.4" | ['LibraryJniLibs', 'DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs']
2121
"3.5.4" | ['DataBindingMergeDependencyArtifacts', 'BundleLibraryClasses', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs']
2222
}
2323
}

0 commit comments

Comments
 (0)