winney

It is never too old to learn.

0%
winney

启动项目注意事项:

  1. 启动Apifox应用——项目的mock接口

项目目录结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
src
│ App.js
│ App.less
│ App.test.js
│ index.css
│ index.js
│ reportWebVitals.js
│ setupTests.js

├─api ——接口文件(分模块)
│ source.js ——素材管理模块相关Api
│ user.js ——用户模块相关Api

├─app ——app公用
│ BreadcrumbMap.jsx ——面包屑相关配置
│ leftMenus.js ——左侧导航栏相关数据
│ leftMenus—对应旧的LeftNav.js ——antd左侧导航旧版的做法
│ rootReducers.js ——reducer的集合
│ router.js ——路由配置
│ store.js ——store的配置

├─assets ——静态资源
│ ├─css
│ │ style.css
│ │
│ ├─images
│ │ header.jpeg
│ │
│ └─less
│ common.less ——公用样式
│ cover_antd.less ——覆盖antd默认样式的样式文件
│ style.less ——其他样式

├─components ——组件集合
│ │ Bottom.jsx ——页面底部
│ │ EditableTable.jsx ——可编辑表格
│ │ LeftNav-旧的使用方法.jsx
│ │ LeftNav.jsx ——左侧导航栏组件
│ │ Top.jsx ——页面顶部
│ │
│ └─charts ——图表相关组件
│ LineChart.jsx ——线性图组件

├─pages ——页面组件(根据模块划分)
│ ├─agent
│ │ Account.jsx
│ │ AddAccount.jsx
│ │ AddAgent.jsx
│ │ Agent.jsx
│ │
│ ├─dashboard
│ │ Overview.jsx
│ │
│ ├─group
│ │ AddGroup.jsx
│ │ Group.jsx
│ │
│ ├─home
│ │ Container.jsx
│ │ Home.jsx
│ │
│ ├─login
│ │ Login.jsx
│ │
│ ├─manage
│ │ Customevent.jsx
│ │ Datacb.jsx
│ │
│ ├─product
│ │ AddProduct.jsx
│ │ EditProduct.jsx
│ │ Product.jsx
│ │
│ ├─source
│ │ AddSource.jsx
│ │ EditSource.jsx
│ │ Source.jsx
│ │ SourceUpload.jsx
│ │
│ ├─tool
│ │ Attribute.jsx
│ │ Logtool.jsx
│ │
│ └─user
│ EditPassword.jsx

├─reducers ——reducers相关(根据模块划分)
│ userSlice.js ——用户模块相关reducer处理

└─utils ——自定义相关文件
fetchUtil.js ——接口请求相关封装

项目笔记

在 create-react-app 中使用

注:先引入less,免得后面再来配置的时候,由于依赖包之间的版本之间存在冲突问题。

安装和初始化

1
yarn create react-app ad_manage_react
1
2
cd antd-demo
yarn start
安装并引入 antd
1
yarn add antd
安装 craco 并修改 package.json 里的 scripts 属性
1
yarn add @craco/craco
1
2
3
4
5
6
7
8
9
/* package.json */
"scripts": {
- "start": "react-scripts start",
- "build": "react-scripts build",
- "test": "react-scripts test",
+ "start": "craco start",
+ "build": "craco build",
+ "test": "craco test",
}

在项目根目录创建一个 craco.config.js 用于修改默认配置

自定义主题

首先把 src/App.css 文件修改为 src/App.less,然后修改样式引用为 less 文件。

1
2
3
/* src/App.js */
- import './App.css';
+ import './App.less';
1
2
3
/* src/App.less */
- @import '~antd/dist/antd.css';
+ @import '~antd/dist/antd.less';

然后安装 craco-less 并修改 craco.config.js 文件如下。

1
yarn add craco-less
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const CracoLessPlugin = require('craco-less');

module.exports = {
plugins: [
{
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
modifyVars: { '@primary-color': '#1DA57A' },
javascriptEnabled: true,
},
},
},
},
],
};

添加react-router-dom@6

1
yarn add react-router-dom@6

添加react-redux

1
yarn add react-redux

添加Redux Toolkit

1
yarn add @reduxjs/toolkit

添加redux-persist

1
yarn add redux-persist

异步获取数据

useEffect
可变的变量不放在useEffect中

错误用法:

这样写会报错

1
2
3
4
5
6
let sourceList = [];
useEffect(() => {
getSourcesList(1).then(res => {
sourceList = res
})
},[])

改为:

注:useEffect后面的依赖项,要加[],不加,会一直执行这个方法。

1
2
3
4
5
6
7
8
const [sourceList, setSourceList] = useState([]);
useEffect(() => {
getSourcesList(1).then(res => {
console.log('res获取素材列表');
console.log(res);
setSourceList(res)
})
},[])

使用数据图表

使用echarts-for-react数据图表

ECharts for React

ECharts–官网文档

注:要安装echarts,不然会报以下错误:

