getsentry / sentry-android-gradle-plugin

Gradle plugin for Sentry Android. Upload proguard, debug files, and more.
https://docs.sentry.io/platforms/android/gradle/
MIT License
142 stars 32 forks source link

Configuration Cache Incompatibility #683

Closed WebTiger89 closed 3 months ago

WebTiger89 commented 6 months ago

Gradle Version

8.7

AGP Version

8.4.0-beta01

Code Minifier/Optimizer

None

Version

4.4.0

Sentry SDK Version

7.6.0

Steps to Reproduce

Enable gradle configuration cache

Expected Result

Build succeed instead of failing

Actual Result

When trying to build my app module via terminal the build fails with error:

Configuration cache state could not be cached: field `provider` of `org.gradle.configurationcache.serialization.codecs.ProviderBackedFileCollectionSpec` bean found in field `__sourceDirs__` of task `:myapp:generateSentryBundleIdMinApi29Debug` of type `io.sentry.android.gradle.sourcecontext.GenerateBundleIdTask`: error writing value of type 'org.gradle.api.internal.provider.BiProvider'                                                                                                                                                                                                                                    
> Querying the mapped value of property(org.gradle.api.file.Directory, property(org.gradle.api.file.Directory, property(org.gradle.api.file.Directory, map(org.gradle.api.file.Directory flatmap(provider(task 'generateMinApi29DebugBuildConfig', class com.android.build.gradle.tasks.GenerateBuildConfig)) check-type())))) before task ':myapp:generateMinApi29DebugBuildConfig' has completed is not supported     

Using --no-configuration-cache works.

See issue https://github.com/getsentry/sentry-android-gradle-plugin/issues/554

markushi commented 6 months ago

The underlying issue seems to be that we want to package the BuildConfig, before it's even created. Let's have a closer look and check if maybe even should exclude the BuildConfig class.

romtsn commented 4 months ago

hey @WebTiger89 the issue has been addressed in the version 4.6.0, which just has been published. Please give it a try and let us know. Thank you!

WebTiger89 commented 4 months ago

Unfortunately the issue persists. I have updated the version to 4.7.1. When enabling confiuration cache in gradle.properties file: org.gradle.unsafe.configuration-cache=true I get following error:

  • What went wrong: Configuration cache state could not be cached: field provider of org.gradle.configurationcache.serialization.codecs.ProviderBackedFileCollectionSpec bean found in field __sourceDirs__ of task :myapp:generateSentryBundleIdMinApi29Debug of type io.sentry.android.gradle.sourcecontext.GenerateBundleIdTask: error writing value of type 'org.gradle.api.internal.provider.BiProvider' Querying the mapped value of property(org.gradle.api.file.Directory, property(org.gradle.api.file.Directory, property(org.gradle.api.file.Directory, map(org.gradle.api.file.Directory flatmap(provider(task 'generateMinApi29DebugBuildConfig', class com.android.build.gradle.tasks.GenerateBuildConfig)) check-type())))) before task ':myapp:generateMinApi29DebugBuildConfig' has completed is not supported

Using .\gradlew myapp:assembleMinApi29Debug --no-configuration-cache works

WebTiger89 commented 4 months ago

@romtsn Can you reopen the issue please

romtsn commented 4 months ago

@WebTiger89 ok, thanks for letting us know. In this case I'll have to ask to provide a reproducible sample - would you be able to do so? Otherwise, I'm afraid we won't be able to fix it.

romtsn commented 3 months ago

@WebTiger89 any chance you can provide a sample here?

WebTiger89 commented 3 months ago

@romtsn I have found a solution: Since AGP 8.0 BuildConfig generation is disabled by default, see https://developer.android.com/build/releases/past-releases/agp-8-0-0-release-notes, BuildConfig generation must be enabled explicitly per module.

I have enbaled generation buildFeatures.buildConfig = true (build.gradle.kts)

for my android app module which is the cause for failing when sentry-android-gradle-plugin is used in combination with org.gradle.unsafe.configuration-cache=true (gradle.properties)

It works if I set buildFeatures.buildConfig = false, but it also works if I add android.enableBuildConfigAsBytecode=true to gradle.properties file, found here https://medium.com/androiddevelopers/5-ways-to-prepare-your-app-build-for-android-studio-flamingo-release-da34616bb946

romtsn commented 3 months ago

Glad that you found it and thanks for sharing the details!

I'd guess to reproduce this, we'd have to test on AGP 8.+ and enable buildFeatures.buildConfig = true, correct?

WebTiger89 commented 3 months ago

Yeah buildFeatures.buildConfig = true and org.gradle.unsafe.configuration-cache=true (gradle.properties)

romtsn commented 3 months ago

okay, thanks, somehow I wasn't able to reproduce it myself, but one of our tests was able to catch this, so I'll look into it!

romtsn commented 3 months ago

@WebTiger89 version 4.9.0 has been shipped, please give it a try and let us know if the issue is still not fixed. thank you!