Flutter iOS环境下修改Info.plist中CFBundleName为含&符号的应用名称时编译报错的解决方法咨询
Hey there, I’ve dealt with this exact problem before when working with special characters in iOS bundle names—let’s get this sorted out for you!
Why the Error Happens
The Info.plist file is an XML document, and the & character is a reserved XML entity. When you write it directly, the XML parser interprets it as the start of an entity reference (like & or <) instead of a literal character, which throws a compilation error.
Step-by-Step Solutions
1. Manually Escape the & Character in Info.plist
Open your ios/Runner/Info.plist file as a plain text file (or in a code editor), find the CFBundleName entry, and replace the & with its XML entity equivalent &.
Example:
<key>CFBundleName</key> <string>S&S</string>
This tells the XML parser to render the character as a literal & instead of treating it as syntax.
2. Use Xcode’s Visual Editor (Easier & Safer)
Xcode automatically handles XML entity escaping for you, so you don’t have to remember the entity codes:
- Open your Flutter project’s
ios/Runner.xcworkspacein Xcode. - Select the Runner target in the project navigator.
- Go to the Info tab.
- Find the Bundle display name field (this maps directly to
CFBundleName). - Type
S&Sdirectly into the field—Xcode will automatically convert the&to&in the underlyingInfo.plistfile.
3. Verify the Fix
After making the change, try compiling your Flutter iOS app again. If everything works, you’ll see the app name S&S displayed correctly on the iOS home screen and in app listings.
Important Notes
- Never write unescaped
&,<,>,", or'directly in XML files likeInfo.plist—these all require entity escaping. - If you’re setting the app name via Flutter’s
pubspec.yaml, keep in mind that thenamefield can’t contain special characters, but you can override it directly inInfo.plistusing the methods above.
内容的提问来源于stack exchange,提问作者Abdullah Butt