1
Module not found: Error: Can't resolve 'echarts' in 'H:\Gitee\ad_manage_react\node_modules\echarts-for-react\esm'
1
yarn add echarts
1
yarn add echarts-for-react
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import React from 'react';
import ReactECharts from 'echarts-for-react';
const options = {
grid: { top: 8, right: 8, bottom: 24, left: 36 },
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
},
yAxis: {
type: 'value',
},
series: [
{
data: [820, 932, 901, 934, 1290, 1330, 1320],
type: 'line',
smooth: true,
},
],
tooltip: {
trigger: 'axis',
},
};


<ReactECharts option={options} />

工具栏组件

toolbox

echart图表生成表格

toolbox—features—dataView

将echarts的数据视图装换为table表格,并且导出excel

将ECHARTS的数据视图展示为TABLE并且导出EXCEL

一、使用工具栏的方法

工具栏生成表格的设置,在toolbox->feature->dataView中设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const options = {
xAxis: {
type: 'category',
name: '日期',
key: 'date',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
},
yAxis: {
type: 'value',
},
legend: {
data: ['自然量', '推广量']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
series: [
{
name: '自然量',
key: 'nature',
type: 'line',
stack: 'Total',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '推广量',
key: 'spread',
type: 'line',
stack: 'Total',
data: [220, 182, 191, 234, 290, 330, 310]
},
],
tooltip: {
trigger: 'axis',
},
toolbox: {
feature: {
dataView: {
show: true,
readOnly: false,
lang: ['', '关闭', '刷新'],
optionToContent: function(opt) {
var axisData = opt.xAxis[0].data;
var series = opt.series;
var table = '<table class="chart-table" style="width:100%;text-align:center" border="1">'+
'<thead><tr>'
+ '<th>时间</th>'
+ '<th>时间</th>'
+ '<th>时间</th>'
+'</thead></tr>'
+ '<tbody>';
for (var i = 0, l = axisData.length; i < l; i++) {
table += '<tr>'
+ '<td>' + axisData[i] + '</td>'
+ '<td>' + series[0].data[i] + '</td>'
+ '<td>' + series[0].data[i] + '</td>'
+ '</tr>';
}
table += '</tbody></table>';
return table;
}
},
}
},
};
1
2
3
4
5
const onChartReadyCallback = (echarts) =>{
myLineChart = echarts;
}

<ReactECharts option={options} onChartReady={onChartReadyCallback}/>
二、自定义表格的方法

需要设置toolbox属性

缺点:表头的固定不好设置

设置dataView为不可见

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
.....

feature: {
dataView: {
show: true
}
}
......

let myLineChart = '';
const onChartReadyCallback = (echarts) =>{
myLineChart = echarts;
}

const toggleToTable = () => {
let opt = myLineChart.getOption();
var tbHtml = opt.toolbox[0].feature.dataView.optionToContent(opt);

// 然后将生成的HTML填充到对应的节点
}


<div onClick={toggleToTable}>生成表格</div>
三、使用antd生成表格

注:

  1. 主要是处理columnsdataSource数据
  2. 不需要设置toolbox属性

legend

图例组件展现了不同系列的标记(symbol),颜色和名字

1
2
3
legend: {
data: ['自然量', '推广量']
},

grid

设置这个位置,可以让legend显示在图表上方位置,而不是覆盖在图表上

直角坐标系内绘图网格

1
2
3
4
5
6
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true //grid 区域是否包含坐标轴的刻度标签。
},

折叠图叠加

series
1
2
3
4
5
6
7
8
9
10
11
12
{
name: '自然量',
type: 'line',
stack: 'Total',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: '推广量',
type: 'line',
stack: 'Total',
data: [220, 182, 191, 234, 290, 330, 310]
},

echart添加横向滚动条

dataZoom
1
2
3
4
5
6
7
dataZoom: [
{
type: 'slider',
show: true,
xAxisIndex: [0],
}
],

左侧导航栏-新版本的使用

1
2
3
4
5
6
7
8
9
10
const items = [
{ label: '菜单项一', key: 'item-1' }, // 菜单项务必填写 key
{ label: '菜单项二', key: 'item-2' },
{
label: '子菜单',
key: 'submenu',
children: [{ label: '子菜单项', key: 'submenu-item-1' }],
},
];
return <Menu items={items} />;
加上页面跳转
1
2
3
4
5
6
7
8
{
label: (
<a href="https://ant.design" target="_blank" rel="noopener noreferrer">
Navigation Four - Link
</a>
),
key: 'alipay',
},
项目中-加上页面跳转的做法
1
2
3
4
5
6
7
import { Link } from 'react-router-dom';

