微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

M1 Mac 上的 Pod 安装错误 - Flutter 项目与本机代码如 shared_preferences

如何解决M1 Mac 上的 Pod 安装错误 - Flutter 项目与本机代码如 shared_preferences

我在 MacBook Pro M1 上(在有人说这是因为 M1 或其他原因之前,我已经用 Flutter 和 M1 编程了几个星期,但在此之后我必须重置我的 M1)。 ..我的大问题:

每次我在运行 Pod 安装时遇到错误时,我都无法使用包含本机代码(如 gpg --verify commit.ascshared_preferences)的包启动我的项目。

我在 Stack Overflow 上搜索过,到目前为止没有任何帮助。如果我在没有包的情况下开始我的项目就没有问题,这是我的 Flutter 代码,非常简单:

sqlite

这是我从 Flutter 得到的错误

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")
        ),),);
  }
},

我编辑了我的 Podfile 并指定了一个平台,但没有任何帮助。以下是一些细节:

    /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`.

我安装并重新安装了很多次 Cocoa-pods 它也没有帮助

解决方法

你需要做的不是pod install

arch -x86_64 pod install     

Cocoapods 仍然不完全支持 Apple Silicon。使用 arch -x86_64 运行命令会强制终端改用 Rosetta 2。

如果这不起作用,请尝试遵循 this article

,

对我来说,在我完成这些步骤之前,这些 flutter runflutter build iosarch -x86_64 pod install 等都不起作用:

  1. 在终端中运行 sudo gem install ffi
  2. 然后flutter build ios --release。 并且工作正常。
,

运行这个命令:

arch -x86_64 sudo gem install ffi

在那之后,做你的flutter build ios --no-codesign或其他什么 它会正常工作。

此处提供了更多信息question

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。