Wednesday, April 26, 2017

Porting game from iOS to Android -- 8 or Bust (a Mathematical Puzzle)

https://play.google.com/store/apps/details?id=com.siddbetter.numbercrunchpaid



Recently, we decided to launch our game which was on iOS on Android. Releasing on Android made sense because of its reach and popularity.

Well, I started making research to be able to port my game from Objective-C to Java Android.

After going through some frameworks and site reviews on frameworks,  I decided to code natively using Android Java. Maybe because I had some prior knowledge of java. Also, the point that using a framework which allowed building in both would have made sense from scratch.

After having the first hurdle out. I explored which IDE to use. after struggling for a day in eclipse I switched to Android Studio.
 
Android Studio installed. I started out with some sample.
The Android Studio would crash a lot and be using emulator(ADB) for seeing the running code very tiresome. Although I always used the emulator in iPhone.
 
So I decided to work on my device instead of the emulator in the case of Android.
 
I started learning Android.

  1.  First I learned Activity and Views and how do they connect.  

             Activity is like a UIViewController in iOS.
    Storyboard --> got replace by layouts
            When I created an activity, the IDE asks me associated View and creates in layout folder.                      Connecting with tools:conext

         In activity --- by setContentView(r.layout.{activityname})
     
         Lifecycle changed - ---                                  
                    OnCreate                                   ViewdidLoad
    OnStart/                       viewWillAppear/ViewDidAppear
                    OnResume       viewWillAppear/ViewDidAppear -- Background
                OnPause                                    ViewWillDisappear/ViewDidDisappear
                    OnStop                                      ViewDidUnload
    OnDestroy                                  Dispose

          not exactly matching but close enough

2. Storyboard allowed connection in the GUI manner --- by connecting the screen fields in View fields.
       Android -- we have to do it findbyview
     
3. The major issue was the sizing issue iOS has only 2 sizes for iPhone and iPad. Android has no sizes standard.

        ViewGroup, FrameLayout, LinearLayout .....  
        Much of my time was spent in making the views suitable for all layout using LinearLayout ....              for my game activity I went on with Framelayout with actual sizing
        This became major task to get the code running for som many screens starting 4", 5", 7"  
         (HDMI, xHDMI,xx-HDMI)

        Understanding the size, layout, DPI concept is very necessary to be able to tackle this issue.
    4.  Next task was to port my objective C to Java.
 Not so difficult. other than replacing the performSelector afterDelay with handler.postDelayed

        What I most missed was NSPredicates,, filterarrays ... , valueforKeypath
        Replaced with Predicate, predicate.apply with some changes could achieve it.
   
        Rest --- MutableArray <-> ArrayList
                 MutableDictionary  <-> HashMap
             
                Got the mapping in place and which does not exists coded a class for their support
                Code Android Utility functions for matching function emulating ones in iOS.

    5.  Animation
               CABasicAnimation, AnimationGroup , UIView animation, [CATransaction begin/commit --
              - setCompletionBlock]

                replaced by
                ScaleAnimation and other Animation types with animation listener, ObjectAnimator,
                ValueAnimator, AnimatorSet,  AnimatorListenerAdapter

Interpolators
     
Missed CALayers of ios.
 
    6. CoreData Replaced by SQLite (using GreenDao for ORM)
    7. Emitter ---- droidparticle
    8. Volley for network  
    9.  Last was Localization --- Excellent support in Android with String and Values folder of resources.


All this typically were the element of my iOS to Android Port




                 

No comments:

Post a Comment