Building for the new AppleTV / tvOS

You can not link static libs with other libs. If you could, you would get linker errors during the linkage of your program because of duplicate symbols. So, IMHO, current solution using iOS headers should work fine, because I doubt any of those libs (libpng, libjpeg, libssl, libwebsocket, libtiff, libcrypto, libwebp, libfreetype, libchipmunk) use iOS specific things.

Ok, ld that comes with Xcode actually checks for LC_VERSION_MIN_IPHONEOS build command. If it finds it, ld throws warning: ā€œURGENT: building for tvOS simulator, but linking in object file ā€¦ built for iOS. Note: This will be an error in the future.ā€

The second problem is that AppleTV apps will have to be built with bitcode enabled, so we are forced to rebuild all the needed libraries. I will do this a bit later.

Yay, my ATV Dev Kit gets here tomorrow.

Are you sure about the bitcode? When creating an AppleTV app in iTC you can set ā€œDisable Bitcodeā€, would be a major miscommunication on Apples part if they turned that off just days before everyone is going to submit apps. After all, they are the ones who need a LOT of apps in the Store from day one to compete with Android boxes.

No, they will not turn it off, but AFAIK apps submitted to AppStore with bitcode disabled will not be accepted.

PS. Bitcode is already mandatory for watchOS AppStore apps

Added scripts for building all the needed libs using AppleTV SDK. https://github.com/elvman/cocos2d-x-3rd-party-libs-src/tree/tvos

It seems that OpenSSL does not compile for AppleTV target. Will fix this later.

Thanks @elvman for great work on the scripts. While youā€™ve been into this. Do you see it possible that the SpiderMonkey and other cocos2d-JS related libs are compiled for tvOS too? There are sources for it available so it should be possible, right?

Yes, it is possible, but for now I want to finish porting cocos2d-x to AppleTV, so that I can launch my game on AppleTV AppStore as soon as it is launched.

I commited all the libraries built using tvOS SDK here: https://github.com/elvman/cocos2d-x-3rd-party-libs-bin/tree/tvos

Well, Apple has actually made Bitcode a requirement when building for tvos now:

target 'cocos2dx-tv' has bitcode disabled (ENABLE_BITCODE = NO), but it is required for the 'appletvos' platform

Thanks for all the work done Elvman and others.

Can someone advise how to fix all the bitcode errors . I copied all the 3rd party libraries across and changed all bitcode enable settings in Xcode to ā€œYesā€ but still get all the bitcode errors. Is it a matter of waiting for a bitcode enabled cocos2d-x version ?

No, you can actually compile everything for yourself. Using the 3rd party libs compiled by @elvman you only need to build cocos2d-x with Bitcode enabled. After that also enable Bitcode on your own project and you are good to go. I believe the 3rd party libs are tvOS only, so building a Bitcode enabled iOS app still wonā€™t work without rebuilding everything from scratch with Bitcode enabled.

I actually have all the needed libraries prebuilt already. You can download them here: https://github.com/elvman/cocos2d-x-3rd-party-libs-bin/tree/tvos

1 Like

Has anyone submitted an app yet? Any rejections or similar? A common reason for rejection seems to be the unability to exit the app from the main menu via a short press of the menu button.

I didnā€™t submit yet but I bumped into this thread earlier. Didnā€™t have a change to try it but maybe it helps you.
https://forums.developer.apple.com/message/54875#54875

Has anyone added menus to their game yet? I thought I could do without but needs a two button menu now, in case anyone has something ready mimicking the Apple menus, that would be great.

This is total great @elvman. Iā€™ve noticed that youā€™ve compiled also the lua script interpreter.

Did anyone tried to compile the spidermonkey with bitcode? Any hints on how to try that? Iā€™m still fighting with it with no good resultā€¦ Thanks!

Word of warning to anyone using Chipmunk, the simulation wigs out and starts spitting NaN floats after collisions for some reason. This only happened when using it on an actual Apple TV, not the simulator.

After some googling, I ended up at this thread and it seems to only happen with arm64 processors. https://chipmunk-physics.net/forum/viewtopic.php?f=3&t=3143

I rebuilt the chipmunk library without the -ffast-math flag and so far it looks good. Iā€™m not sure if thatā€™s a solid fix or not, but itā€™s good enough for my purposes.

Iā€™ve compiled libcocos2d tvOS.a and successfully run your sample on device. Then Iā€™ve included the very same library in my cocos-js project and received this error:

ld: ā€˜/pp/src/work/appleTV/cocos-js/sample-js-tvos/frameworks/libcocos2d tvOS.a(bio_lib.o)ā€™ does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE) or obtain an updated library from the vendor for architecture arm64

The lead shows on bio_lib.o which points to libssl.a (included with curl).

My questions:

  1. how come that the very same lib works in one project but fails in the other? Is it that c++ project donā€™t uses any of the ssl functions but JS project does?
  2. do you see my tracking from bio_lib.o to libssl.a as correct? It is only my guess based on google searches. No bio_lib.o exist on my computer.
  3. Iā€™ve tested libssl.a for bitcode presence using otool -l libssl.a | grep __LLVM and it prints nothing. That means there is no bitcode included. Would you point me where to do fix this and recompile it properly?
  1. My sample does not use libssl, so that is why it doesnā€™t complain about that.
  2. I will check and fix the libssl build script (I guess bitcode is not enabled for it)
  3. You can fix them in cocos2d-x 3rd party lib sources