{
label: ( <Link to="/product">全部产品</Link>),
key:'/product',
icon: <AppstoreOutlined />
},
  1. 左侧导航menus

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    import { 
    AppstoreOutlined,
    ToolOutlined,
    MacCommandOutlined,
    FolderOpenOutlined,
    DashboardOutlined,
    PieChartOutlined,
    SettingOutlined }
    from '@ant-design/icons';
    import { Link } from 'react-router-dom';

    const leftMenus = [
    {
    // label: '全部产品',
    label: ( <Link to="/product">全部产品</Link>),
    key:'/product',
    icon: <AppstoreOutlined />
    },
    {
    // label: '素材管理',
    label: ( <Link to="/source">素材管理</Link>),
    key:'/source',
    icon: <FolderOpenOutlined />
    },
    {
    label: '公共模块',
    key:'/ad',
    icon: <MacCommandOutlined />,
    children: [
    {
    // label: '权限管理',
    label: ( <Link to="/ad/account">权限管理</Link>),
    key:'/ad/account',
    icon: ''
    },
    {
    // label: '用户管理',
    label: ( <Link to="/ad/user">用户管理</Link>),
    key:'/ad/user',
    icon: ''
    },
    {
    // label: '账户管理',
    label: ( <Link to="/ad/agent">账户管理</Link>),
    key:'/ad/agent',
    icon: ''
    },
    {
    // label: '项目管理',
    label: ( <Link to="/ad/group">项目管理</Link>),
    key:'/ad/group',
    icon: ''
    },
    {
    // label: '渠道管理',
    label: ( <Link to="/ad/channel">渠道管理</Link>),
    key:'/ad/channel',
    icon: ''
    },
    {
    // label: '设备管理',
    label: ( <Link to="/ad/device">设备管理</Link>),
    key:'/ad/device',
    icon: ''
    },
    {
    // label: '推广参数设置',
    label: ( <Link to="/ad/config">推广参数设置</Link>),
    key:'/ad/config',
    icon: ''
    },
    ]
    },
    {
    key:'/dashboard',
    label: '仪表盘',
    icon: <DashboardOutlined />,
    children: [
    {
    // label: '总览',
    label: ( <Link to="/dashboard/overview">总览</Link>),
    key:'/dashboard/overview',
    icon: ''
    },
    {
    // label: '实时',
    label: ( <Link to="/dashboard/realtime">实时</Link>),
    key:'/dashboard/realtime',
    icon: ''
    },
    {
    // label: '渠道效果对比',
    label: ( <Link to="/dashboard/channeleffect">渠道效果对比</Link>),
    key:'/dashboard/channeleffect',
    icon: ''
    },
    ]
    },
    {
    key:'/collect',
    label: '报表',
    icon: <PieChartOutlined />,
    children: [
    {
    // label: '分包推广详情',
    label: ( <Link to="/collect/subpackage">分包推广详情</Link>),
    key:'/collect/subpackage',
    icon: ''
    },
    {
    // label: 'SEM活动详情',
    label: ( <Link to="/collect/sem">SEM活动详情</Link>),
    key:'/collect/sem',
    icon: ''
    },
    {
    // label: '激活延迟分析',
    label: ( <Link to="/collect/effectevaluate">激活延迟分析</Link>),
    key:'/collect/effectevaluate',
    icon: ''
    },
    ]
    },
    {
    key:'/tool',
    label: '工具',
    icon: <ToolOutlined />,
    children: [
    {
    // label: '归因查询',
    label: ( <Link to="/tool/attribute">归因查询</Link>),
    key:'/tool/attribute',
    icon: ''
    },
    {
    // label: '日志流',
    label: ( <Link to="/tool/logtool">日志流</Link>),
    key:'/tool/logtool',
    icon: ''
    },
    ]
    },
    {
    key:'/manage',
    label: '配置',
    icon: <SettingOutlined />,
    children: [
    {
    // label: '推广回调管理',
    label: ( <Link to="/manage/datacb">推广回调管理</Link>),
    key:'/manage/datacb',
    icon: ''
    },
    {
    // label: '埋点管理',
    label: ( <Link to="/manage/customevent">埋点管理</Link>),
    key:'/manage/customevent',
    icon: ''
    },
    ]
    },
    ]

    export default leftMenus;
  2. 左侧导航-组件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    import React, {useState, useEffect} from 'react'
    import { Layout, Menu } from 'antd';
    import { useLocation } from 'react-router-dom';

    import leftMenus from '../app/leftMenus';
    import {
    MenuUnfoldOutlined,
    MenuFoldOutlined,
    }
    from '@ant-design/icons';

    const { Sider } = Layout;
    // const { SubMenu } = Menu;

    // 左侧导航栏
    export default function LeftNav(props) {
    const location = useLocation();
    const pathname = location.pathname;
    const [selectedKeys, setSelectedKeys] = useState([]);
    const [openKeys, setOpenKeys] = useState([]);

    useEffect(() => {
    // 更新选中状态

    const rank = pathname.split('/');
    switch(rank.length) {
    case 2 :
    setSelectedKeys([pathname])
    break;

    case 3:
    setSelectedKeys([pathname])
    setOpenKeys([rank.slice(0, 2).join('/')])
    break;

    case 4:
    setSelectedKeys([pathname])
    setOpenKeys([rank.slice(0, 2).join('/'), rank.slice(0, 3).join('/')])
    break;
    default:
    setSelectedKeys([]);
    setOpenKeys([]);

    }
    },[pathname]);

    // 展开/收起SubMenu触发
    const onOpenChange = keys => {
    setOpenKeys(keys)
    };

    // 点击MenuItem时触发
    const onClick = e => {
    setSelectedKeys([e.key])
    }
    return (
    <Sider
    trigger={null}
    collapsible
    collapsed={props.isCollapsed}
    collapsedWidth="60"
    className='left-sider'
    style={{
    overflow: 'auto',
    height: '100vh',
    position: 'fixed',
    left: 0,
    top: 0,
    bottom: 0,
    }}
    >
    <div className="logo">
    <span
    className='toggleFold'
    onClick={props.onToggle}
    >
    { props.isCollapsed ? <MenuUnfoldOutlined/> : <MenuFoldOutlined/>}
    </span>
    </div>
    <Menu
    items={leftMenus}
    theme="dark"
    mode="inline"
    openKeys={openKeys}
    selectedKeys={selectedKeys}
    onOpenChange={onOpenChange}
    onClick={onClick}
    defaultSelectedKeys={[selectedKeys]}
    />
    </Sider>
    )
    }

