Repository navigation
Fix in Flutter Tools: Added kebab/param-cased as fileNames expected by the tool for multidimesional flavors in aab's build process - #124797
Conversation
…://github.com/pepompeu/flutter into fix-flutter-tools-for-multidimentional-flavor
| @@ -6,6 +6,10 @@ | |||
| // reformatting of code. | |||
| "editor.formatOnSave": false, | |||
There was a problem hiding this comment.
Do we need these lines then?
There was a problem hiding this comment.
nvm, we probably don't want to be autoformatting anything in this repo
There was a problem hiding this comment.
Vs-code doesn't respect the default rules of current .settings for the workspace scope, if you have especified some different behavior for ["dart"] in your global setup scope.
Added this lines to ensure respect for the original rules, avoiding auto formatting.
|
@gnprice do you know if this is a reasonable solution? |
|
This certainly looks plausible as the sort of thing I'd expect AGP to do when picking this filename. The last time I looked for documentation of this sort of thing, there really wasn't any at all. So unless that's changed, the only way to try to pin down AGP's behavior here is for someone to try things out — make a small example Android project, muck with the flavors in the build, and see what happens. That or study the AGP implementation, I guess, but the empirical approach may be easier. One case I'd be curious about is what happens when an individual flavor is more than one word long — e.g. there's a Or for more of an exotic edge case: what happens when individual flavors have names that start with a capital letter, and/or contain an underscore? It looks like there's a test case for that just above the one this PR adds, with a single |
|
I'm interested in learning more about how the AGP behaves in different scenarios when it comes to naming files for projects with flavors. I'm willing to try out different use cases and experiment with various configurations. I'm going to try out the specific use case you mentioned with the fooBar and bazQuux flavors on two or more different dimensions to see what output file names are generated. I'll also look into the edge case you mentioned with flavors that have names starting with capital letters or containing underscores. Once I have some results to share, I'll provide a follow-up with my findings. Thanks again for your help! |
…-flutter-tools-for-multidimentional-flavor
|
Tested my proposal for this use cases: In the current master the AGP exports the folders and files as follows: camelCase file name: snake_case file name: In the latest master we get this error for the three file names:
With my proposal we got a pass for the lowercase and snake_case flavor. As the flavor received from the BuildInfo class is only a string, we cant separate the dimensions of the flavor in fooBar situations I would like to propose the addition of a restriction to flavor naming in flutter to only lowercase and snakeCase until we develop a better way to interpret the --flavor tag in the build command @gnprice what do you think we should do next? |
|
Thanks for the PR! Forgive me if I am misunderstanding, but I don't see how this fixes #65264. The issue (and the title of this PR) are about computing the correct .aab filename when building appbundles with multidimensional flavors, but the description and code change of this PR seems to be about an issue that occurs when the project has flavors with camelCased names (nothing to do with multidimensional flavors). This separate issue was mentioned as a comment on #65264, but I personally could not reproduce it on master on neither my MacBook nor my Ubuntu VM. Regardless, we need a way to separate out each of the flavors per dimension (as @pepompeu pointed out). Here's one possibility I can think of: modify packages/flutter_tools/gradle/src/main/groovy/flutter.groovy to add a new task to print productFlavors. Then, modify packages/flutter_tools/lib/src/android/gradle.dart to invoke the task added in step 1 and read the output to get the separate flavors. For inspiration, you can look at some code that does something similar for getting the build variants:
|
|
Sorry for my confusion @andrewkolos, it's my first PR ever! Trying my best to help. From my testing, the aab is built correctly and is placed in the output folder with the correct naming, in the correct place. From my understanding, the problem is that the tool emits the warning reported in the issue if it can't find the outputed file. The initial idea of the pr was to extend the files searched for the tool inside the folder to include this kind of outputs: app-one-two-three-release.aab I'm missing something here? |
That's what I understand too. I think our difference in understanding is the problem that #65264 is describing. Focusing on only the issue description (first comment), I came up with this way to reproduce this issue:
flavorDimensions "signed", "env"
productFlavors {
signed {
dimension "signed"
}
unsigned {
dimension "signed"
}
prodThing { // We include some camel-casing to make sure this is not an issue.
dimension "env"
}
internalThing {
dimension "env"
}
}
Adding a However, the file that actually exists is This PR would add the following path to search: which is still different. |
|
It seems like a sticky point here is that in a project like @andrewkolos's helpful example above,
One solution to that would be, as mentioned, to add a Gradle task that tells us what the flavors and flavor dimensions are, so that we can unpack a string like (This might be improved in the future by fixing #119196; not sure how much.) Here's another possible solution: we could say that when you have multiple flavor dimensions, you need to express the different flavors to Then there'd be no question that there are two flavors, namely Conveniently that would also have zero impact on everyone who's using |
|
(I should also acknowledge, since I was somewhat negative above at #124797 (comment) about Android's level of documentation of this sort of thing in AGP, that the docs have improved! That page https://developer.android.com/build/build-variants#flavor-dimensions is quite helpful, and even spells out most of what the filenames look like. I don't think that was there a year or two ago; and in fact the Internet Archive first spotted that page just last week… indeed just a couple of hours after my comment. Also although that page gives a very helpful example, it doesn't quite pin down the behavior to the degree one wants when writing code like this to interoperate with it. So the empirical investigations above are still essential.) |
|
@pepompeu thanks for your willingness to contribute! However, it seems like the approach in this PR is not the solution we want for #65264. I think further discussion on the correct approach should happen on that issue. |
This PR adds the kebab/param-cased version of the .aab bundle file name to the possible options so the gradle tool can look for it in the bundle directory and prevent the flutter build command failing because it could not find the .aab file and the end of the build.
List which issues are fixed by this PR. You must list at least one issue.
Fixes #65264
Based on @PritamSangani solution
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.