-
Notifications
You must be signed in to change notification settings - Fork 27.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flutter Gradle Plugin uses antipatterns #123934
Comments
Hi @bartekpacia, it looks like the issue you linked to #122579 is not related to this issue. Kindly update the issue with the correct link. Thank you |
Hi @danagbemava-nc, thanks for triaging this issue, and sorry for the mistake. I meant #121541 - I edited my post. |
@bartekpacia while is by no means required, As you work on the kotlin conversion stuff please feel free to add groovy/gradle/gradle-kotlin section to the style guide AND/OR add lint checkers for items you see as anti patterns. I know historically groovy/gradle has been one of the areas we mostly focused on getting it to work without a ton of deep expertise in the language (especially compared to dart). |
Good idea. Re: Gradle style guide – cool idea, but that'd be quite a lot of effort. For now, if somebody's interested I'd recommend reading:
Re: lints checks - I think that we should at least make sure that no warnings are emitted by Gradle in a default |
Yeah I agree creating a style guide that is solid is a lot of work. My intent was more to indicate that if you run across things that bother you feel free to add a gradle style section so we can start to enforce what you have found to be best practices. It may say "Do not do XYZ and instead do ABC" and that is all. |
May be related: Android Studio Build Analyzer report.How do I follow the recommendation from Build Analyzer by editing my build.gradle: Task Setup Issues This task declares the same output directory as task ':app:mergeDebugAssets': build/app/intermediates/assets/debug As a result, these tasks are not able to take advantage of incremental build optimizations and might need to run with each subsequent build. Learn more Recommendation: Edit the plugin(s) to ensure each task specifies a unique output directory. :app:mergeDebugAssets This task frequently determines build duration because of dependencies between its inputs/outputs and other tasks. Duration: 5.6s / 35.0% Sub-project: :app Plugin: com.android.application Type: com.android.build.gradle.tasks.MergeSourceSetFolders Task Execution Categories: Uncategorized Warnings Consider filing a bug to report this issue to the plugin developer. Generate report Task Setup Issues This task declares the same output directory as task ':app:copyFlutterAssetsDebug': build/app/intermediates/assets/debug As a result, these tasks are not able to take advantage of incremental build optimizations and might need to run with each subsequent build. Learn more Recommendation: Edit the plugin(s) to ensure each task specifies a unique output directory. Adding this reduces my incremental build time by 6sec: afterEvaluate {
// Help cache :copyFlutterAssetsDebug.
cleanMergeDebugAssets.enabled = false
} |
Move static methods together. Fix property uses of duplicate strings. Add types wherever obvious Fix format depth Add whitespace to top and bottom of classes Ignore line length for file Ignore prefer single quote for file Ignore correction for getFoo used instead of foo Loosely related to /issues/123934
Flutter Gradle Plugin makes use of a few patterns that are considered to be "bad Gradle".
Names of AGP tasks are "guessed", instead of hooking up into official extension points.
I learned about this from Extend the Android Gradle Plugin article. Here's a paragraph that might be useful:
This is not what FGP does. Instead, it finds tasks by gluing strings together:
This is exactly what the Android docs advise against.
Dependencies between tasks are defined explicitly, instead of being inferred on the basis of inputs/outputs. Also, FGP tasks output their files into AGP task's output directories.
I realized this after reading this great article by a former Gradle engineer.
For example,
copyFluterAssets{flavor}
puts its output into the output directory ofmerge{flavor}Assets
task here. The relevant excerpt:Let's take the
copyFlutterAssetsTask
again as an example.It's not anything critical, of course, but I think it's good to have these points noted somewhere and fix them in the long run. I think it'd be good to do it after #121541 because writing Kotlin is faster and more pleasant than writing Groovy :)
This is somewhat related to #119196.
Thanks @gnprice for motivating me to write this down.
The text was updated successfully, but these errors were encountered: