更新 xcode 13 后 react-native run-ios 命令未成功运行

Posted

技术标签:

【中文标题】更新 xcode 13 后 react-native run-ios 命令未成功运行【英文标题】:react-native run-ios command not running successfully after updated xcode 13 【发布时间】:2021-11-17 09:46:24 【问题描述】:

更新 Xcode 13 后,react-native run-ios 命令在我的项目中无法成功运行。

当我运行该命令时,Successfully launched the app on the simulator 会显示在终端中。没有错误信息。应用构建不好,打不开。

但是我可以用 Xcode 成功运行。

我的 react-native 版本是“0.61.5”。有没有人遇到像我这样的问题?

【问题讨论】:

【参考方案1】:

我遇到了类似的问题。虽然我有 react-native 版本 59.10。

解决方案是使用补丁包修改 react-native fishhook.c 文件:

`diff --git a/node_modules/react-native/Libraries/fishhook/fishhook.c 
 b/node_modules/react-native/Libraries/fishhook/fishhook.c
 index 205ee82..d580178 100755
 --- a/node_modules/react-native/Libraries/fishhook/fishhook.c
 +++ b/node_modules/react-native/Libraries/fishhook/fishhook.c
 @@ -21,15 +21,20 @@

-#import "fishhook.h"
+#include "fishhook.h"

-#import <dlfcn.h>
-#import <stdlib.h>
-#import <string.h>
-#import <sys/types.h>
-#import <mach-o/dyld.h>
-#import <mach-o/loader.h>
-#import <mach-o/nlist.h>
+#include <dlfcn.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <mach/mach.h>
+#include <mach/vm_map.h>
+#include <mach/vm_region.h>
+#include <mach-o/dyld.h>
+#include <mach-o/loader.h>
+#include <mach-o/nlist.h>

#ifdef __LP64__
typedef struct mach_header_64 mach_header_t;
@@ -76,6 +81,36 @@ static int prepend_rebindings(struct rebindings_entry **rebindings_head,
return 0;


+#if 0
+static int get_protection(void *addr, vm_prot_t *prot, vm_prot_t 
*max_prot) 
+  mach_port_t task = mach_task_self();
+  vm_size_t size = 0;
+  vm_address_t address = (vm_address_t)addr;
+  memory_object_name_t object;
+#ifdef __LP64__
+  mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT_64;
+  vm_region_basic_info_data_64_t info;
+  kern_return_t info_ret = vm_region_64(
+      task, &address, &size, VM_REGION_BASIC_INFO_64,(vm_region_info_64_t)&info, &count, &object);
+#else
+  mach_msg_type_number_t count = VM_REGION_BASIC_INFO_COUNT;
+  vm_region_basic_info_data_t info;
+  kern_return_t info_ret = vm_region(task, &address, &size, VM_REGION_BASIC_INFO, (vm_region_info_t)&info, &count, &object);
+#endif
+  if (info_ret == KERN_SUCCESS) 
+    if (prot != NULL)
+      *prot = info.protection;
+
+    if (max_prot != NULL)
+      *max_prot = info.max_protection;
+
+    return 0;
+  
+
+  return -1;
+
+#endif
+
@@ -84,6 +119,7 @@ static void perform_rebinding_with_section(struct rebindings_entry *rebindings,
                                        uint32_t *indirect_symtab) 
uint32_t *indirect_symbol_indices = indirect_symtab + section->reserved1;
void **indirect_symbol_bindings = (void **)((uintptr_t)slide + section->addr);
+
 for (uint i = 0; i < section->size / sizeof(void *); i++) 
 uint32_t symtab_index = indirect_symbol_indices[i];
 if (symtab_index == INDIRECT_SYMBOL_ABS || symtab_index == INDIRECT_SYMBOL_LOCAL ||
@@ -92,18 +128,33 @@ static void perform_rebinding_with_section(struct rebindings_entry *rebindings,
 
 uint32_t strtab_offset = symtab[symtab_index].n_un.n_strx;
 char *symbol_name = strtab + strtab_offset;
-    if (strnlen(symbol_name, 2) < 2) 
-      continue;
-    
+    bool symbol_name_longer_than_1 = symbol_name[0] && symbol_name[1];
 struct rebindings_entry *cur = rebindings;
 while (cur) 
   for (uint j = 0; j < cur->rebindings_nel; j++) 
-        if (strcmp(&symbol_name[1], cur->rebindings[j].name) == 0) 
-          if (cur->rebindings[j].replaced != NULL &&
-              indirect_symbol_bindings[i] != cur->rebindings[j].replacement) 
+        if (symbol_name_longer_than_1 && strcmp(&symbol_name[1], cur->rebindings[j].name) == 0) 
+          kern_return_t err;
+
+          if (cur->rebindings[j].replaced != NULL && indirect_symbol_bindings[i] != cur->rebindings[j].replacement)
         *(cur->rebindings[j].replaced) = indirect_symbol_bindings[i];
+
+          /**
+           * 1. Moved the vm protection modifying codes to here to reduce the
+           *    changing scope.
+           * 2. Adding VM_PROT_WRITE mode unconditionally because vm_region
+           *    API on some iOS/Mac reports mismatch vm protection attributes.
+           * -- Lianfu Hao Jun 16th, 2021
+           **/
+          err = vm_protect (mach_task_self (),(uintptr_t)indirect_symbol_bindings, section->size, 0, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_COPY);
+          if (err == KERN_SUCCESS) 
+            /**
+             * Once we failed to change the vm protection, we
+             * MUST NOT continue the following write actions!
+             * iOS 15 has corrected the const segments prot.
+             * -- Lionfore Hao Jun 11th, 2021
+             **/
+            indirect_symbol_bindings[i] = cur->rebindings[j].replacement;
       
-          indirect_symbol_bindings[i] = cur->rebindings[j].replacement;
       goto symbol_loop;
     
   
@@ -187,6 +238,9 @@ int rebind_symbols_image(void *header,
 struct rebindings_entry *rebindings_head = NULL;
 int retval = prepend_rebindings(&rebindings_head, rebindings, rebindings_nel);
 rebind_symbols_for_image(rebindings_head, (const struct mach_header *) header, slide);
+    if (rebindings_head) 
+      free(rebindings_head->rebindings);
+    
 free(rebindings_head);
 return retval;

`

来源:https://github.com/facebook/fishhook/pull/87/files

【讨论】:

谢谢,@Ville。让我试试补丁包。但现在我在删除 node_modules 并清理了构建文件夹后面临另一个问题。 :(***.com/questions/69322333/…

以上是关于更新 xcode 13 后 react-native run-ios 命令未成功运行的主要内容,如果未能解决你的问题,请参考以下文章

更新到 Xcode 13 后出现错误破坏了应用程序

更新 xcode 13 后 react-native run-ios 命令未成功运行

更新Xcode Swift [重复]

Xcode 设备不可用,未找到运行时配置文件

Xcode 13.2 beta 发布,Swift 这个更新太赞了

Xcode 13.2 beta 发布,Swift 这个更新太赞了