Skip to content

Commit

Permalink
Support Task Configuration Avoidance
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanenicolas committed Feb 9, 2019
1 parent af80c0a commit 4387cf1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ buildscript {
'compileSdk': 28,

'androidTools': '26.2.0',
'kotlin': '1.2.71',

'kotlin': '1.3.11',
'release': '8.8.1',
]

ext.deps = [
android: [
'runtime': 'com.google.android:android:4.1.1.4',
'gradlePlugin': "com.android.tools.build:gradle:3.1.4",
'gradlePlugin': "com.android.tools.build:gradle:3.3.0",
],
'androidx': [
'core': "androidx.core:core:1.0.0",
Expand Down Expand Up @@ -57,7 +56,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.android.tools.build:gradle:3.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.16'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ class ButterKnifePlugin : Plugin<Project> {
val rPackage = getPackageName(variant)
val once = AtomicBoolean()
variant.outputs.all { output ->
val processResources = output.processResources
val processResources = output.processResourcesProvider

// Though there might be multiple outputs, their R files are all the same. Thus, we only
// need to configure the task once with the R.java input and action.
if (once.compareAndSet(false, true)) {
// TODO: switch to better API once exists in AGP (https://issuetracker.google.com/118668005)
val rFile =
project.files(
when (processResources) {
is GenerateLibraryRFileTask -> processResources.textSymbolOutputFile
is LinkApplicationAndroidResourcesTask -> processResources.textSymbolOutputFile
else -> throw RuntimeException(
"Minimum supported Android Gradle Plugin is 3.1.0")
})
.builtBy(processResources)
project.tasks.create("generate${variant.name.capitalize()}R2", R2Generator::class.java) {
val processResourcesTask = processResources.get()
it.outputDir = outputDir
it.rFile = rFile
// TODO: switch to better API once exists in AGP (https://issuetracker.google.com/118668005)
it.rFile = project.files(
when (processResourcesTask) {
is GenerateLibraryRFileTask -> processResourcesTask.textSymbolOutputFile
is LinkApplicationAndroidResourcesTask -> processResourcesTask.textSymbolOutputFile
else -> throw RuntimeException(
"Minimum supported Android Gradle Plugin is 3.3.0")
})
.builtBy(processResourcesTask)
it.packageName = rPackage
it.className = "R2"
// TODO: switch to as task provider when AGP supports it: (https://issuetracker.google.com/issues/123655659)
variant.registerJavaGeneratingTask(it, outputDir)
}
}
Expand Down
3 changes: 1 addition & 2 deletions butterknife/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="butterknife"/>
<manifest package="butterknife.core"/>

0 comments on commit 4387cf1

Please sign in to comment.