19

I'm on a MacBook Pro M1 (and before someone says well it's because of M1 or something else, I've been programming with Flutter and M1 for weeks but then I must have to reset my M1 and after this) ... my big problem:

I can not start my project with a package that include native codes like shared_preferences or sqlite, every time I get a error running Pod Install.

I searched on Stack Overflow and so far nothing helped me. If I start my project without the package there are no problems, this is my Flutter code very simple:

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
 runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
    );
  }

}


`class Home extends StatelessWidget {
  const Home({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: RaisedButton.icon(
          onPressed: ()async{
            final prefs = await SharedPreferences.getInstance();
            if(prefs.containsKey("test")){
              print("available");
            }else{
              await prefs.setInt("test", 1);
            }
            final send = await post("xxx",body: {
              "query":"SELECT * FROM NEWS"
            });
            print(json.decode(send.body));
          },
          icon: Icon(Icons.person),
          label: Text("Hii")
        ),
      ),
    );
  }
} ,

This is the error I get from Flutter:

    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:177:in `sources'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:1073:in `block in resolve_dependencies'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/user_interface.rb:64:in `section'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:1072:in `resolve_dependencies'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer/analyzer.rb:124:in `analyze'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:414:in `analyze'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:239:in `block in resolve_dependencies'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/user_interface.rb:64:in `section'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:238:in `resolve_dependencies'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/installer.rb:160:in `install!'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/command/install.rb:52:in `run'
    /Library/Ruby/Gems/2.6.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/lib/cocoapods/command.rb:52:in `run'
    /Library/Ruby/Gems/2.6.0/gems/cocoapods-1.10.0/bin/pod:55:in `<top (required)>'
    /usr/local/bin/pod:23:in `load'
    /usr/local/bin/pod:23:in `<main>'
    ```
    ――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
    [!] Oh no, an error occurred.
    Search for existing GitHub issues similar to yours:
    https://github.com/CocoaPods/CocoaPods/search?q=dlsym%280x7fdfa0da8bc0%2C+Init_ffi_c%29%3A+symbol+not+found+-+%2FLibrary%2FRuby%2FGems%2F2.6.0%2Fgems%2Fffi-1.14.2%2Flib%2Fffi_c.bundle&type=Issues
    If none exists, create a ticket, with the template displayed above, on:
    https://github.com/CocoaPods/CocoaPods/issues/new
    Be sure to first read the contributing guide for details on how to properly submit a ticket:
    https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md
    Don't forget to anonymize any private data!
    Looking for related issues on cocoapods/cocoapods...
    Found no similar issues. To create a new issue, please visit:
    https://github.com/cocoapods/cocoapods/issues/new
Error output from CocoaPods:
↳
    [!] Automatically assigning platform `iOS` with version `12.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

I edited my Podfile and specified a platform but nothing helped. Here are some details:

Flutter Version = 1.22.5 (I tried also the newest version 1.22.6)
Xcode Version = 12.3 (I tried also the newest version 12.4)
Cocoa-pods  = 1.10.0 ((I tried also the newest version 1.10.1)

I installed and reinstalled many times Cocoa-pods it didn't help either

aheze
  • 24,434
  • 8
  • 68
  • 125
Talal Zeid
  • 231
  • 1
  • 2
  • 5
  • 2
    Running on M1, I ended up needing a mix of both answers below: `arch -x86_64 sudo gem install ffi` then `cd ios && arch -x86_64 pod install`. Thanks @aheze and @ShobitMahajan – maganap Oct 24 '21 at 09:38
  • After ```arch -x86_64 sudo gem install ffi``` , A simple pod install would work next time onwards. – Shobit Mahajan Oct 25 '21 at 12:30

9 Answers9

41

Instead of pod install, you need to do:

arch -x86_64 pod install     

Cocoapods still doesn't have full Apple Silicon support. Running commands with arch -x86_64 forces Terminal to use Rosetta 2 instead.

If that doesn't work, try following this article.

aheze
  • 24,434
  • 8
  • 68
  • 125
19

Run this command :

arch -x86_64 sudo gem install ffi

After that, do your flutter build ios --no-codesign or whatever It will work fine.

More info is provided here https://github.com/flutter/flutter/issues/70796#issue-746115543

Shobit Mahajan
  • 362
  • 2
  • 10
7

for me none of these flutter run, flutter build ios, arch -x86_64 pod install and etc does not work until I did these steps:

  1. run sudo gem install ffi in terminal.
  2. then flutter build ios --release. and worked fine.
3

Run

sudo gem uninstall ffi 

and

sudo gem install ffi -- --enable-libffi-alloc
david okoroafor
  • 313
  • 1
  • 7
1

arch -x86_64 pod install instead pod install

It is while updating repo at the same time

arch -x86_64 pod install --repo-update
Akbar Khan
  • 2,215
  • 19
  • 27
1

I followed all these guidelines and nothing worked, after a lot of searching I found this video https://www.youtube.com/watch?v=uZD2EQbBqPg that solved this pod install problem once and for all

0

If your using a m1 use rosetta terminal and from your project's ios directory run pod update

0

Go to the terminal and locate you ios folder directory for example:

cd /Users/dev/IdeaProjects/<project_name>/ios

then run:

pod install

add these files in .zshrc:

export LANG=en_US.UTF-8 export PATH="/usr/local/sbin:$PATH" export PATH="/usr/local/opt/ruby/bin:$PATH"

Edit Scheme:

change to debug from release

things to remember for flutter developers:

**you can use only one bundle identifier against one account for project. if you are using Mac M1 then try to run app on physical device as Iphone device can automatically solve most of the problem **

Arslan
  • 194
  • 1
  • 10
0

Only Working Solution after 2022

Need to update line 63 of podhelper.rb file in packages/flutter_tools/bin/podhelper.rb (You can search podhelper in Finder to find it)

Original :

continue if xcframework_file.start_with?(".") # Hidden file, possibly on external disk.

Updated :

next if xcframework_file.start_with?(".") # Hidden file, possibly on external disk.

Changes reqired Screenshot

Credit : jmagman on GitHub