flutter / website

Flutter documentation web site
https://docs.flutter.dev
Other
2.75k stars 3.17k forks source link

Issue with `ci_post_clone.sh` (`$(FLUTTER_BUILD_NAME)` in `Info.plist` not being expanded) #10807

Open lukehutch opened 1 week ago

lukehutch commented 1 week ago

Page URL

https://docs.flutter.dev/deployment/cd

Describe the problem

I added ci_post_clone.sh (the script by @Diizzayy) to my Flutter project, and set up the Xcode cloud deployment workflow as shown in the Flutter docs at the above URL.

I get the following CI build errors:

However flutter run works locally. So there seems to be some step missing from the ci_post_clone.sh script (something that is run by flutter run but not by the script, to replace these variables with the actual correct values before the Xcode Cloud build is started).

After a local run of flutter run, my Generated.xcconfig (which is not checked into git) does include the following (these numbers are correctly picked up from pubspec.yaml when I run flutter run):

FLUTTER_BUILD_NAME=0.0.1
FLUTTER_BUILD_NUMBER=378

Runner/Info.plist and Flutter/AppFrameworkInfo.plist both contain:

    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>

My Runner.xcodeproj/project.pbxproj file contains the following for each target:

                MARKETING_VERSION = "$(FLUTTER_BUILD_NAME)";
                CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";

@jmagman asked me in #7259 to file this separate bug report, and include:

[✓] Flutter (Channel beta, 3.23.0-0.1.pre, on Fedora Linux 40 (Workstation Edition) 6.8.10-300.fc40.x86_64, locale en_US.utf8)
    • Flutter version 3.23.0-0.1.pre on channel beta at /opt/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2feea7a407 (3 weeks ago), 2024-06-06 10:19:10 +0700
    • Engine revision bb10c54666
    • Dart version 3.5.0 (build 3.5.0-180.3.beta)
    • DevTools version 2.36.0

Expected fix

As far as I can tell, Xcode Cloud is simply not generating Generated.xcconfig, so maybe it is not calling flutter build, but rather is relying only on Xcode to build the ipa?

I tried adding this to the end of ci_post_clone.sh, but it does not seem to have fixed the problem:

flutter build ios --release --no-codesign
jmagman commented 1 week ago

No, Info.plist doesn't change.

I meant, is CFBundleShortVersionString in the generated app literally $(FLUTTER_BUILD_NAME) (incorrect) or is it 0.0.1 (correct)? If it's the FLUTTER_BUILD_NAME variable name, this error has to do with your Xcode setup and xcconfig, and wouldn't be related to the Xcode Cloud setup--it's something you should fix in your project.

lukehutch commented 1 week ago

@jmagman is this what you are suggesting I do?:

plutil -convert xml1 ./build/ios/iphoneos/Runner.app/AppFrameworkInfo.plist
plutil -convert xml1 ./build/ios/iphoneos/Runner.app/Info.plist

Then examining these two files, I can see that the variable names are replaced with the correct version strings in Info.plist, but not in AppFrameworkInfo.plist.

I tried taking the keys and values out of AppFrameworkInfo.plist, assuming that they only needed to be in Info.plist, but then I get a build error.

lukehutch commented 1 week ago

I found the issue: I had assumed that both Runner/Info.plist and Flutter/AppFrameworkInfo.plist should contain:

    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>

However I noticed that when I create a new Flutter project, Flutter/AppFrameworkInfo.plist has the value 1.0 in place of both of these variables. I put the 1.0 values back, and now Xcode Cloud can build the app.

I don't understand what these 1.0 values in Flutter/AppFrameworkInfo.plist are used for though -- are they just placeholders, given that they are not updated based on the Flutter build version strings? They have to be present, or the build fails, but they are not updated automatically from the Flutter build number, and apparently the FLUTTER_* variables are not expanded in AppFrameworkInfo.plist.

Should Flutter be manually keeping these version numbers up to date in AppFrameworkInfo.plist? Obviously it doesn't make sense to do it manually. Are these version numbers even used anywhere?