Apportable SDK is a product that allows you to compile a game (or application) developed on Objective-C / Cocoa Touch for iOS for Android without modification. This is a complete toolchain (compiler, debugger, linker - all, all), running Foundation, CoreFoundation, UIKit, many other iOS frameworks ported to Android (even such a trifle as GameKit and StoreKit, with backends for GooglePlus and Amazon GameCircle / Appstore).
The goal of Apportable is to give the iOS developer a transfer of their application to Android in an hour, without changing the code, and after that maintain one code base. How to port a simple toy on cocos2d - under the cut
Go to
the Apportable website .
After
registration, we are given an option to deflate the SDK, a user-specific link.
')
It will be pumped out for a very long time - Apportable uses patched android-sdk, ndk and other heavy artillery.
After installation, it will say:
Toolchain downloaded into /Users/darvin/.apportable/toolchain.
Apportable CLI is successfully installed at /Users/darvin/.apportable/SDK/bin/apportable
If you're using the default shell, add the Apportable CLI to your PATH using:
(echo; echo 'PATH="/Users/darvin/.apportable/SDK/bin:$PATH"') >> ~/.bash_profile; source ~/.bash_profile
So we do:
$ echo; echo 'PATH="/Users/darvin/.apportable/SDK/bin:$PATH"') >> ~/.bash_profile; source ~/.bash_profile
Now let's extort our guinea pig, some
random open-source game from the gitkhab , filed on Objective-C / Cocos-2d (support for cocor2d in the apportable is especially good, they are even the
official sponsor of cocos2d ). Disclaimer: the author has nothing to do with the experimental game, it is completely unadapted for the Apportable SDK, just a game on cocos2d
$ git clone https://github.com/haqu/climbers.git $ cd climbers
Checking to compile from Xcode:
$ open climbers.xcodeproj
We connect our favorite Nexus (or Galaxy, or non-Chinese without google-apps - there is almost no difference), run the utility that will create climbers.approj (this is a set of Apportable settings that are superimposed over .xcodeproj), compiles the project and uploads it to device:
$ apportable load
The utility first asks:
If the app is using OpenGL ES, does it use ES1 or ES2? (Cocos2D 1.X uses ES1, 2.X uses ES2)
[1/2] 1
Should the app initially launch in landscape or portrait orientation? (default: landscape)
[L/p] p
The toy uses Cocos2D 1.X, so the answer is “1”, the second question is “p”.
After the first attempt, the compilation falls off with error messages:
/Users/darvin/GAMES/climbers/Support/CocosDenshion/CDAudioManager.m:322: error: undefined reference to 'AudioSessionGetProperty'
/Users/darvin/GAMES/climbers/Support/CocosDenshion/CDAudioManager.m:382: error: undefined reference to 'AVAudioSessionCategoryPlayAndRecord'
......
/Users/darvin/GAMES/climbers/Support/CocosDenshion/CDOpenALSupport.m:227: error: undefined reference to 'ExtAudioFileDispose'
Updating Jar...
scons: *** [Build/android-armeabi-debug/climbers/apk/lib/armeabi/libverde.so] Error 1
scons: building terminated because of errors.
It complains about the missing
AudioFile * functions ... Google suggests that they are in the
AudioToolbox framework. Well…
$ vim climbers.approj/configuration.json
In the "
add_params " section we find the lines:
We fix on:
"deps": ["AudioToolbox"],
$ apportable load
The game is loaded on the connected Android mobile phone, even there is sound. The graphics went down a bit - the developer did not rely on different resolutions of androidophones, however, it is easy (and necessary) to fix, if you adapt the graphics too lazy, Apportable represents a
workaround that will scale the graphics as if the game was running on an iOS device. Let's try the second way:
At the beginning
- [AppDelegate applicationDidFinishLaunching:] add:
#ifdef APPORTABLE [UIScreen mainScreen].currentMode = [UIScreenMode emulatedMode:UIScreenBestEmulationMode]; #endif
Here we set the best emulation mode for the device - if its resolution / proportions are similar to the iPad - it will emulate the iPad, if on the iPhone - iPhone.
It is also worth removing unnecessary orientation selection code:
#if GAME_AUTOROTATION == kGameAutorotationUIViewController [director setDeviceOrientation:kCCDeviceOrientationPortrait]; #else [director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft]; #endi
Save, run the
apportable load command . See Objective-C / Cocos 2d toy on Nexus:
Fork the toys after porting to Android.
Only one configuration file has been added, five lines have been changed in AppDelegateFull listing of the porting sessionDocumentation and
mailing list available . Also, our specially trained engineers monitor
the StackOverflow tag .
Video session porting
tweejump .
Starter SDK Edition is
free , supported by Android 4+. Best of all, Apportable is suitable for porting games - applications still have different UI guidelines, and games are already run-in on
many appstor leaders . I will be glad to answer any questions, in the next article I am going to tell you how to quickly and painlessly tear out the bugs arising during porting and transparently, without changing the code base, integrate social frameworks,
StoreKit and GameKit.