antd-日期选择-最近几天

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { DatePicker } from 'antd';
const { RangePicker } = DatePicker;

<RangePicker
ranges={{
'全部': [moment("2020-09-10"), moment()],
'今天': [moment(), moment()],
'昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'近7天': [moment().subtract(6, 'days'), moment()],
'近14天': [moment().subtract(13, 'days'), moment()],
'近30天': [moment().subtract(29, 'days'), moment()],
}}
locale={locale}
defaultValue={[moment("2020-09-10"), moment()]}
style={{width:220}}
onChange={onRangeChange}
placement="bottomRight"
/>
</Form.Item>

antd表格

渲染表格的数据—–数组数据,每一项要有唯一的key值

key值相关报错:Warning: Each child in a list should have a unique "key" prop.

解决方法:

  1. 在数据中添加key属性

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [
    {
    "key": 3215,
    "id": 3215,
    "group_id": 2,
    "group_name": "测试项目",
    "create_by": "10000"
    }
    ....
    ]
  2. 使用别的唯一性的属性: rowKey = { record => record.id}

    1
    2
    3
    4
    5
    6
    <Table 
    columns={columns}
    dataSource={accountList}
    rowKey = { record => record.id}
    bordered>
    </Table>

报错信息处理

[Violation] Added non-passive event listener to a scroll-blocking <some> event. Consider marking eve

react报错: Unable to preventDefault inside passive event li ……

React js -[Violation] Added non-passive event listener to a scroll-blocking ‘mousewheel’ event

react Added non-passive event listener to a scroll-blocking ‘mousewheel’ event

1
2
yarn add default-passive-events  或  cnpm i default-passive-events -S
并在 App.js 中 import 'default-passive-events';

加上以上配置之后,

报错:react-dom.development.js:6848 Unable to preventDefault inside passive event listener invocation.

React中使用antd的select报错Unable to preventDefault inside passive event listener invocation.

最后解决:

先停掉运行中的项目,找到node_modules\react-dom\cjs\react-dom.development.js中6202行的代码将event.preventDefault();注释掉,再重新运行项目,无需任何其他设置

1
2
3
4
5
6

if (event.preventDefault) {
//event.preventDefault(); // $FlowFixMe - flow is not aware of `unknown` in IE
} else if (typeof event.returnValue !== 'unknown') {
event.returnValue = false;
}

React中轮播报错pan-y不起作用Unable to preventDefault inside passive event listener invocation

macOS环境配置

iOS

参考博客:MacOs M1安装Homebrew 在国内最简单方法——使用这个安装成功

1.安装Homebrew

安装步骤:

M1芯片:

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/huwei1024/HomebrewCN/raw/master/Homebrew.sh)"

报错:

1
command not found : brew

因为M1芯片的包安装位置不在是以前的/usr/local/,而是/opt/homebrew,所以要将配置文件里的环境变量改过来

1、首先进入根目录

1
$ cd ~

2、创建.zshrc文件

1
$ touch .zshrc

3、打开文件进行编辑

1
$ open -e .zshrc

4、如果有旧的环境就修改,没有就新增

1
2
export PATH=/opt/homebrew/bin:$PATH
export PATH=/opt/homebrew/sbin:$PATH

5、保存
使用command + s
6、生效环境变量

1
$ source .zshrc

7、测试

1
$ brew -v    // 显示版本,即安装成功


本次安装参考内容:

开源安装脚本库:https://gitee.com/cunkai/HomebrewCN

复制以下内容到你的终端:
intel芯片:

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

