Skip to content

Add-to-app Flutter build script fails when Podfile is in different directory from Xcode project #42513

Open

Description

@hllGitHub

We found that there is Run Flutter Build Script in flutter 1.9.

flutter_export_environment_path = File.join('$SRCROOT', relative, 'flutter_export_environment.sh');
  script_phase :name => 'Run Flutter Build Script',
    :script => "set -e\nset -u\nsource \"#{flutter_export_environment_path}\"\n\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/xcode_backend.sh build",
    :input_files => [
      File.join('$SRCROOT', flutter_application_path, '.metadata'),
      File.join('$SRCROOT', relative, 'App.framework', 'App'),
      File.join('$SRCROOT', relative, 'engine', 'Flutter.framework', 'Flutter'),
      flutter_export_environment_path
    ],
    :execution_position => :before_compile

Under normal circumstances can meet our normal use. However, if our Podfile is not in the .xcodeproj directory, ie the Podfile is not in the $SRCROOT directory, then this place is faulty.

File.join('$SRCROOT', flutter_application_path, '.metadata'),
File.join('$SRCROOT', relative, 'App.framework', 'App')
File.join('$SRCROOT', relative, 'engine', 'Flutter.framework', 'Flutter')
File.join('$SRCROOT', relative, 'flutter_export_environment.sh') these paths are not exists.

Suggestion:

I suggest that we can add a parameter pod_path.

in Podfile:

pod_path = current_Podfile_path
install_all_flutter_pods(flutter_application_path, pod_path)

in podhelper.rb:

pod_path ||=flutter_application_path
flutter_export_environment_path = File.join(pod_path, relative, 'flutter_export_environment.sh');
  script_phase :name => 'Run Flutter Build Script',
    :script => "set -e\nset -u\nsource \"#{flutter_export_environment_path}\"\n\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/xcode_backend.sh build",
    :input_files => [
      File.join(pod_path, flutter_application_path, '.metadata'),
      File.join(pod_path, relative, 'App.framework', 'App'),
      File.join(pod_path, relative, 'engine', 'Flutter.framework', 'Flutter'),
      flutter_export_environment_path
    ],
    :execution_position => :before_compile

podhelper.rb.txt

