Coder Social home page Coder Social logo

gradle / android-cache-fix-gradle-plugin Goto Github PK

View Code? Open in Web Editor NEW
476.0 30.0 46.0 2.64 MB

Gradle plugin that fixes Android build caching problems.

Home Page: https://plugins.gradle.org/plugin/org.gradle.android.cache-fix

License: Apache License 2.0

Groovy 89.77% Java 8.91% Kotlin 1.32%
gradle android

android-cache-fix-gradle-plugin's Introduction

This repository is maintained by the Develocity Solutions team, as one of several publicly available repositories:

Android Cache Fix Gradle Plugin

Verify Build Plugin Portal Revved up by Develocity

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. For other versions, please see older versions.

  • Supported Gradle versions: 7.0+
  • Supported Android Gradle Plugin versions: 7.0+, including alpha, beta, and rc versions
  • Supported Kotlin versions: 1.7.0+

We only test against the latest patch versions of each minor version of Android Gradle Plugin. This means that although it may work perfectly well with an older patch version (say 7.0.1), we do not test against these older patch versions, so the latest patch version is the only version from that minor release that we technically support.

The Android cache fix plugin is compatible with the Gradle Configuration Cache when used in conjunction with Android Gradle Plugin 4.2.0 and above. Using the configuration cache with earlier versions of the Android Gradle Plugin is not supported.

Should I use this?

Take a look at the list of issues especially unresolved issues. If any of these apply to your project, you can use this plugin to solve them.

How can I discover issues?

You can discover issues by using the task input comparison tool in Develocity. More information about how to diagnose cache misses here. You can compare the inputs of a build that seeds the build cache - typically CI - with a build that consumes from the build cache like a local developer build. If you discover an issue related to the Android Gradle Plugin, please file an issue in the Android Bug Tracker. You can also file an issue here and we can see if a workaround is possible.

Applying the plugin

This plugin should be applied anywhere the com.android.application or com.android.library plugins are applied. We recommend adding the plugin to your project's conventions plugin.

Kotlin
// in build.grade.kts for convention plugin build
dependencies {
  // ...
  implementation("org.gradle.android.cache-fix:org.gradle.android.cache-fix.gradle.plugin:3.0.1")
  // ...
}

// in com.myconventions.build.gradle.kts
plugins {
    id("com.android.application") // or "com.android.library"
  // Add this next line to your existing convention plugin.
    id("org.gradle.android.cache-fix")
}
Groovy
// in build.grade for convention plugin build
dependencies {
    // ...
    implementation("org.gradle.android.cache-fix:org.gradle.android.cache-fix.gradle.plugin:3.0.1")
    // ...
}

// in com.myconventions.build.gradle
plugins {
    id 'com.android.application' // or 'com.android.library'
    // Add this next line to your existing convention plugin.
    id 'org.gradle.android.cache-fix'
}

If you are not using convention plugins and would like a quick way of testing the plugin you can alternatively place it in the root project's build.gradle (change '3.0.1' to the latest version of the cache fix plugin here). We discourage this approach because it uses cross project configuration.

Kotlin
plugins {
    id("org.gradle.android.cache-fix") version "3.0.1" apply false
}

subprojects {
    plugins.withType<com.android.build.gradle.api.AndroidBasePlugin>() {
        apply(plugin = "org.gradle.android.cache-fix")
    }
}
Groovy
plugins {
    id "org.gradle.android.cache-fix" version "3.0.1" apply false
}

subprojects {
    plugins.withType(com.android.build.gradle.api.AndroidBasePlugin) {
        project.apply plugin: "org.gradle.android.cache-fix"
    }
}

List of issues

You can take a look at the list of issues that the plugin fixes by looking at the classes in org.gradle.android.workarounds. It contains a number of Workaround implementations annotated with @AndroidIssue. The Javadoc has a short description of the problem, and the annotation gives information about when the problem was introduced, what is the first version of the Android plugin that fixes it, and there's a link to the issue on Android's issue tracker:

/**
 * Fix {@link org.gradle.api.tasks.compile.CompileOptions#getBootClasspath()} introducing relocatability problems for {@link AndroidJavaCompile}.
 */
@AndroidIssue(introducedIn = "3.0.0", fixedIn = "3.1.0-alpha06", link = "https://issuetracker.google.com/issues/68392933")
static class AndroidJavaCompile_BootClasspath_Workaround implements Workaround {
    // ...
}

Unresolved Issues

Please vote for the linked issues if you are experiencing them in your project.

Fixed by the Android Cache Fix plugin, but unresolved in any current or upcoming preview release of the Android Gradle Plugin:

Not fixed by the Android Cache Fix plugin since it has no workaround:

Not fixed by the Android Cache Fix plugin since it has no workaround but is fixed in Android Gradle Plugin 8.0.0 or newer:

Room

The Room annotation processor causes cache misses: https://issuetracker.google.com/issues/132245929. To work around this issue, please apply the Room Gradle Plugin.

Implementation Notes

