Xcode Validate failed with framework Code-sign Error

Standard

My iOS app contains two custom swift embed framework, there named FWA and FWB here, and some 3rd party embed framework.

I compiled them as universal framework with bitcode, and archived my app.

I got error while I validating the archive –

2016-09-09 01:50:58 +0000  /var/folders/8d/6t4zhl296lx7_1nlg7qt5_j40000gn/T/XcodeDistPipeline.CDC/Root/Payload/MyAPP.app/Frameworks/FWB.framework: replacing existing signature
2016-09-09 01:50:58 +0000  /var/folders/8d/6t4zhl296lx7_1nlg7qt5_j40000gn/T/XcodeDistPipeline.CDC/Root/Payload/MyApp.app/Frameworks/FWB.framework: invalid resource directory (directory or signature have been modified)

Only FWB got this, FWA is fine.

Both them have same code-sign settings: iOS Developer, and same Provisioning Profile: Automatic.

Finally, I changed FWB’s Provisioning Profile as iOS Team Provisioning Profile: *, validate passed.

Maybe Xcode cannot find Provisioning Profile for FWA, so it is code-sign free framework.
However Xcode chosen incorrect Provisioning Profile for FWB, since it have similar bundle id with my app.

Call and embed C/Obj-C code in Swift Framework

Standard

Since Xcode 6, we can create dynamic frameworks with swift language running on iOS 8.

In my swift framework, I have to implement some functions with C or Obj-C code like compression. As found from searching, maybe I can use Bridge Header to use zlib and some obj-c libs. However, Xcode reported error, in framework I can’t use bridge!

I’d tried defined an unzip protocol in framework, implement it in my app project, set to framework class. But I felt this is not best way.

In next searching, I found @asmname. IT IS WOUNDERFUL NEWS!
I can define some C function to return result I want, like this:

In zip.m:
id zipData(NSData *data, BOOL compress) {}

In Zip.swift:
// @asmname did changed to @_silgen_name since swift 2.2
@asmname("zipData") func c_zipData(data: NSData, compress: Bool) -> AnyObject

class Zip {
  func zipData(data: NSData, compress: Bool) -> (NSData?, ErrorType?) {
    let result = c_zipData(data, compress: compress)
    if let data = result as? NSData { return (data, nil) }
    return (nil, result as? ErrorType?)
  }
}

It can WORK! But … App crashed … EXC_I386_GPFIT

Then I changed scheme setting, open NSZombie, tip me sending message to released object – [NSInlineData release].

I think the reason is –
Since ARC, in zip.m, after zipData() returned, the NSData would be called release by Cocoa.
After Zip.swift got the NSData object (or NSError), it don’t know the object should be retain first, but it would release it.

So I changed swift code:

let result = Unmanaged<AnyObject>.passRetained(c_zlibData(data, compress: compress)).takeUnretainedValue()

I guess Unmanaged.passRetained() just like shared_ptr in C++, it would retained once, after swift code needn’t the object, ARC would make retainCount from 1 to 0.

And I was tried to use passUnretained().takeRetainedValue(), the code would crash in next line.

OK, problem solved, I shall make my best framework happily right now~

error relocation overflow in R_ARM_THM_CALL

Standard

I got many error like this while compiling cocos2d-x game (cocos2d-x 3.3 + quick, Android NDK r10d).

These error shown by many cocos2d-x class like UILayout.cpp or CCHttpClient.cpp, many method from web is that add LOCAL_ARM_MODE:=arm into Android.mk, but it is nothing affect.

Finally, I try to change Application.mk, change head to this:
APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION=4.9 # it was clang.

After that, compile did passed.

Resize or repirtation USB HDD on Mac

Standard
  • Keep away from the app named StellaPartitionManger.
  • Half function of Disk Utility can only worked on recovery mode.

3 days before, I felt I spend more disk space (B) on my 1T USB HDD to unused partition:

A 50G ntfs, B 250G ntfs, C 500G hfs+, D 120G hfs+

1st night, I merged B & C. There is goes well copy all of file to volume C, and removed volume B.

 

2nd morning, I found an OS X app named StellaPartitionManager and looks well, then begin to resize C, let it scale to most space it could.

StellaPartitionManger still worked whole day from 10AM to 9PM, and Not finished! No progress bar! Only status description: Moving blocks.
I should go home now! Should I wait it whole night? No!
Finally, I terminated it, and found no data lost… What the hell StellaPartitionManger did…

