I launched my first Android app ("Brainy Mathdoku") last week using the Kivy framework. I have an engineering background and have done some programming work (primarily in C) many years ago (probably before some of you are born here). Recently, I decided to learn how to code again and I am particularly interested in mobile devices. I came across a post by someone (tito) who did some weekend hack on the game 2048 using the kivy framework and decided to give it a try. I believe Kivy largely fits my original expectations. The following summarizes my experience with Kivy, which hopefully might be useful to someone in this community. Please download our app and give us some feedback.
https://play.google.com/store/apps/details?id=com.hilgol.geniussquare
1. My development environment is on a Windows 7 laptop. My initial target environment is Android but I also want to target iOS. I initially played around with pycharm vs the standard python IDLE interface. I ended up using python IDLE as pycharm seems slow and I do not need all the bells and whistles of pycharm. One of the best things I like about the Kivy framework is that you can test the code in PC (generally much faster than mobile, more on that later). After you feel comfortable with the UI, you can then test it on a real Android device using the Kivy Launcher ***without any compilation***. To me, that removes the barrier of entry for many would-be programmers like me. I really liked the idea of virtualbox for a release build environment, it makes things a lot easier. I did run into a trivial issue initially. After the installation of virtualbox and the Ubuntu environment, I only get a desktop with nothing (no icon or menu) on it. Then I figure out how to launch a terminal by using Ctrl + Alt + T. The next challenge on Ubuntu is bit more difficult to overcome. I ran out of space on the .vdi file. I took me a bit of digging to figure out how to resize the vdi file:
a. VBoxManage clonehd oldxp.vdi newxp.vdi https://forums.virtualbox.org/viewtopic.php?f=8&t=24505
b. Download Gparted and make USB bootable. Create a virtual machine in virtualbox using the USB image (by using the pointer image). Next follow the steps in the article below….. http://www.howtogeek.com/187721/how-to-boot-from-a-usb-drive-in-virtualbox/
2. Documentation: I find the documentation well written. To be honest, I have made many dumb mistakes initially. However, most of them are driven by my lack of experience in OO and UI implementation, rather than lack of documentation. I find the sample codes to be especially useful. I solved 95% of my questions by going through the sample codes.
3. UI Widgets and Animation: I was initially disappointed by the lack of a visual design interface. I now understand it is extremely difficult to use such development tool to accommodate the multiplicity of devices out there. The kivy language is a little abstract to me at first. Following the sample codes, I figure out how to do everything I want to do.
4. I used buildozer to build the final apk package. I would say this is the trickiest part of the whole process as there are a lot of platform dependent (Android) factors. I have spent a fair amount of time initially in getting it to work and learnt two things: use the “verbose” option in buildozer and make sure you understand how to use “adb logcat.” [Make a point to learn adb if you are targeting Android. It will save you a lot of time.] Building an apk is relatively straightforward. However, as you add platform specific functionalities to it, you have to play around with the library and the buildozer.spec file. I have implemented four platform specific functionalities:
a. Google Game Services – Please read http://kivy.org/planet/2014/03/2048-in-python-kivy/ and https://github.com/tito/2048/issues/2 I think everything you need to know to get the code to work is included in the two articles.
b. Facebook Integration – I follow the procedures laid out in http://kivy.org/planet/2013/08/using-facebook-sdk-with-python-for-android-kivy/ I ran into some issues initially. It turned out Facebook now requires approval before you can use most of their API. I registered at developer.facebook.com. The process is free but the documentation of facebook approval process is quite poor. It took me a few back and forth with facebook before they finally approve my app id which is required if you want to use the OpenGraph API.
c. Email / Sharing – I largely follow examples used in pyjinius; Please see pyjinius source code for more details https://github.com/kivy/pyjnius
d. Flurry Analytics – I registered with flurry and download the android SDK. I have to add FlurryAnalytics-4.1.0.jar to the lib folder and adjust the buildozer.spec accordingly. To use flurry analytics in the kivy code, this is what I did:
flurry_api_key="XXXXXXXXXXXXXXXXXXXXXXXXXXxx" # put in your api key
PythonActivity=autoclass("org.renpy.android.PythonActivity")
flurryagent = autoclass("com.flurry.android.FlurryAgent")
HashMap=autoclass('java.util.HashMap') # Java HashMap class = Python Dictionary
flurryagent.setVersionName(__version__) # set version to be reported to Flurry
flurryagent.setContinueSessionMillis(60*1000) # 1 minute for new session
current_activity=cast("android.app.Activity", PythonActivity.mActivity)
flurryagent.onStartSession(current_activity, flurry_api_key)
_flurry_event_data(“event1”, flurry_data=flurry_data_dictionary)
…………………………………
…………………………………..
def _flurry_event_data(event_name, flurry_data, flag=True):
global platform, HashMap, flurryagent
if platform=="android":
params=HashMap()
for k, v in flurry_data.items():
params.put(k, v)
flurryagent.logEvent(event_name, params, flag)
else:
pass
5. Speed of devices/widgets: I really like the ease of adding widgets dynamically in Kivy. However, I found out there is a catch – you have to be careful with the number of widgets as it can slow down the app drastically if it is overly used. [I didn’t notice the issue as I was doing a lot of testing on the PC] In couple of screens, I need to break them into multiple screens so that the user experience is acceptable.
Overall, I would say the kivy team has done an excellent job and the framework definitely meets my expectation. Please check out my app https://play.google.com/store/apps/details?id=com.hilgol.geniussquare and ping me if you have any comments or feedback. Cheers.