XCode5.1出現“could not build module XXX”的情況
阿新 • • 發佈:2019-02-03
今天除錯時前幾次沒什麼問題,之後xcode莫名其妙出現了could not build module XXX的情況,有報foundation錯的,也有報其它官方庫錯誤的,甚至在只編譯foundation的程式時也報錯。網上查了下說有可能在command+單擊檢視官方標頭檔案時不小心修改了標頭檔案(例如多了一個空格、按了個冒號什麼的),在歷經:
1、clean工程
2、設定是否自動啟用target中module功能
3、清空project的derived data資料夾
證明都無效!
最後無奈重灌XCode5.1才最終解決。。。
(考慮原來本機裝有XCode_4.3.3,是否原版本沒解除安裝乾淨所致?但其它的project編譯沒問題)
最後證明以上都無效!!!
後來github上找到了一段程式碼可以omit掉該issue,這似乎是XCode5的bug。雖然忽略掉該庫可以解決問題但可能會引起其他的需要用到該庫的問題,但目前沒遇到。
如下:
新建該程式碼然後新增到編譯檔案裡即可。// When the `accessibility inspector' is enabled on the iOS Simulator the private `UIAccessibility' // framework is loaded. In turn it will try to load a list of bundles amongst which is one that has // only resources, no executable. This leads to `CFBundleLoadExecutableAndReturnError' logging this // offending error message. // // This code omits the `SDK_ROOT/System/Library/AccessibilityBundles/CertUIFramework.axbundle' // bundle from ever being attempted to load. // // This code is available under the MIT license: http://opensource.org/licenses/MIT // #import <Foundation/Foundation.h> #import <objc/runtime.h> #import <dlfcn.h> #define ACCESSIBILITY_PATH @"/System/Library/PrivateFrameworks/UIAccessibility.framework" #define APP_SUPPORT_PATH @"/System/Library/PrivateFrameworks/AppSupport.framework/AppSupport" #define COPY_PREFS_NAME "CPCopySharedResourcesPreferencesDomainForDomain" typedef CFStringRef (*CopyAppSupportPrefs)(CFStringRef); @interface UIAccessibilityLoader : NSObject // STFU compiler. - (void)loadActualAccessibilityBundle:(NSBundle *)bundle didLoad:(BOOL *)didLoad loadSubbundles:(BOOL)loadSubbundles; @end @interface STFU_UIAccessibilityLoader : NSObject @end @implementation STFU_UIAccessibilityLoader static Boolean IsAccessibilityEnabled(NSString *sdkRoot) { NSString *frameworkPath = [sdkRoot stringByAppendingPathComponent:APP_SUPPORT_PATH]; void *appSupport = dlopen([frameworkPath fileSystemRepresentation], RTLD_LAZY); CopyAppSupportPrefs CopyPrefs = (CopyAppSupportPrefs)dlsym(appSupport, COPY_PREFS_NAME); if (CopyPrefs != NULL) { CFStringRef accessibilityDomain = CopyPrefs(CFSTR("com.apple.Accessibility")); if (accessibilityDomain != NULL) { Boolean enabled = CFPreferencesGetAppBooleanValue(CFSTR("ApplicationAccessibilityEnabled"), accessibilityDomain, NULL); CFRelease(accessibilityDomain); return enabled; } } return false; } static BOOL LoadAccessibilityFramework(NSString *sdkRoot) { NSString *frameworkPath = [sdkRoot stringByAppendingPathComponent:ACCESSIBILITY_PATH]; NSBundle *bundle = [NSBundle bundleWithPath:frameworkPath]; return [bundle load]; } - (void)STFU_loadActualAccessibilityBundle:(NSBundle *)bundle didLoad:(BOOL *)didLoad loadSubbundles:(BOOL)loadSubbundles; { if (bundle.executablePath == nil) { // No need to actually load this bundle which only contains localized resources. *didLoad = YES; } else { [self STFU_loadActualAccessibilityBundle:bundle didLoad:didLoad loadSubbundles:loadSubbundles]; } } + (void)load; { char *sdkPath = getenv("IPHONE_SIMULATOR_ROOT"); if (sdkPath != NULL) { @autoreleasepool { NSString *sdkRoot = [NSString stringWithUTF8String:sdkPath]; if (IsAccessibilityEnabled(sdkRoot) && LoadAccessibilityFramework(sdkRoot)) { Class loader = object_getClass(objc_getClass("UIAccessibilityLoader")); SEL originalSel = @selector(loadActualAccessibilityBundle:didLoad:loadSubbundles:); SEL swizzledSel = @selector(STFU_loadActualAccessibilityBundle:didLoad:loadSubbundles:); Method originalMethod = class_getInstanceMethod(loader, originalSel); Method swizzledMethod = class_getInstanceMethod(self, swizzledSel); if (originalMethod != NULL && swizzledMethod != NULL) { if (class_addMethod(loader, swizzledSel, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))) { method_exchangeImplementations(originalMethod, swizzledMethod); } } } } } } @end