M1芯片:

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/huwei1024/HomebrewCN/raw/master/Homebrew.sh)"

回车运行,按照提示运行下去就可以了

错误
做完上面的傻瓜式操作,理论上就OK了,但是我这边出现了安装完后用不了的错误

1
command not found : brew


相关参考内容:

Homebrew国内如何自动安装(国内地址)(Mac & Linux)

旧文章:macOS安装Homebrew太慢,换用清华镜像

1
2
3
git config --global --add safe.directory /opt/homebrew/Homebrew/Library/Taps/homebrew/homebrew-core

git config --global --add safe.directory /opt/homebrew/Homebrew/Library/Taps/homebrew/homebrew-cask
查看镜像
1
cd "$(brew --repo)" && git remote -v

2.安装watchman

参考:Mac系列之:Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW

1
brew install watchman

报错信息:

1
2
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

解决方法,终端输入以下命令:

1
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE

查看版本

1
watchman -v

3.安装cocoapods

1
brew install cocoapods

报错信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
yarn run v1.22.19
warning ../../../../../package.json: No license field
$ react-native run-ios
info Found Xcode project "AwesomeProject.xcodeproj"
info Building (using "xcodebuild -project AwesomeProject.xcodeproj -configuration Debug -scheme AwesomeProject -destination id=A7F04948-7FA8-45D1-B4A6-C26B21B6548A")
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening AwesomeProject.xcodeproj.
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project AwesomeProject.xcodeproj -configuration Debug -scheme AwesomeProject -destination id=A7F04948-7FA8-45D1-B4A6-C26B21B6548A

User defaults from command line:
IDEPackageSupportUseBuiltinSCM = YES

Prepare packages

Computing target dependency graph and provisioning inputs

Create build description
Build description signature: bf2f29ad51ca6266b44cbb8d643576b3
Build description path: /Users/yangyanyi/Library/Developer/Xcode/DerivedData/AwesomeProject-fgqiuteczcwroxgbdakmwcrknckt/Build/Intermediates.noindex/XCBuildData/bf2f29ad51ca6266b44cbb8d643576b3-desc.xcbuild

note: Building targets in dependency order
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
warning: Unable to read contents of XCFileList '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-resources-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Unable to read contents of XCFileList '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-frameworks-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-resources-Debug-input-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-resources-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-frameworks-Debug-input-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-frameworks-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase '[CP] Copy Pods Resources' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase '[CP] Embed Pods Frameworks' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase 'Bundle React Native code and images' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase 'Start Packager' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')

** BUILD FAILED **


info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

解决方法:

1
2
cd ios 
pod install

参考:Fresh react-native (0.66) app does not build on XCode 13, iOS 11.6: compiler error on SysUio.o

参考:error Failed to build iOS project. We ran “xcodebuild” command but it exited with error code 65. i can not Run my Project

报错信息:

1
2
3
4
5
[!] Error installing CocoaAsyncSocket
[!] /usr/local/bin/git clone https://github.com/robbiehanson/CocoaAsyncSocket.git /var/folders/2p/dtc9s94148j8px03g4gkxpkr0000gn/T/d20221001-8728-969mqt --template= --single-branch --depth 1 --branch 7.6.5

Cloning into '/var/folders/2p/dtc9s94148j8px03g4gkxpkr0000gn/T/d20221001-8728-969mqt'...
fatal: unable to access 'https://github.com/robbiehanson/CocoaAsyncSocket.git/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream

解决方法:

1
pod install

由于网络问题,不断安装中断,每次报类似的错误,继续输入pod install,就会继续安装,直到安装成功

4.hermes-engine的安装问题

这个有490多M,每次安装都失败,报错信息都一致。这个折腾了好久好久….

报错信息:

1
2
3
4
5
6
7
8
[!] Error installing hermes-engine
[!] /usr/bin/curl -f -L -o /var/folders/2p/dtc9s94148j8px03g4gkxpkr0000gn/T/d20221001-67147-8lkp1c/file.tgz https://github.com/facebook/react-native/releases/download/v0.70.1/hermes-runtime-darwin-v0.70.1.tar.gz --create-dirs --netrc-optional --retry 2 -A 'CocoaPods/1.11.3 cocoapods-downloader/1.5.1'

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 496M 0 1343k 0 0 1299 0 4d 15h 0:17:38 4d 14h 894
curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)

解决方法:

  1. 打开一个终端,先执行
1
2
export http_proxy='your.host:port' //your.host:port我的是127.0.0.1:1087
export https_proxy='your.host:port' your.host:port我的是127.0.0.1:1087
  1. 这个终端界面转到项目目录下,再执行pod install --verbose
1
pod install --verbose						// 在安装命令添加参数`--verbose`看打印详细信息

参考:Cocoapods安装私有库问题

安装完成

命令行打印消息中看到自动执行Generating Pods project

命令行打印消息中看到自动执行Integrating client project

1
2
3
4
5
6
7
8
9
10
11
[!] Please close any current Xcode sessions and use `myapp.xcworkspace` for this project from now on.

Integrating target `Pods-myapp` (`myapp.xcodeproj` project)

Integrating target `Pods-myapp-myappTests` (`myapp.xcodeproj` project)
- Running post integrate hooks
- Writing Lockfile in `Podfile.lock`
- Writing Manifest in `Pods/Manifest.lock`
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update

-> Pod installation complete! There are 59 dependencies from the Podfile and 49 total pods installed.

根据终端提示,如果想要使用刚添加的第三方库,必须打开MyApp.xcworkspace,而非之前的MyApp.xcodeProj

CocoaPods的安装与使用

5.运行项目

1
2
3
yarn ios 

yarn react-native run-ios

配置 ANDROID_SDK_ROOT 环境变量

1.打开配置文件的命令

1
2
3
vi ~/.zshrc

vi /Users/yangyanyi/.zshrc

2.编辑配置文件,将以下代码粘贴到配置文件中

1
2
3
4
5
6
# 如果你不是通过Android Studio安装的sdk,则其路径可能不同,请自行确定清楚
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/tools
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools

3.保存后退出vi,参考:Mac终端编辑完成后如何保存

1
:wq

4.使用source $HOME/.zshrc命令来使环境变量设置立即生效(否则重启后才生效)

1
source $HOME/.zshrc

5.使用echo $ANDROID_SDK_ROOT检查此变量是否已正确设置

1
echo $ANDROID_SDK_ROOT

输入完,在终端成功显示:/Users/yangyanyi/Library/Android/sdk

运行项目

报错信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':react-native-gradle-plugin'.
> Could not resolve all files for configuration ':react-native-gradle-plugin:classpath'.
> Could not download kotlin-gradle-plugin-1.6.10.jar (org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10)
> Could not get resource 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.6.10/kotlin-gradle-plugin-1.6.10.jar'.
> Could not GET 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.6.10/kotlin-gradle-plugin-1.6.10.jar'.
> Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.40.215] failed: connect timed out
> Could not download kotlin-compiler-embeddable-1.6.10.jar (org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.10)
> Could not get resource 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.6.10/kotlin-compiler-embeddable-1.6.10.jar'.
> Could not GET 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.6.10/kotlin-compiler-embeddable-1.6.10.jar'.
> Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.40.215] failed: connect timed out

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 12m 28s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':react-native-gradle-plugin'.
> Could not resolve all files for configuration ':react-native-gradle-plugin:classpath'.
> Could not download kotlin-gradle-plugin-1.6.10.jar (org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10)
> Could not get resource 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.6.10/kotlin-gradle-plugin-1.6.10.jar'.
> Could not GET 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.6.10/kotlin-gradle-plugin-1.6.10.jar'.
> Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.40.215] failed: connect timed out
> Could not download kotlin-compiler-embeddable-1.6.10.jar (org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.10)
> Could not get resource 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.6.10/kotlin-compiler-embeddable-1.6.10.jar'.
> Could not GET 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.6.10/kotlin-compiler-embeddable-1.6.10.jar'.
> Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.40.215] failed: connect timed out

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 12m 28s

at makeError (/Users/yangyanyi/Documents/Code/Gitee/reactive_native/myapp/node_modules/execa/index.js:174:9)
at /Users/yangyanyi/Documents/Code/Gitee/reactive_native/myapp/node_modules/execa/index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (/Users/yangyanyi/Documents/Code/Gitee/reactive_native/myapp/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
at async Command.handleAction (/Users/yangyanyi/Documents/Code/Gitee/reactive_native/myapp/node_modules/@react-native-community/cli/build/index.js:142:9)
info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Mac系统——iOS环境

安装Homebrew

开源安装脚本库:https://gitee.com/cunkai/HomebrewCN

复制以下内容到你的终端:
intel芯片:

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

M1芯片:

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/huwei1024/HomebrewCN/raw/master/Homebrew.sh)"

回车运行,按照提示运行下去就可以了

错误
做完上面的傻瓜式操作,理论上就OK了,但是我这边出现了安装完后用不了的错误

1
command not found : brew

经过检查后发现,是因为M1芯片的包安装位置不在是以前的/usr/local/
而是/opt/homebrew,所以要将配置文件里的环境变量改过来

1、首先进入根目录

1
$ cd ~

2、创建.zshrc文件

1
$ touch .zshrc

3、打开文件进行编辑

1
$ open -e .zshrc

4、如果有旧的环境就修改,没有就新增

1
2
export PATH=/opt/homebrew/bin:$PATH
export PATH=/opt/homebrew/sbin:$PATH

5、保存
使用command + s
6、生效环境变量

1
$ source .zshrc

7、测试

1
$ brew -v

原文链接:MacOs M1安装Homebrew 在国内最简单方法——使用这个安装成功

