Objective-C & C++ for Android

A Better NDK for Android

Cross platform apps without the pain.

Google's NDK


Google's NDK

  • Outdated GCC
  • A very minimal and buggy libc (bionic)
  • C++ support isn't great 
    • no C++11
    • slow STL
    • spotty support for exceptions, RTTI
  • hard to debug
  • no docs - you have to read the source
  • hard to use

At Apportable, we have a few beliefs

Rewriting your app over again to support another platform is a waste of time and effort

You should be able use the best tools and languages to develop mobile apps that work on multiple platforms.

About Apportable

  • Started a little over two years ago (YC W2011). 
  • First app, Osmos, shipped was Jan 12th 2012
  • Today power dozens of best sellers on Android 
  • Raised $2.4m led by Google Ventures in July

What exactly is the Apportable SDK?


What Apportable is not.

  • Is it NOT source code translation
  • It does NOT generate Java.
  • It is NOT an iOS emulator on Android (like WINE)

The Apportable SDK compiles your Objective-C (iOS) and C++ source code into to a native application that runs on Android. 

Just to repeat that....

NO JAVA.

NATIVE.



(Yes, you can do native on Android.)

How does Apportable work exactly?

Lets just port something!




  • Visit www.apportable.com and sign up
  • Install the SDK and toolchain
  • Open a a terminal and navigate to your source code
  • Plugin in an Android device
  • Run apportable load and answer a couple of questions about your app
  • Thats it. You should see your app running on Android!*

    The Apportable SDK includes:

    The latest and greatest clang.

    Our own fork of it with added much better support for Android.
    The same clang used by Xcode for iOS development.

     

    Frameworks
    and libraries

    UIKit
    Boost
    ICU
    libpng, libgif, libtiff, libjpeg
    CoreGraphics
    OpenAL
    CoreAnimation
    libobjc
    C++11 (libc++)

    libc
    libdispatch
    Core Foundation
    Foundation

    Support for many binary 3rd party binary libraries from iOS

    • Flurry
    • AdMob
    • Chartboost
    • etc

    Most source libraries without of the box (Facebook, DropBox, etc)


    Debugging and tools

    • Latest and greatest GDB 
    • Our own Apportable profiler suite
      • memory, network, performance
      • like a mini instruments

    Use All The Best Features

    • C++11 
    • Assembly
    • Objective-C ARC
    • Objective-C literals
    • Objective-C Runtime API (swizzling, etc)

    We have done the hard work of supporting the variations in Android for you.



    Building for Android

    How you can make your app fit on Android with your cross platfrom source code

    Support More Screen Resolutions

    • Handling the native resolution is best and will always look the best.
    • If you made assumptions about iOS screen sizes, you can emulate them on Android and scale your UI up with UIScreenModes.

    #ifdef ANDROID
      [UIScreen mainScreen].currentMode = 
         [UIScreenMode emulatedMode:UIScreenBestEmulatedMode];
    #endif

    Add Hardware Button Support

     - (void)buttonUpWithEvent:(UIEvent *)event
     {
        switch (event.buttonCode)
        {
            case UIEventButtonCodeBack:
                // handle back button if possible,             // otherwise exit(0)
                break;
            case UIEventButtonCodeMenu:
                // show menu if possible.
                break;
            default:
                break;
        }
     }
    
     - (BOOL)canBecomeFirstResponder
     {
        return YES;
     }

    Use different device information

    UIDevice+Apportable.h
    @property (nonatomic, readonly) NSString *nativeCPUABI; 
    // e.g. "armeabi-v7a"@property (nonatomic, readonly) NSString *nativeModel;  
    // e.g. @"Xoom"
    
    @property (nonatomic, readonly) NSString *nativeManufacturer;
    // e.g. @"Motorola"
    @property (nonatomic, readonly) NSString *nativeSystemVersion; // e.g. @"4.2" @property (nonatomic, readonly) NSUInteger nativeSDKVersion; // e.g. Froyo is 8 @property (nonatomic, readonly) NSString *macAddress; // requires access_wifi_state @property (nonatomic, readonly) NSString *odin; // open device identifier number @property (nonatomic, readonly) NSString *nativeSecureIdentifier; @property (nonatomic, readonly) NSString *telephonyIdentifier; // read_phone_state
    @property (nonatomic, readonly) NSString *carrierBranding; // e.g. @"Verizon"

    Customizing your build 

    • Edit the .approj directory generated next to XCode project.
    • In the <project>.approj/configuration.json file you can:
      • Add and remove source files
      • Tweak the APKs features and permissions 
      • Change defines, icons, and other settings


    Full support for Java

    No limitations on using Java. Use what works best to solve whatever problem.

    BridgeKit

    • BridgeKit is a fully Objective-C API for bridging to Java and calling Android APIs or custom Java code
    • Used to back much of UIKit and system APIs
    • Subclass Java classes in Objective-C
      • Generates classes with dexmaker
    • Handles memory management of Java objects inside an NSObject correctly
    • Best of both worlds

    http://static.apportable.com/documentation/BridgeKit/html/

    Bridging Application Lifecycle

    • Apportable converts Android lifecycle events to compatible iOS ones. For example,
      • onCreate->application:didFinishLaunchingWithOptions:
      • onPause->application:willResignActive,
      • onStop->application:didEnterBackground
    • When an Apps are in the background, iOS suspends your threads, but Android does not, so Apportable emulates that by suspending them.

    Push Notifications and Local Notifications

    • Push notifications are handled by Google Cloud Messaging on Google Play Apps
    • Local notifications translate to a custom alarm service

    In App Purchasing (StoreKit)

    Apportable's StoreKit bridges to Google In App Billing (on Google Play) and Amazon Payments (on Kindle).
    Near full StoreKit compatibility.

    iOS Framework Support

    • Great OpenGL and OpenAL support
    • Foundation - Near full coverage. Major update in development
    • CoreFoundation - Good coverage, full support in development
    • CoreData - working, limited to automatic migration support only
    • AVFoundation has audio but no video support
    • MediaPlayer supports video and audio (codecs depend on device, ogg is the most universal)
    • CoreAnimation - partial, new version in development backed by OpenGL
    • UIKit - current shipping UIKit works for simple apps. Backed with Android views. a full UIKit support backed by new CoreAnimation in development

    iOS 7 Features

    SpriteKit - In dev, currently 20% faster than iOS (even on iOS)
    GameController framework ready for native controllers

    Works great with OUYA and Google Glass

    OpenGL based UIKit preview


    Cocos2D

    • Apportable is the primary sponsor of the cocos2d-iphone project.
    • CocosBuilder also now Apportable product


    We Love Open Source

    http://github.com/apportable/
    Android SDK/NDK (Apache Software License 2.0), Apple CFLite (APSL 2.0), Apple Objective-C Runtime (APSL 2.0), Apple XNU (APSL 2.0), Boost (Boost License), Breakpad (BSD License), BSD libc (BSD license), Clang (LLVM license), Cocotron (MIT license), CommonCrypto (APSL 2.0), Crystax (BSD license), DDS decoder (NVIDIA general license), Facebook SDK (Apache Software License 2.0), FreeType (FreeType license), GIFLIB (MIT License), gles2-bc (Apache Software License 2.0), GNUstep Objective-C runtime (MIT license), Google Market APK Expansion Library (Apache Software License 2.0), JMDNS (Apache Software License 2.0), JSON (new BSD license), kazmath (BSD license), libcurl (Curl License), libdispatch (Apache Software License 2.0), libexpat (MIT License), libjpeg (libjpeg License), libkqueue (BSD license), libpng (zlib license), libpthread_workqueue (BSD license), libtarga (MIT license), libtiff (MIT License), libuuid (Modified BSD License), libvorbis (BSD license), libxml2 (MIT license), OpenGLES (SGI Free Software B License Version 2.0), openssl (OpenSSL license), SBJSON (BSD license), Skia (Apache Software License 2.0), SQLite (public domain), uriparser (new BSD license), ZFont (Apache Software License 2.0), zlib (zlib license)

    About me

    • My name is Zac Bowling
    • Platform Engineer at Apportable
    • 100+ hackathons in the last 4+ years (may of seen me in Wired Magazine, Business Insider, or Dutch public television)
    • Email: zac@apportable.com
    Made with Slides.com