关于Tweak.xm:23:136: error: unknown type name 'NSString'

小白,首次编译tweak工程,提示如下报错信息
==> Notice: Build may be slow as Theos isn’t using all available CPU cores on this computer. Consider upgrading GNU Make: Parallel Building · theos/theos Wiki · GitHub

Making all for tweak gd…
==> Preprocessing Tweak.xm…
==> Compiling Tweak.xm (armv7)…
Tweak.xm:23:136: error: declaration of ‘NSString’ must be imported from module ‘ObjectiveC.NSObject’ before it is required
static id (*_logos_meta_orig$_ungrouped$NSURLProtocol$propertyForKey$inRequest$)(_LOGOS_SELF_TYPE_NORMAL Class _LOGOS_SELF_CONST, SEL, NSString *, id); static id _logos_m…
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk/usr/include/objc/./NSObject.h:13:8: note: previous declaration is here
@class NSString, NSMethodSignature, NSInvocation;
^
Tweak.xm:4:9: error: receiver type ‘NSString’ for instance message is a forward declaration
if([key isEqualToString:@“networkRedirectCount”])
^~~
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk/usr/include/objc/./NSObject.h:13:8: note: forward declaration of class here
@class NSString, NSMethodSignature, NSInvocation;
^
Tweak.xm:6:16: error: definition of class NSNumber must be available to use Objective-C numeric literals
return @1;
^
3 errors generated.

xcode版本是:12.4
macos版本:10.15.7
Tweak.mk代码如下

%hook NSURLProtocol
+(id)propertyForKey:(NSString *)key inRequest:(id)inRequest
{
if([key isEqualToString:@“networkRedirectCount”])
{
return @1;
}
return %orig;
}
%end

Makefile文件如下

THEOS_DEVICE_IP = 172.18.253.190

THEOS_DEVICE_PORT = 22

TARGET := iphone:clang:latest:7.0

include $(THEOS)/makefiles/common.mk

TWEAK_NAME = gd

gd_FILES = Tweak.xm

gd_CFLAGS = -fobjc-arc

include $(THEOS_MAKE_PATH)/tweak.mk

恳请大佬解答,不胜感激

低情商:看报错
高情商: 有考虑过学正向吗

1 个赞

以前搞Android,对IOS着急用写个插件,正想开发一点没弄过,大佬能指点一下?

没导入头文件

可以具体说下怎么处理吗?多谢

#import <Foundation/Foundation.h>

我胡乱试的,加的#import <Foundation/NSString.h>,可以编译通过了,还是非常感谢 :+1: :+1: :+1: