Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: Issues with multiple flavors. command-line builds #18342

Closed
eikebartels opened this issue Jun 10, 2018 · 29 comments
Closed

iOS: Issues with multiple flavors. command-line builds #18342

eikebartels opened this issue Jun 10, 2018 · 29 comments
Labels
platform-ios iOS applications specifically t: xcode "xcodebuild" on iOS and general Xcode project management tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@eikebartels
Copy link

eikebartels commented Jun 10, 2018

Hello,

Im having a couple of problems with flavors. Manly on iOS but also on Android.

I have one code base for 2 different apps. Each app has a live and staging configuration. Each of this configuration has one for release and one for debug.

My configuration in Xcode looks like:

screen shot 2018-06-10 at 16 10 46

screen shot 2018-06-10 at 16 10 50

And my configuration in Android Studio looks like

screen shot 2018-06-10 at 16 11 53

Things going wrong.

  1. I run app a from Android Studio. Then I wanna run app b. App b installs on simulator but app a starts.
  2. flutter does not take Xcode schema environment variables.
  3. If I run flutter build ios --release --flavor instructor_live --target lib/main_instructor_live.dart Im getting errors like
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **
    
Xcode's output:
↳
    In file included from /Users/eikebartels/Documents/driveddy/mobile/ios/Pods/Protobuf/objectivec/GPBWellKnownTypes.m:35:
    /Users/eikebartels/Documents/driveddy/mobile/ios/Pods/Protobuf/objectivec/GPBWellKnownTypes.h:40:10: fatal error: 'Protobuf/Any.pbobjc.h' file not found
     #import <Protobuf/Any.pbobjc.h>
             ^~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.
Encountered error while building for device.
make: *** [build_instructor_live] Error 1

But archiving via Xcode works

Doctor output

