Repository navigation
Cannot run flavored application on iOS Device because flutter uses one certificate for project #46879
Description
We have a flavored Flutter application. Each flavor has a different bundle ID from a different Apple account.
The code signing is setup correctly on the Xcode Build Configurations, I can archive and deploy all my applications without a problem, but i can only launch one flavor on an iOS device from either Android Studio or VS Code because there is a "global" iOS signing certificate set for the project. I.e., if the "project certificate" is set to the certificate of flavor "A", when I try to run the flavor "B" on an iOS Device directly from both IDEs it will try to sign the flavor "B" with the certificate of flavor "A" and the Xcode build will fail.
The only way I have to launch the apps on a real iOS device is to perform a flutter build ios debug --flavor <flavor> -t <main-file.dart> --no-codesign and then run the desired flavor directly from Xcode, but of course when doing that I have no debugging on the dart code.
I use this flow of performing two builds when archiving and distributing the applications and it works as expected, the only problem I face is with the debug.
Since this issue is related only to code signing, the flavors also works as expected on the iOS Simulator, I can launch any flavor I want on debug on a simulator.
I could use flutter config --clear-ios-signing-cert to change the cert, but of course this isn't the ideal solution because I would still be stuck to one flavor at a time.
Am I doing any configuration wrong? Is there any way to configure flutter in order to get the code signing certificate for debug builds from the iOS configurations on Xcode instead of relying on the certificate set for the project?
Steps to reproduce
- I run the alpha flavor using
flutter run -t lib/alpha-main.dart --flavor alpha - It asked me to selected a development certificate from a list of available certificates and I selected the certificate for alpha.
- The certificate for alpha is now set as default.
- The app build and run on my device as expected.
- I now tries to run beta flavor using
flutter run -t lib/beta-main.dart --flavor beta - flutter run tries to sign beta app with the alpha signing certificate.
- The build fails.
flutter doctor -v
[✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.15.1 19B88, locale
pt-BR)
• Flutter version 1.9.1+hotfix.6 at /Users/edisonlsm/Library/flutter
• Framework revision 68587a0916 (3 months ago), 2019-09-13 19:46:58 -0700
• Engine revision b863200c37
• Dart version 2.5.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/edisonlsm/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling
support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.1, Build version 11A1027
• CocoaPods version 1.7.5
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 41.1.2
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build
1.8.0_202-release-1483-b49-5587405)
[!] IntelliJ IDEA Community Edition (version 2018.3.4)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• For information about installing plugins, see
https://flutter.dev/intellij-setup/#installing-the-plugins
[✓] VS Code (version 1.40.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.7.1
[✓] Connected device (2 available)
• iPhone • <id> • ios • iOS
13.2.3
• iPhone 11 Pro Max • <id> • ios •
com.apple.CoreSimulator.SimRuntime.iOS-13-1 (simulator)
Activity
minikin commentedon Dec 12, 2019
@edisonlsm
check this video https://www.youtube.com/watch?v=gdqnxcV7_FY
I did something similar and it works like a charm.
I can run iOS or Android apps like so:
edisonlsm commentedon Dec 12, 2019
@minikin the problem is that there is an iOS signing certificate set for the project and
flutter runwill always use that certificate, so I can only run one flavor on an iOS device with this command, all the other flavors will throw an code signing error.minikin commentedon Dec 12, 2019
@edisonlsm you need to register separate bundle ids for each flavor at your developer.apple.com account like
com.edisonlsm.app,com.edisonlsm.app.alphaandcom.edisonlsm.app.betaand set-up code signing in Xcode. Then you'll be available to run 3 apps with different configurations.edisonlsm commentedon Dec 12, 2019
@minikin As I said, the apps are registered with different bundles. All the code signing is setup correctly on the Apple Developer portal and on Xcode configurations. I deploy those apps to the App Store without a problem.
The problem I am facing is that
flutter runasks for an iOS certificate and then sets this certificate as the certificate for the entire project. So, if I run "flavor a" and set the certificate for "flavor a" when I try to flutter run "flavor b" it will try to sign "flavor b" with the "flavor a" certificate unless I keep cleaning the certificates between every run, which I do not want to.The biggest problems is that this affects the IDEs plugin, so I can only debug one flavor at a time from Android Studio or VS Code.
iapicca commentedon Dec 12, 2019
Hi @edisonlsm
does the solution proposed by @minikin resolve the issue?
thank you
edisonlsm commentedon Dec 12, 2019
@iapicca No, it does not. The problem is related to
flutter runusing only one iOS signing certificate for the entire project even though there are many different flavors with different signing configurations.minikin commentedon Dec 12, 2019
@edisonlsm Did you add separate schemas and configurations for each flavor in Xcode?
ps: for me, it sounds like your Xcode configs are not right.
edisonlsm commentedon Dec 12, 2019
Let me try to clarify the issue I am facing a little better:
flutter run -t lib/alpha-main.dart --flavor alpha.flutter run -t lib/beta-main.dart --flavor betaedisonlsm commentedon Dec 12, 2019
@minikin The Xcode Configurations are right, all those flavors are apps published on the App Store. I have all schemas, build configurations and signing certificated set up as recommended.
I archive my apps by running
flutter build -t lib/beta-main.dart --flavor beta --no-codesignand then performing an xcode native build, which is the recommended way to archive and deploy Flutter iOS apps. Since in this case the signing is handled by Xcode it uses the right certificate for each flavor.I just could not find a way to debug the apps properly because
flutter rundoes not seem to use the certificates specified on the Xcode project and since each flavor is from a different apple developer account I can not use the a wildcard development certificate for all flavors :/minikin commentedon Dec 12, 2019
@edisonlsm I've got it! Step 2 is the source of your problems.
Can you show your Signing & Capabilities tab in Xcode?
I use fastlane for that. I never do it manually.
edisonlsm commentedon Dec 12, 2019
@minikin I also use fastlane, my entire release & deploy proccess is automated through fastlane :) I only said "native xcode build" to simplify because it is not the focus of this issue. I do not have any problems with my release flow, it works exactly as expected and I have six flavors of this project currently published on the App Store.
The problem to which this issue refers to occurs only on my debug flow.
1 remaining item
edTheGuy00 commentedon Jan 23, 2020
I think I may be having this same issue. I created different schemes for different flavors.
flutter build ios --release --flavor developand
flutter build ios --release --flavor productionall work perfectly fine for CI builds.
I'm able to run all flavors of the app from Xcode perfectly fine.
But the issue is with the
flutter runcommand. No matter what I try:flutter run --flavor stagingorflutter run --flavor productionthey all seems to try to run thedevelopflavorUpdate:
Nevermind, this was my issue. in my case I had set
Product Nameto different values based on the scheme. It appears that Flutter looks for theRunnerproduct name, I switched it back and everything works fine now, I am able to runflutter run --flavor stagingorflutter run --flavor productionand get the appropriate app flavor.I'm not an iOS expert and I'm actually not entirely sure the purpose of Product Name
jmagman commentedon Jun 9, 2020
If you set up
CODE_SIGN_IDENTITY(by target, build configuration, or however you want to organize your flavor) in Xcode, thefluttertool won't override it, no matter what you have set up withflutter config. That signing cert is just what's used as a fallback when it's not set in Xcode.See also #14648 (comment) for recent improvements to flavors on iOS.
There's probably no tool work here, just documentation.
jmagman commentedon Dec 12, 2020
@edTheGuy00 That shouldn't be true as of #55799 (1.18.0-10.0.pre or later), you can put any string you want in the product name. Can you file a new issue if you're still seeing this? I don't know what version you were on.