Activity

  1. added
    c: new featureNothing broken; request for a new capability
    toolAffects the "flutter" command-line tool. See also t: labels.
    platform-iosiOS applications specifically
    on Oct 11, 2019
  2. added
    a: existing-appsIntegration with existing apps via the add-to-app flow
    and removed
    c: new featureNothing broken; request for a new capability
    on Oct 11, 2019
  3. jmagman commented on Oct 11, 2019

    @jmagman
    Member

    You set :project in your host Podfile to a xcproject in some other directory?

  4. jmagman commented on Oct 11, 2019

    @jmagman
    Member

    In your setup is there a case where the Podfile directory isn't Dir.pwd (the current working directory?). Can you describe your directory structure?

  5. changed the title [-]Some ideas about `podhelper.rb`[/-] [+]Add-to-app Flutter build script fails when Podfile is in different directory from Xcode project[/+] on Oct 11, 2019
  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 11, 2019
  7. hllGitHub commented on Oct 12, 2019

    @hllGitHub
    Author

    My Podfile:

    platform :ios, '10.0'
    workspace 'Sprout.xcworkspace'
    project 'Source/Sprout.xcodeproj'
    project 'Source/FlutterModule.xcodeproj'
    
    flutter_application_path = 'flutter/'
    pod_path = '${SRCROOT}/../'
    load File.join(flutter_application_path, '.ios', 'flutter', 'podhelper.rb')
    
    use_frameworks!
    
    target 'Sprout' do
      install_all_flutter_pods(flutter_application_path)
      project 'Source/Sprout.xcodeproj'
    end
    
    target 'FlutterModule' do
      install_all_flutter_pods(flutter_application_path)
      project 'Source/FlutterModule.xcodeproj'
    end
    
    

    My directory:

    .
    ├── Carthage
    │   ├── Build
    │   │   └── 
    │   └── Checkouts
    │       ├── 
    ├── Pods
    │   ├── FMDB
    │   │   └── src
    │   │       └── fmdb
    │   ├── Headers
    │   ├── Local\ Podspecs
    │   ├── Pods.xcodeproj
    │   │   └── xcuserdata
    │   │       └── lianglianghu.xcuserdatad
    │   │           └── xcschemes
    │   └── Target\ Support\ Files
    │       ├── FMDB
    │       ├── Flutter
    ├── Source
    │   ├── FlutterModule
    │   ├── FlutterModule.xcodeproj
    │   ├── FlutterModuleInterface
    │   ├── Sprout
    │   ├── Sprout.xcodeproj
    ├── Sprout.xcworkspace
    ├── build
    │   └── ios
    ├── fastlane
    ├── flutter
    ├── Podfile
    

    The $SRCROOT is './Source', but Podfile is in '.' .
    File.join('$SRCROOT', relative, 'App.framework', 'App') is wrong. Hope can provide custom pod path.

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

    @Mentina

    hello, hllGitHub.I have the same problem as yours. Could you give me some tips to solve this problem?

  10. hllGitHub commented on Oct 17, 2019

    @hllGitHub
    Author

    @Mentina I have some ways.

    1. Refer to my suggestion above, local debugging is fine.
    2. Load flutter as a product
    3. Delete the above script in the Podfile
    4. Adjust the project structure so that the Podfile is in the ${SRCROOT} directory
  11. Mentina commented on Oct 17, 2019

    @Mentina

    @Mentina I have some ways.

    1. Refer to my suggestion above, local debugging is fine.
    2. Load flutter as a product
    3. Delete the above script in the Podfile
    4. Adjust the project structure so that the Podfile is in the ${SRCROOT} directory

    Thanks a lot, I'm trying your advice above. Lcoal debugging is exactly what I want.

  12. hllGitHub commented on Oct 17, 2019

    @hllGitHub
    Author

    @Mentina I have some ways.

    1. Refer to my suggestion above, local debugging is fine.
    2. Load flutter as a product
    3. Delete the above script in the Podfile
    4. Adjust the project structure so that the Podfile is in the ${SRCROOT} directory

    Thanks a lot, I'm trying your advice above. Lcoal debugging is exactly what I want.

    The above four methods can solve this problem. Of course, it is best to make adjustments by the official flutter.

  13. jmagman commented on Oct 17, 2019

    @jmagman
    Member

    I think we can leverage @current_target_definition.user_project_path and @defined_in_file instead of requiring the user to pass in anything extra to install_all_flutter_pods.

  14. self-assigned this
    on Oct 17, 2019
  15. Mentina commented on Oct 18, 2019

    @Mentina

    @hllGitHub Thanks a lot. I have solved this problem by following your suggestions.It works well.

  16. tanqisen commented on Nov 19, 2019

    @tanqisen

    I hook the install_all_flutter_pods function in podhelper.rb.

    in Podfile:

    flutter_application_path = 'my_flutter'
    load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
    
    def fix_flutter_script_phase(flutter_application_path)
      relative = File.join('..', flutter_application_path, '.ios', 'Flutter')
      flutter_export_environment_path = File.join('${SRCROOT}', relative, 'flutter_export_environment.sh');
    
      script_phase :name => 'Run Flutter Build Script',
        :script => "set -e\nset -u\nsource \"#{flutter_export_environment_path}\"\n\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/xcode_backend.sh build",
        :input_files => [
          File.join('${SRCROOT}', '..', flutter_application_path, '.metadata'),
          File.join('${SRCROOT}', relative, 'App.framework', 'App'),
          File.join('${SRCROOT}', relative, 'engine', 'Flutter.framework', 'Flutter'),
          flutter_export_environment_path
        ],
        :execution_position => :before_compile
    end
    
    def install_all_flutter_pods_fixed(flutter_application_path)
      flutter_application_path ||= File.join('..', '..')
      install_flutter_engine_pod
      install_flutter_plugin_pods(flutter_application_path)
      
      # fix path
      fix_flutter_script_phase(flutter_application_path)
      begin
        install_flutter_application_pod(flutter_application_path)
      rescue
      end
    end
    
    target 'some_target' do
      install_all_flutter_pods_fixed(flutter_application_path)
    
      pod ...
    end
    
  17. jmagman commented on Nov 19, 2019

    @jmagman
    Member

    We should fix install_flutter_engine_pod by creating the relative path between @current_target_definition.user_project_path and @defined_in_file. I haven't gotten around to this yet.

  18. added
    P2Important issues not at the top of the work list
    on Aug 18, 2020
  19. removed their assignment
    on Apr 21, 2023
  20. 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 projecta: existing-appsIntegration with existing apps via the add-to-app flowplatform-iosiOS applications specificallyteam-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