Homebrew国内如何自动安装(国内地址)(Mac & Linux)

旧文章:macOS安装Homebrew太慢,换用清华镜像

1
2
3
git config --global --add safe.directory /opt/homebrew/Homebrew/Library/Taps/homebrew/homebrew-core

git config --global --add safe.directory /opt/homebrew/Homebrew/Library/Taps/homebrew/homebrew-cask
查看镜像
1
cd "$(brew --repo)" && git remote -v

安装watchman

1
brew install watchman
报错信息
1
2
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

解决:

1
export HOMEBREW_NO_INSTALL_CLEANUP=TRUE

参考:Mac系列之:Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW

查看版本

1
watchman -v

安装cocoapods

1
brew install cocoapods

镜像地址

1
https://mirrors.tuna.tsinghua.edu.cn
1
npm config set registry 镜像地址
1
2
3
4
5
6
7
8
9
10
npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
taobao - https://registry.npmmirror.com
edunpm - http://registry.enpmjs.org/
eu ----- http://registry.npmjs.eu/
au ----- http://registry.npmjs.org.au/
sl ----- http://npm.strongloop.com/
nj ----- https://registry.nodejitsu.com/
pt ----- http://registry.npmjs.pt/

切换回淘宝镜像

1
npm config set registry https://registry.npmmirror.com/

先用淘宝镜像安装项目,

1
npx react-native init AwesomeProject

安装不了cocoapods

切换到https://registry.npmmirror.com/

切换到项目目录

1
cd AwesomeProject

再安装cocoapods

1
npm i cocoapods

报错信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
yarn run v1.22.19
warning ../../../../../package.json: No license field
$ react-native run-ios
info Found Xcode project "AwesomeProject.xcodeproj"
info Building (using "xcodebuild -project AwesomeProject.xcodeproj -configuration Debug -scheme AwesomeProject -destination id=A7F04948-7FA8-45D1-B4A6-C26B21B6548A")
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening AwesomeProject.xcodeproj.
Command line invocation:
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project AwesomeProject.xcodeproj -configuration Debug -scheme AwesomeProject -destination id=A7F04948-7FA8-45D1-B4A6-C26B21B6548A

User defaults from command line:
IDEPackageSupportUseBuiltinSCM = YES

Prepare packages

Computing target dependency graph and provisioning inputs

Create build description
Build description signature: bf2f29ad51ca6266b44cbb8d643576b3
Build description path: /Users/yangyanyi/Library/Developer/Xcode/DerivedData/AwesomeProject-fgqiuteczcwroxgbdakmwcrknckt/Build/Intermediates.noindex/XCBuildData/bf2f29ad51ca6266b44cbb8d643576b3-desc.xcbuild

note: Building targets in dependency order
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
/Users/yangyanyi/Documents/Code/Gitee/reactive_native/AwesomeProject/ios/Pods/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject.debug.xcconfig:1:1: error: unable to open configuration settings file
warning: Unable to read contents of XCFileList '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-resources-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Unable to read contents of XCFileList '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-frameworks-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-resources-Debug-input-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-resources-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-frameworks-Debug-input-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
error: Unable to load contents of file list: '/Target Support Files/Pods-AwesomeProject/Pods-AwesomeProject-frameworks-Debug-output-files.xcfilelist' (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase '[CP] Copy Pods Resources' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase '[CP] Embed Pods Frameworks' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase 'Bundle React Native code and images' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')
warning: Run script build phase 'Start Packager' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'AwesomeProject' from project 'AwesomeProject')

** BUILD FAILED **


info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

参考:Fresh react-native (0.66) app does not build on XCode 13, iOS 11.6: compiler error on SysUio.o

参考:error Failed to build iOS project. We ran “xcodebuild” command but it exited with error code 65. i can not Run my Project

原因可能是没有安装cocoapods成功

1
cd ios 
1
pod install

然后报错信息:

1
2
3
4
5
[!] Error installing CocoaAsyncSocket
[!] /usr/local/bin/git clone https://github.com/robbiehanson/CocoaAsyncSocket.git /var/folders/2p/dtc9s94148j8px03g4gkxpkr0000gn/T/d20221001-8728-969mqt --template= --single-branch --depth 1 --branch 7.6.5

Cloning into '/var/folders/2p/dtc9s94148j8px03g4gkxpkr0000gn/T/d20221001-8728-969mqt'...
fatal: unable to access 'https://github.com/robbiehanson/CocoaAsyncSocket.git/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream

解决:

(可能也不需要做下面这个设置,每次报以上错误的时候,一直pod install,直到安装成功)

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

参考:SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443

hermes-engine的安装问题

报错信息:

1
2
3
4
5
6
7
8
[!] Error installing hermes-engine
[!] /usr/bin/curl -f -L -o /var/folders/2p/dtc9s94148j8px03g4gkxpkr0000gn/T/d20221001-67147-8lkp1c/file.tgz https://github.com/facebook/react-native/releases/download/v0.70.1/hermes-runtime-darwin-v0.70.1.tar.gz --create-dirs --netrc-optional --retry 2 -A 'CocoaPods/1.11.3 cocoapods-downloader/1.5.1'

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 496M 0 1343k 0 0 1299 0 4d 15h 0:17:38 4d 14h 894
curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)

这个问题折腾了好久好久好久好久……

解决方案:
  1. 打开一个终端,先执行
1
2
export http_proxy='your.host:port' //your.host:port我的是127.0.0.1:1087
export https_proxy='your.host:port' your.host:port我的是127.0.0.1:1087
  1. 这个终端界面转到项目目录下,再执行pod install –verbose
1
pod install --verbose

在安装命令添加参数--verbose看打印详细信息

参考:Cocoapods安装私有库问题

安装完成

然后自动执行Generating Pods project

然后自动执行Integrating client project

1
2
3
4
5
6
7
8
9
10
11
[!] Please close any current Xcode sessions and use `myapp.xcworkspace` for this project from now on.

Integrating target `Pods-myapp` (`myapp.xcodeproj` project)

Integrating target `Pods-myapp-myappTests` (`myapp.xcodeproj` project)
- Running post integrate hooks
- Writing Lockfile in `Podfile.lock`
- Writing Manifest in `Pods/Manifest.lock`
CDN: trunk Relative path: CocoaPods-version.yml exists! Returning local because checking is only performed in repo update

-> Pod installation complete! There are 59 dependencies from the Podfile and 49 total pods installed.

根据终端提示,如果想要使用刚添加的第三方库,必须打开MyApp.xcworkspace,而非之前的MyApp.xcodeProj

CocoaPods的安装与使用

运行项目
1
2
3
yarn ios 

yarn react-native run-ios
1
echo insecure >> ~/.curlrc然后 pod install
1
2
3
4
5
6
7
解决办法:
1.删除项目依赖包以及 yarn 缓存
rm -rf node_modules && yarn cache clean
2.重新装包
yarn install
3.清除 React-Native 缓存
rm -rf ~/.rncache

如果iOS使用的是Mac M1的架构,可能还会遇到Cocoapods 的一些兼容问题。如果在安装 pods依赖时出现问题,可以尝试运行下面的命令:

1
2
sudo arch -x86_64 gem install ffi
arch -x86_64 pod install

详解React Native项目中启用Hermes引擎

解决 React-Native mac 运行报错 error Failed to build iOS project. We ran “xcodebuild” command but it exite

s

更新到最新版本RN 0.64.0后,React本机应用程序将无法运行

Installing React Native with Mapbox Navigation in iOS

参考:[!] Error installing Fabric. /usr/bin/curl -f -L -o /var/folders

参考:【解决】[!] Error installing Fabric. [!]/usr/bin/curl -f -L -o /var/folders

Pod Error installing Bugly

pod install 报错 :error installing AMapFoundation ,iOS 大佬们来看一下

Failed to build iOS project. We ran “xcodebuild” command but it exited with error code 65

镜像切换

Mac全自动安装brew一键配置国内镜像源

Mac HomeBrew国内镜像安装方法

科学上网

淘宝镜像:https://mirrors.aliyun.com/homebrew/?spm=a2c6h.13651104.0.0.1fc17608pdL2JD

Mac系统下——Android 环境

Java Development Kit

1
2
brew tap homebrew/cask-versions
brew install --cask zulu11

React Native 需要 Java Development Kit [JDK] 11。你可以在命令行中输入 javac -version(请注意是 javac,不是 java)来查看你当前安装的 JDK 版本

3. 配置 ANDROID_SDK_ROOT 环境变量

React Native 需要通过环境变量来了解你的 Android SDK 装在什么路径,从而正常进行编译。

具体的做法是把下面的命令加入到 shell 的配置文件中。如果你的 shell 是 zsh,则配置文件为~/.zshrc,如果是 bash 则为~/.bash_profile(可以使用echo $0命令查看你所使用的 shell。):

1
2
3
4
5
6
# 如果你不是通过Android Studio安装的sdk,则其路径可能不同,请自行确定清楚
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/tools
export PATH=$PATH:$ANDROID_SDK_ROOT/tools/bin
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools

译注:~表示用户目录,即/Users/你的用户名/,而小数点开头的文件在 Finder 中是隐藏的,并且这个文件有可能并不存在。可在终端下使用vi ~/.zshrc命令创建或编辑。如不熟悉 vi 操作,请点击这里学习。

使用source $HOME/.zshrc命令来使环境变量设置立即生效(否则重启后才生效)。可以使用echo $ANDROID_SDK_ROOT检查此变量是否已正确设置。

请确保你正确指定了 Android SDK 路径。你可以在 Android Studio 的”Preferences”菜单中查看 SDK 的真实路径,具体是Appearance & BehaviorSystem SettingsAndroid SDK