Play2 is a template for creating iOS and Android apps sharing a common non-UI core.
Base your new iOS and Android apps off Play2 infrastructure to maximize code reuse and save development time.
You get the maximum benefit if you develop app on both platforms at the same time. About 50% of app's functionality (conceptually) can be reused, but your milage may vary.
The project is based on several open source technologies that work together to create a tremendous value.
Play2 is a rouge fork of mx3 by Steven Kabbes. The folder and makefile structure is mostly unchanged, but dependencies and code of the actual starter apps have diverged significantly.
- Latest Xcode with Command Line Tools
- Android NDK
The bundled starter iOS and Android apps are type of "pull to refresh" that display results in UITableView and ListView. The functionality where code is shared across platforms:
- Making HTTPS request and downloading JSON response
- Unpacking JSON response and saving it into sqlite3 database
- Pulling data from local sqlite3 database in form of a local API
- Some business logic, mostly around data
Since the focus of this project is sharing of non-UI code across platforms the opportunities for useful unit tests are abound. The project includes some fairly useful starter unit tests as well as Xcode and Jenkins friendly options to invoke them.
-
Run
git clone https://github.com/yevgenyk/Play2.git
-
Run
cd Play2
-
Run
sh subs.sh
to set up and pull submodules -
Optionally run
sudo gem install xcpretty
to beautify the output ofxcodebuild
-
===> If you get compile errors this may be because the version of Djinni is not stable. You can pin to an older commit. Only do this if you canot compile.
cd deps/djinni git checkout 137c2ea8fd12635ca29e98af6bffd3018e822451 cd ../..
-
Run
make mac
-
Run
make tests
This builds and runs a series of gtest unit tests that are ran inside mac shell. The last test downloads some JSON data from a remote site, updates a local database and pulls back the results. This means every time you run it the final
Updated count
value will be different.
If you have gotten this far you should proceed to the actual starter apps!
- Run
make ios
to generate objective-c proxies used by the actual app. - The actual app is located in
app-ios/app
folder. - The iOS app in app-ios should run, pick the target called 'app' It should just load and run. Pull to refresh to see numbers change! Updated numbers will show up in blue!
- Make sure you have Android NDK installed on your mac. Make sure its folder is in PATH.
Something like this:
export PATH=$PATH:/Users/yevgeny/android-ndk-r10d export ANDROID_NDK=/Users/yevgeny/android-ndk-r10d
- Run
ndk-build
and you should see this errorAndroid NDK: Could not find application project directory !
. This is what you want. Runmake android
to build the example android application - Run
make androidNdk
to build JNI libraries. This will produce the shared shared libraries needed by the Android app. - Run
make androidJava
to build Android app using gradle. The app is located inapp-android
folder. You can open this project in Android Studio by choosingapp-android/app
folder and importing it as gradle project.
make clean
- cleans all generated filesmake tests
- runs the unit testsmake ios
- builds a static library for iosmake mac
- builds a static library for macmake androidNdk
- builds JNI shared library for the Android appmake androidJava
- builds the Android app using theapp-android/app/build.gradle
script
- Play2.gyp - gyp definition file which spcifies targets and dependencies
- Application.mk - the android make file, you should modify this file to specify things like APP_ABI which is curently set only to x86 to speed up compilation
- Makefile - helper for interacting with gyp, and using command line builds (no xcode!!)
- deps/ - third party dependencies
- objc/ - objective-c code for iOS/OSX implementation, and also generated objective-c files
- src/ - shared implementation code
- test/ - gtest tests
http://codingsimplicity.com/play2-starter-project-ios-android-using-dninni-and-gyp/