MergeNativeLibs, StripDebugSymbols, MergeJavaResources, MergeSourceSetFolders, BundleLibraryClassesJar, DataBindingMergeDependencyArtifacts, LibraryJniLibs and ZipMerging Workarounds

It has been observed that caching the MergeNativeLibsTask, StripDebugSymbols, MergeSourceSetFolders, BundleLibraryClassesJar, DataBindingMergeDependencyArtifacts, LibraryJniLibs and ZipMergingTask 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 disable caching for these tasks.

Older Android Gradle Plugin Versions

Use Android Cache Fix Plugin 2.4.6 when using an older Android Gradle Plugin version.

  • Supported Gradle versions: 5.4.1+
  • Supported Android Gradle Plugin versions: 3.5.4, 3.6.4, 4.0.1, 4.1.3, 4.2.2

Older Kotlin Gradle Plugin Versions

Use Android Cache Fix Plugin 2.6.0 when using an older Kotlin Gradle Plugin version.

  • Supported Kotlin versions: [1.3.72-1.5.32]

Learn more

Visit our website to learn more about Develocity.

License

The Android Cache Fix Gradle plugin is open-source software released under the Apache 2.0 License.

android-cache-fix-gradle-plugin's People

Contributors

alextu avatar bacecek avatar big-guy avatar bigdaz avatar bot-githubaction avatar c00ler avatar cdsap avatar clayburn avatar cristiangm avatar dependabot[bot] avatar erichaagdev avatar etiennestuder avatar ghale avatar github-actions[bot] avatar goooler avatar jeremydyoung avatar johnjohndoe avatar jprinet avatar jrodbx avatar jthurne avatar louiscad avatar lptr avatar osipxd avatar ribafish avatar rnett avatar runningcode avatar thegarlynch avatar tylerbertrand avatar zacsweers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-cache-fix-gradle-plugin's Issues

Add 4.2.x to PluginApplicationTest when released.

Right now since 4.2.x isn't released, the build fails being unable to find the plugin:

Could not resolve all artifacts for configuration ':classpath'.
|         > Could not find com.android.tools.build:gradle:4.2.0-alpha01.

NPE on subproject mergeProduct1Flavor1JavaResource task when using DashO

I'm having issues with a multi project build when using this plugin and DashO plugin at the same time in one subproject. My project is as follows:

  • build.gradle
    • projectA (com.android.library) -> Subproject with NPE issue. DashO is only applied in this project. Dependency on projectB
    • projectB (com.android.library) -> Depencency on other (com.android.library) sub-projects
    • projects (com.android.library)
    • projectN (com.android.application) -> Dependency on projectA

These scenarios work (always with org.gradle.caching=true):

  • Apply android-cache-fix-gradle-plugin as suggested in readme file (all subprojects). Disable dasho plugin on projectA
  • Disable android-cache-fix-gradle-plugin for all projects and enable dasho plugin on projectA
  • Apply dasho plugin on projectA and android-cache-fix-gradle-plugin for all projects except for projectA

Details:

  • gradle version: 6.1.1
  • com.android.tools.build:gradle:4.0.0
  • DashO plugin: "com.preemptive.dasho:dasho-android:1.2.+". Installed DashO version: 10.3.0
  • org.gradle.android.cache-fix plugin version: 1.0.7

Issue in org.gradle.android.workarounds.AbstractAbsolutePathWorkaround on line 28. Stacktrace:

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':projectA:mergeProduct1Flavor1ReleaseJavaResource'.
> java.lang.NullPointerException (no error message)
* Try:
Run with --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':projectA:mergeProduct1Flavor1ReleaseJavaResource'.
	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:73)
	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
	at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
	at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:41)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:372)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:359)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:352)
	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:338)
	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: java.lang.NullPointerException
	at org.gradle.api.internal.tasks.DefaultTaskInputs.unpackVarargs(DefaultTaskInputs.java:111)
	at org.gradle.api.internal.tasks.DefaultTaskInputs.access$100(DefaultTaskInputs.java:46)
	at org.gradle.api.internal.tasks.DefaultTaskInputs$1.call(DefaultTaskInputs.java:102)
	at org.gradle.api.internal.tasks.DefaultTaskInputs$1.call(DefaultTaskInputs.java:99)
	at org.gradle.util.GUtil.uncheckedCall(GUtil.java:425)
	at org.gradle.api.internal.tasks.TaskMutator.mutate(TaskMutator.java:45)
	at org.gradle.api.internal.tasks.DefaultTaskInputs.files(DefaultTaskInputs.java:99)
	at org.gradle.api.internal.tasks.DefaultTaskInputs.files(DefaultTaskInputs.java:45)
	at org.gradle.android.workarounds.AbstractAbsolutePathWorkaround$_apply_closure1$_closure2.doCall(AbstractAbsolutePathWorkaround.groovy:28)
	at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:41)
	at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:25)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:42)
	at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:231)
	at org.gradle.internal.event.BroadcastDispatch$SingletonDispatch.dispatch(BroadcastDispatch.java:150)
	at org.gradle.internal.event.AbstractBroadcastDispatch.dispatch(AbstractBroadcastDispatch.java:58)
	at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:325)
	at org.gradle.internal.event.BroadcastDispatch$CompositeDispatch.dispatch(BroadcastDispatch.java:235)
	at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:141)
	at org.gradle.internal.event.ListenerBroadcast.dispatch(ListenerBroadcast.java:37)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy107.beforeExecute(Unknown Source)
	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:66)
	... 22 more

