Skip to content

Cannot run flavored application on iOS Device because flutter uses one certificate for project #46879

Open

Description

@edisonlsm

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

  1. I run the alpha flavor using flutter run -t lib/alpha-main.dart --flavor alpha
  2. It asked me to selected a development certificate from a list of available certificates and I selected the certificate for alpha.
  3. The certificate for alpha is now set as default.
  4. The app build and run on my device as expected.
  5. I now tries to run beta flavor using flutter run -t lib/beta-main.dart --flavor beta
  6. flutter run tries to sign beta app with the alpha signing certificate.
  7. 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

  1. minikin commented on Dec 12, 2019

    @minikin

    @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:

    flutter run -t lib/src/configurations/flavors/main_development.dart --release --flavor development
  2. edisonlsm commented on Dec 12, 2019

    @edisonlsm
    Author

    @minikin the problem is that there is an iOS signing certificate set for the project and flutter run will 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.

  3. minikin commented on Dec 12, 2019

    @minikin

    @edisonlsm you need to register separate bundle ids for each flavor at your developer.apple.com account like com.edisonlsm.app, com.edisonlsm.app.alpha and com.edisonlsm.app.beta and set-up code signing in Xcode. Then you'll be available to run 3 apps with different configurations.

  4. edisonlsm commented on Dec 12, 2019

    @edisonlsm
    Author

    @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 run asks 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.

  5. iapicca commented on Dec 12, 2019

    @iapicca

    Hi @edisonlsm
    does the solution proposed by @minikin resolve the issue?
    thank you

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Dec 12, 2019
  7. edisonlsm commented on Dec 12, 2019

    @edisonlsm
    Author

    @iapicca No, it does not. The problem is related to flutter run using only one iOS signing certificate for the entire project even though there are many different flavors with different signing configurations.

  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Dec 12, 2019
  9. minikin commented on Dec 12, 2019

    @minikin

    @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.

  10. edisonlsm commented on Dec 12, 2019

    @edisonlsm
    Author

    Let me try to clarify the issue I am facing a little better:

    1. I ran the alpha flavor using flutter run -t lib/alpha-main.dart --flavor alpha.
    2. It asked me to selected a development certificate from a list of available certificates and I selected the certificate for alpha.
    3. The certificate for alpha is now set as default.
    4. The app build and run on my device as expected.
    5. I now tries to run beta flavor using flutter run -t lib/beta-main.dart --flavor beta
    6. flutter run tries to sign beta app with the alpha signing certificate.
    7. The build fails.
  11. edisonlsm commented on Dec 12, 2019

    @edisonlsm
    Author

    @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-codesign and 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 run does 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 :/

  12. minikin commented on Dec 12, 2019

    @minikin

    @edisonlsm I've got it! Step 2 is the source of your problems.
    Can you show your Signing & Capabilities tab in Xcode?

    then performing an xcode native build, which is the recommended way to archive and deploy Flutter iOS apps

    I use fastlane for that. I never do it manually.

  13. added
    t: xcode"xcodebuild" on iOS and general Xcode project management
    platform-iosiOS applications specifically
    on Dec 12, 2019
  14. edisonlsm commented on Dec 12, 2019

    @edisonlsm
    Author

    @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.

  15. 1 remaining item

  16. edTheGuy00 commented on Jan 23, 2020

    @edTheGuy00

    I think I may be having this same issue. I created different schemes for different flavors.

    flutter build ios --release --flavor develop
    and
    flutter build ios --release --flavor production

    all 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 run command. No matter what I try:

    flutter run --flavor staging or flutter run --flavor production they all seems to try to run the develop flavor

    Update:
    Nevermind, this was my issue. in my case I had set Product Name to different values based on the scheme. It appears that Flutter looks for the Runner product name, I switched it back and everything works fine now, I am able to run flutter run --flavor staging or flutter run --flavor production and get the appropriate app flavor.

    I'm not an iOS expert and I'm actually not entirely sure the purpose of Product Name

  17. removed
    p: toolingAffects the flutter_plugin_tools package
    on Apr 28, 2020
  18. jmagman commented on Jun 9, 2020

    @jmagman
    Member

    If you set up CODE_SIGN_IDENTITY (by target, build configuration, or however you want to organize your flavor) in Xcode, the flutter tool won't override it, no matter what you have set up with flutter 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.

  19. added
    P2Important issues not at the top of the work list
    on Aug 18, 2020
  20. jmagman commented on Dec 12, 2020

    @jmagman
    Member

    It appears that Flutter looks for the Runner product name

    @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.

  21. added
    P3Issues that are less important to the Flutter project
    and removed
    P2Important issues not at the top of the work list
    on Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectd: api docsIssues with https://api.flutter.dev/platform-iosiOS applications specificallyt: xcode"xcodebuild" on iOS and general Xcode project managementteam-iosOwned by iOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions