Table of contents

React Native ios Error [RCTModuleMethod.mm:375] Unknown argument type '__attribute__'

Objective C Mar 11, 2020 Viewed 419 Comments 0

Question

The package.json for my React Native project is as follows: "react": "16.8.3", "react-native": "0.59.5". Xcode 11 compiles successfully, but reports an error after running on IPhone simulator:

2020-03-08 09:32:21.481 [error][tid:main][RCTModuleMethod.mm:375] Unknown argument type '__attribute__' in method -[RCTAppState getCurrentAppState:error:]. Extend RCTConvert to support this type.
2020-03-08 09:32:21.481540+0800 NativeTest[6056:30774] Unknown argument type '__attribute__' in method -[RCTAppState getCurrentAppState:error:]. Extend RCTConvert to support this type.
2020-03-08 09:32:21.514 [fatal][tid:main] Exception '*** -[__NSArrayM objectAtIndexedSubscript:]: index 1 beyond bounds [0 .. 0]' was thrown while invoking getCurrentAppState on target AppState with params (
    2,
    3
)
callstack: (
    0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23d03ab1 _CFThrowFormattedException + 194
    3   CoreFoundation                      0x00007fff23b85749 -[__NSArrayM objectAtIndexedSubscript:] + 169
    4   NativeTest                          0x00000001011d00df -[RCTModuleMethod processMethodSignature] + 13327
    5   NativeTest                          0x00000001011d4e9d -[RCTModuleMethod invokeWithBridge:module:arguments:] + 189
    6   NativeTest                          0x000000010126fd17 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 791
    7   NativeTest                          0x000000010126f823 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 131
    8   NativeTest                          0x000000010126f799 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25
    9   libdispatch.dylib                   0x00000001020bddd4 _dispatch_call_block_and_release + 12
    10  libdispatch.dylib                   0x00000001020bed48 _dispatch_client_callout + 8
    11  libdispatch.dylib                   0x00000001020ccde6 _dispatch_main_queue_callback_4CF + 1500
    12  CoreFoundation                      0x00007fff23bd4049 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    13  CoreFoundation                      0x00007fff23bceca9 __CFRunLoopRun + 2329
    14  CoreFoundation                      0x00007fff23bce066 CFRunLoopRunSpecific + 438
    15  Foundation                          0x00007fff2576b86f -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 211
    16  Foundation                          0x00007fff2576bae2 -[NSRunLoop(NSRunLoop) runUntilDate:] + 72

RCTModuleMethod.mm:375] Unknown argument type '__attribute__' in method -[RCTAppState getCurrentAppState:error:]. Extend RCTConvert to support this type.

Solution 1

Upgrade React Native to 0.59.9 or 0.60.x.

Solution 2

Refer to the code https://github.com/facebook/react-native/pull/25146/files, and modify the method RCTParseUnused of node_modules/react-native/React/Base/RCTModuleMethod.mm manually.

static BOOL RCTParseUnused(const char **input)
{
  return RCTReadString(input, "__attribute__((unused))") ||
         RCTReadString(input, "__attribute__((__unused__))") ||
         RCTReadString(input, "__unused");
}
Updated Mar 11, 2020