Support AGP 4.0.0 GA

It just dropped today. When I updated my project to use it, I got the following error from this plugin:

Android plugin 4.0.0 is not supported by Android cache fix plugin. Supported Android plugin versions: 3.5.0, 3.5.1, 3.5.2, 3.5.3, 3.6.0, 3.6.1, 3.6.2, 3.6.3, 4.0.0-rc01.

Add deprecation checks to integration tests

We currently don't check whether we add any new deprecations with the nasty hacks we do to workaround caching problems. We should at least check and fail the test if a new deprecation is caused. We should require a deprecation to be explicitly accepted if it's the only way to work around an issue.

Databinding class-list is missing (Generated class list does not exist data-binding/debug/class-list/_generated.txt_

I have a library module A which uses an aar B that has databinding enabled. On applying this plugin, compiling the library fails with

Generated class list does not exist data-binding/debug/class-list/_generated.txt

This behaviour is not consistent.

I also have another module which has only BindingAdapters. I get the same error for that module despite having databinding classes within the module itself

This occurs only while applying this plugin

Versions:
Andorid Gradle Plugin : 3.1.2
Gradle: 4.7

Similar issue is #56

Extension of type 'AndroidConfig' does not exist.

If i have the plugin enabled, i get this error:
Extension of type 'AndroidConfig' does not exist. Currently registered extension types: [ExtraPropertiesExtension, g]

Gradle: 4.4.1
Android Gradle Plugin: 3.1.0
Cache fix plugin: 0.4.0

Support Configuration Caching

Starting this issue to strategize about this:

Are we going to need to compile against Gradle 6.0 to take advantage of newer APIs?
Should we drop support for AGP 3.5? No new cache fixes against AGP 3.5 are likely going to be developed, maybe we can just suggest AGP 3.5 users stay with version 1.0.7?

Are we going to be able to do all the funny business we do with task manipulation with configuration caching?

Could not find com.android.tools.build:gradle:3.0.0.

After adding plugins block in my app/build.gradle:

plugins {
    id "org.gradle.android.cache-fix" version "0.3.4"
}

The log shows:

Could not find com.android.tools.build:gradle:3.0.0.
Searched in the following locations:
    https://plugins.gradle.org/m2/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom
    https://plugins.gradle.org/m2/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.jar
Required by:
    project :app > org.gradle.android.cache-fix:org.gradle.android.cache-fix.gradle.plugin:0.3.4 > gradle.plugin.org.gradle.android:android-cache-fix-gradle-plugin:0.3.4

better description

What exactly is the problem with cache?
Is it reported to Google team to fix it directly in the plugin?

Simplify setup with project root plugin

In order to simplify setup, we should add a second plugin which is applied in the project root.

It then applies the existing cache fix plugin to all subprojects which have either the android application plugin or the android library plugin.

In addition the plugin itself should take care of determining if it should be applied or not.

Generated class list does not exist error from data binding task

If i have the plugin enabled, i get this error:

Execution failed for task ':features:onboarding:transformClassesAndResourcesWithSyncLibJarsForDebug'.
> failure, see logs for details.
  Generated class list does not exist <redacted>/modules/features/onboarding/build/intermediates/data-binding/debug/class-list/_generated.txt

The module in question has both data binding and Kotlin kapt enabled.
If i do not apply this plugin on the module, the build succeeds.

Gradle: 4.6
Android Gradle Plugin: 3.1.0
Cache fix plugin: 0.4.0
Kotlin plugin: 1.2.31

Usage documentation

I stumbled into your plugin and tried it out on one of my projects. I am missing a bit of documentation on how to use it and what to expect. I cannot see if there is any new task being added or if there should be any console output when running a build. I kindly ask you to add a bit of guidance to your README.md. Thanks.

AGP 4.2 incompatibility

Tested with 4.2.0-alpha04

Caused by: java.lang.NullPointerException: Cannot invoke method setAccessible() on null object
	at org.gradle.android.workarounds.MergeJavaResourcesWorkaround.setPropertyValue(MergeJavaResourcesWorkaround.groovy:22)
	at org.gradle.android.workarounds.AbstractAbsolutePathWorkaround$_apply_closure1$_closure2.doCall(AbstractAbsolutePathWorkaround.groovy:27)

MergeJavaResources fix introduces artificial skipWhenEmpty

The MergeJavaResources fix creates a new input that is marked with skipWhenEmpty(true). This is normally not a problem, but in situations where the inputs are empty, this will cause the task to be skipped with a NO-SOURCE outcome rather than creating an empty jar. This causes problems for downstream tasks that expect the jar to exist, even if it is empty.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.