At home, I did backup all data, tried to repartition all volumes with StellaPartitionManger, but problem coming.
While StellaPartitionManger finished operate, OS X could not identity the disk!
What did you done, StellaPartitionManger!

Disk Utility couldn’t erase any volume, couldn’t repartition on the disk.
And I tried plug it to a Windows computer, did repartition, OS X couldn’t identity it.
And I tried to use root permission on Terminal open Disk Utility or use disutil command, got same error tip.
StellaPartitionManger, I remembered you! Get out my sight!

In the last morning, I try to restart Mac and press command+r enter recovery mode, open Disk Utility.
It worked now! My dearest volumes come back!

GXUI – GUI for go from google

Standard

Google released open source GUI library based on OpenGL – GXUI.

Feature from source code –

  • Contains many components like Button, TextInput, Tree and more.
  • There are tree adapter specific class.
  • Theme change, default for dark.
  • Based on OpenGL.
  • Easy cross-compiling with C extension.

Install on Mac

I’m using Mac OS X 10.10.3 beta and Golang 1.4.

First of all, install GLEW into system. Download newest GLEW from SourceForge. Then run:

$ tar xvzf glew-20150124.tgz
$ cd glew-1.11.0
$ make
$ sudo make install

Ignore compile warning, and run:

$ go get github.com/google/gxui
$ go get code.google.com/p/freetype-go/freetype/truetype
$ go get github.com/go-gl-legacy/gl
$ go get github.com/go-gl/glfw/v3.1/glfw

While installing freetype, there maybe an error – exec: “hg”: executable file not found in $PATH
run this or browse Mercurial Download site for other platform.

brew install mercurial

After all commands did finished, enter $GOPATH/src/gxui/samples and run any sample app.

$ cd $GOPATH/src/github.com/google/gxui/samples
$ go run polygon

And you may found the polygon is about 7.1MB after you build it, there is amazing size!
The reason is GXUI use golang use so little dependent library: (removed compatibility version)

$ otool -L ./main
./main:
 /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL
 /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa
 /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit
 /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo
 /usr/lib/libSystem.B.dylib
 /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
 /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
 /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics
 /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
 /usr/lib/libobjc.A.dylib

Most of them are system libraries.

Repost from Qiita.

Facebook SDK could not show invite or request dialog

Standard

We are testing invite and request with Facebook SDK in our game for company, and we used FBWebDialog on iOS.

Some of request is worked, friend could received on Facebook, only request live could not, the dialog hide too fast to click “send” button.

I searched and found too many FAQ, Q&A, and found nothing, Facebook document does no help to me.
Finally, when we testing same feature on Android, we found the reason –

Facebook limited invite or request title must less than 50 characters!

OK, no program issue, just title text too long …

Facebook SDK无法显示邀请或请求对话框

我们要在公司的游戏里测试用Facebook SDK邀请好友与向好友请求,在iOS上用FBWebDialog。

好友可以在Facebook上收到多数请求,除了向好友请求生命,对话框一闪而过,根本来不及点发送。

我找了很多常见问题与问答都一无所获,Facebook的文档也没有任何帮助。
终于,当我们在Android上测试此功能时,终于找到了答案:

Facebook限制邀请和请求的标题必须在50个字符以下!

还好,不是程序原因,只是标题太长了。

Launch sequence for cocoa (iOS and OS X)

Standard

First, call main(), and call UIApplicationMain(), in there it done these –

  • Create instance of UIApplication.
  • Create delegate instance for UIApplication – YourAppDelegate.
  • Open message loop, notify YourAppDelegate while system event.
  • Create instance of UIWindow (extend by UIView), set as window property for YourAppDelegate.
  • Load Info.plist then find storyboard out.
  • Load storyboard and create root view controller (point by white arrow).
  • Set the view controller above as rootViewController property for UIWindow.
  • Create and add rootViewController.view as sub view to UIWindow, and show UIWindow.

Continue reading

Android app debug for Java and native C++ code

Standard

We can find most error or exception log from LogCat on Android Develop Tools or Android Studio, it show us detail infomation of exception name and stack path.

But  we can not see any usful infomation sometime, such as running native code.
Just like “Fatal signal 11 (SIGSEGV)”, and a lot of binary data.
Although we use “Debug as Android Application”, exception cannot be catch at all, even if the bad code is in java.

Continue reading