[✓] Flutter (Channel beta, v0.4.4, on Mac OS X 10.13.4 17E202, locale en-DE)
    • Flutter version 0.4.4 at /Users/eikebartels/Applications/flutter
    • Framework revision f9bb4289e9 (4 weeks ago), 2018-05-11 21:44:54 -0700
    • Engine revision 06afdfe54e
    • Dart version 2.0.0-dev.54.0.flutter-46ab040e58

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /Users/eikebartels/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[!] iOS toolchain - develop for iOS devices (Xcode 9.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4, Build version 9F1027a
    • ios-deploy 1.9.2
    ! CocoaPods out of date (1.5.0 is recommended).
        CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
        For more info, see https://flutter.io/platform-plugins
      To upgrade:
        brew upgrade cocoapods
        pod setup

(Im still using cocoa pods v 4.0 because otherwise nothing works anymore.

@eikebartels
Copy link
Author

I found one issue related to point 1.
When you run an app with a specific flavor you have to set Use ... for command line builds
screen shot 2018-06-13 at 11 38 31

I think what needs to be changed somehow. Because this causes issue if you are working with different flavors and im not sure how it gonna behave on CI

@Caioflandau
Copy link

Caioflandau commented Jul 2, 2018

+1 here. I'm having the same issue on iOS builds - especially point 1. Case is:

  1. An app that can have two different flavors (most common case being a staging and a production flavor)
  2. Each flavor has a different bundle ID on iOS (each flavor maps to a specific build scheme)
  3. Install one flavor and then the other
  4. No matter which flavor I launch, Flutter will launch the one set in the "Use <configuration> for command-line builds"

When building it, it does build and install the right flavor. But then when launching it on the iOS emulator it launches the wrong one.

In other words: each build scheme has a different bundle ID. When launching the app, although it installs the right one, Flutter can only launch the one that has the bundle ID of the configuration set in "Use <configuration> for command-line builds".

@zoechi zoechi added the tool Affects the "flutter" command-line tool. See also t: labels. label Jul 3, 2018
@acudworth
Copy link

Having this issue too - this is a very common workflow setup and needs to be addressed asap. Flutter should launch the app with bundle identifier that has just been built

@asinel
Copy link

asinel commented Aug 2, 2018

I have a problem with building too. Will it be fixed?

@eikebartels
Copy link
Author

eikebartels commented Aug 17, 2018

Regarding the Use ... for command line builds issue. You can make use of the ruby library https://github.com/CocoaPods/Xcodeproj to set the value via CI.

Im using fastlane

lane :build_beta do
    sh("./modify_pbxproj.sh instructor")
sh("cd .. && flutter build ios --release --no-codesign --flavor instructor --target lib/main_instructor.dart --build-name=#{ENV["BUILD_VERSION"]} --build-number=#{ENV["BUILD_NUMBER"]}")

build_app(
        workspace: "ios/Runner.xcworkspace", 
        clean:false,
        scheme: "Instructor", 
        output_name:"instructor",
        include_symbols:true, 
        export_method: "ad-hoc", 
        xcconfig:"ios/Flutter/Instructor.xcconfig",
        output_directory: "build",
        archive_path: "build/archive",
        silent:false, 
        verbose: true,
        include_symbols:true, 
        include_bitcode: false, 
        # result_bundle:true
        )
end 

My modify_pbxproj.sh file looks like:

#!/bin/sh
P_PATH="../ios/Runner.xcodeproj"
ruby modify_pbxproj.rb $1 $P_PATH

And my modify_pbxproj.rb looks like

require 'xcodeproj'

config = ARGV[0]
project_path = ARGV[1]
project = Xcodeproj::Project.open(project_path)
objectGroup = project.objects_by_uuid["97C147051CF9000F007C117D"]
puts "Old Config: #{objectGroup.default_configuration_name}"
objectGroup.default_configuration_name = config
puts "New Config: #{objectGroup.default_configuration_name}"
project.save(project_path)

Which this kind of dirty solution Im able to switch between different flavour configurations and build on CI

@eikebartels eikebartels changed the title A lot of problems with flavors iOS: Issues with multiple flavors. command-line builds Aug 17, 2018
@Abgaryan
Copy link

@eikebartels good job.

@nashfive
Copy link

Any update on this issue ? I also have this problem, the command line is trying to launch the wrong app in the simulator...

@zoechi zoechi added the platform-ios iOS applications specifically label Oct 1, 2018
@zoechi zoechi added this to the Goals milestone Oct 1, 2018
@leorachit
Copy link

Please help on this.

@xster xster added t: xcode "xcodebuild" on iOS and general Xcode project management and removed tool Affects the "flutter" command-line tool. See also t: labels. labels Jan 5, 2019
@zoechi zoechi added tool Affects the "flutter" command-line tool. See also t: labels. and removed tool Affects the "flutter" command-line tool. See also t: labels. labels Jan 8, 2019
@zoechi
Copy link
Contributor

zoechi commented Feb 13, 2019

Please check if #27691 fixes this as well

@martin-fink
Copy link

Hi! I've run into the same problem on Flutter 1.2.1, channel stable.

flutter run --flavor $flavor builds and installs the correct version, but runs the one specified under "Use ... for command-line builds".

@mayurdhurpate
Copy link

I tried setting up Flutter Flavor for iOS apps following this blog: https://www.tengio.com/blog/multiple-firebase-environments-with-flutter/ but even though the Debug-dev scheme seems to be running during flutter run --flavor dev, the resulting App always seem to run on my Production server.

(Have added my Flutter verbose output for reference: http://pasted.co/7b85a2f9)
Option for Use ... for command line builds doesn't seem to work for me too.

Would be great if we can have an official way of setting up flavor on iOS and Android. Hoping that #32761 pull request might solve a few issues.

@maqoo
Copy link

maqoo commented Jul 14, 2019

I am having the same issue here. We have multiple flavors which are represented with schemes in iOS project. Using command line flutter build ios --flavor $flavor_name -t $target does not produce the correct app version. The flavors work using flutter run though 🤔

@evelyne24
Copy link

evelyne24 commented Jul 22, 2019

Confirmed. Same problem with flutter run or flutter build running the wrong iOS build scheme.

@eseidelGoogle
Copy link
Contributor

I believe @jonahwilliams is looking at our underlying build infrastructure as we speak, which likely will affect our support of flavors: https://github.com/flutter/flutter/projects/35

@acudworth
Copy link

Great to see this is being worked on - it's sorely needed for a lot of build setups!

@nickponomar
Copy link

Is there a workaround?? My app uses flavors to separate prod and dev config for Firebase... Currently I can not start my app in with dev Firebase... blocks further development

@droplet-js
Copy link

How to add ios flavors appname for multiple languages

@aniket08485786
Copy link

Any updates?
I am facing the same problem here.
Android Flavors are working properly but for iOS, it doesn't seem to work...
I cant give different app name to each scheme/flavor in XCode

Also Please add proper documentation on flutter Website... just dont link other people's blog in it..
it's rather confusing for people like me who are coming from the android background and who have no knowledge of XCode / iOS.

@mayurdhurpate
Copy link

Any updates on this one? It's difficult to manage multiple environments (especially when using multiple Firebase projects for staging and production) to configure without using flavors.

@0x6a68
Copy link

0x6a68 commented Oct 1, 2019

As @eseidelGoogle already mentioned you can track progress at this project https://github.com/flutter/flutter/projects/35

@tasaquino
Copy link

@eikebartels I have flavors/schemes configured in my project and could set the configuration using command line while building/archiving. Just pass the -configuration:

xcodebuild -workspace ./Runner.xcworkspace -configuration Release-beta -scheme beta -destination 'generic/platform=iOS' -archivePath build/ios/iphoneos/Runner.xcarchive archive -allowProvisioningUpdates

xcodebuild -exportArchive -archivePath build/ios/iphoneos/Runner.xcarchive -exportPath build/ios/iphoneos -exportOptionsPlist exportOptions-prod.plist

I am using Circle CI, here is a gist with example for the config.yml

@jpcarreira
Copy link

Any further development on this one? I'm currently manually changing Use ... for command-line builds whenever I want to switch between dev and prod environments.

@kuhnroyal
Copy link

@jpcarreira I have patched my local stable channel with the changes from ccfdf95 - this seems to work

@jpcarreira
Copy link

@jpcarreira I have patched my local stable channel with the changes from ccfdf95 - this seems to work

Thanks for your tip, I did something similar: branched-out of the current stable branch and cherry-picked that commit. And it has been working so far, hopefully soon this commit will be part of the stable channel.

@kuhnroyal
Copy link

This is now working on the beta channel.

@jmagman jmagman added this to Awaiting triage in Tools - Xcode review Jan 10, 2020
@jmagman
Copy link
Member

jmagman commented Jan 22, 2020

Closing as fixed by #42964. Please reopen if you think there's still an issue.
Thanks!

@jmagman jmagman closed this as completed Jan 22, 2020
Tools - Xcode review automation moved this from Awaiting triage to Engineer reviewed Jan 22, 2020
@BraveEvidence
Copy link

BraveEvidence commented Feb 3, 2020

My issue is not getting resolved even after changing command-line builds option. I am using different scheme in iOS for multiple firebase project. It seems to work on Android. If I add release version of Google service info plist file after dev version then it uses release version irrespective of flavor and vice versa.Even changing to master branch, did not work for me. For more details, check this https://stackoverflow.com/questions/59944278/configuring-multiple-scheme-in-ios-causes-mismatch-in-flavors

@bobanminic96
Copy link

bobanminic96 commented Apr 6, 2020

I experiencing that if i'am building dev flavor, or any other, bundle id is always same, for production. Building from terminal/cmd line.

UPDATE:

It looks like it is some error on CLI from flutter because i debug it with package_info flutter package to get info about build, and i saw that it is correct bundle_id, as i wanted, but still in CLI when run flutter build ios -flavors dev -t lib/main_dev.dart , it still shows up production bundle id.

Im concerned about this because of separate Firebase projects plist files in config folder. My push does not work and dont know is it related with this maybe, or i didnt setup in project firebase properly.

@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@lock lock bot locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform-ios iOS applications specifically t: xcode "xcodebuild" on iOS and general Xcode project management tool Affects the "flutter" command-line tool. See also t: labels.
Projects
Tools - Xcode review
  
Engineer reviewed
Development

No branches or pull requests