A not so brief introduction to KaiOS and app development for it
#kaios #bananahackers #appdev #dev #development
If you have checked recent messages(around 11-01, 3 o'clock UTC. I think it wouldn't be so “recent” at the time you are reading my post), you could see yet another guy or girl interested in developing apps(in this case games) for KaiOS. Since it wasn't the first time someone newcomer in the BananaHackers community interested in app development had shown up, and since they were asking almost the same set of questions every now and then, I thought writing a blog post regarding that would be a good idea.
Here you go with a list of titles and a sentence about what's inside the said section:
A wild Mozilla reappears after about 5 years: Some historical words on the origin of KaiOS, Mozilla's late FirefoxOS, and the difference between FirefoxOS and KaiOS.
Hardware properties of KaiOS devices: In this section, I've written about what hardware KaiOS devices usually have, including physical keys, the display, connectivity, and other hardware features or properties.
Software properties: I've written what type of apps does KaiOS support, where to start developing for KaiOS, what language and technologies you can choose from, and such these.
The reasons why you might not want to develop for KaiOS: Here I have mostly linked to another blog post regarding the reasons why you might not want to develop for KaiOS at all.
Hardware requirements for the app development: This section is about the main coding device you need to develop for KaiOS as well as the KaiOS development device you can choose.
Links collection: I've linked to resources you probably will need while developing for KaiOS.
Last words: Last words of the post...
A wild Mozilla reappears after about 5 years
Before going through anything else let me write a few words regarding this Operating System calling itself “Open”. KaiOS is just FirefoxOS or B2G which appeared years ago from Mozilla, by some called the web Robin Hood. I remember at that time it was a trend for almost every company to have their own mobile operating system. You could see Ubuntu Touch from Canonical, Tizen from Samsung if I remember correctly, FirefoxOS from Mozilla, and I suppose a few others which I don't remember right now.
The late FirefoxOS was a web-based operating system for (low-end?) touch devices. This means the operating system was a big browser having web apps running in. And B2G stands for Boot2Gecko. Gecko, according to Cambridge dictionary, is a small lizard with wide feet, found especially in warm countries
. You can pet one but I don't guarantee it does not bite! I never had one to pet but geckoes seem pretty cute. Don't they?
However, in the context of front-end development, especially Firefox browser, is the name of an engine:
Gecko is the layout engine developed by the Mozilla Project and used in many apps/devices, including Firefox and Firefox OS. Gecko interprets JS, HTML and CSS plus embedded content like images and draws everything on the screen of the user's device. Gecko among other things includes a networking stack, graphics stack, a JS VM, and many other stuff.
So now that you kinda know what FirefoxOS is, you also know what KaiOS is. KaiOS is a version of FirefoxOS launched in 2018 for “smart feature phones” with no touch support(at least devices launched till now, which are running KaiOS v2.x or v1.0 never had touch support as far as I know). Most of these devices have got an ABC keypad. To read about the hardware properties of KaiOS devices, go ahead to the next section.
Kai means open in Chinese. So KaiOS means open operating system.
— From somewhere on KaiOSTech
Hardware properties of KaiOS devices
Physical keys
All KaiOS devices have got an ABC keyboard, with JioPhone 2 as an exception which has got a nice and soft QWERTY keyboard(see the photo below from tbrrss. This photo was originally used on this wiki page dedicated to JioPhone).
Other than that all KaiOS devices include D-pad navigation keys(up/down/right/left), Okay or Enter key to confirm things usually(or shoot at enemies in some games), Soft left and Soft right keys, Call key and Power or Back(space) key. Many devices have got one or two more keys like my Nokia 800 Tough which has got a shortcut key above the Call key and Back(space) key above the Power key.
So to sum up you've got these keys on all devices(excluding JioPhone 2):
0
to9
ArrowUp
,ArrowDown
,ArrowLeft
,ArrowRight
Enter
Call
Backspace
SoftRight
SoftLeft
And these two as optional because you won't find them on all devices:
- Power
- Shortcut key
There are also other physical keys on some devices. Like the side power key on the BananaPhone(the other name for Nokia 8110 4G) which you can use to turn the display on/off and power the device on or off. Or 2720 Flip has got that of 8110 and two keys on the side for volume up and down. Not sure if you can capture even of these keys in your app.
Display/Screen
Regarding the display all devices have got a 240x320
one(height is 320 pixels and width is 240). JioPhone 2 is however an exception having 320x240
instead. Note that the size of the screen of devices is not the same for all devices but the screen resolution is. That's all that you've got to draw your content on.
Many devices like Nokia 2720 Flip have got another display, usually black and white. According to the website of Nokia, the Flip has got a secondary 1.3-inch front display which displays incoming text messages or caller ID of some incoming call as well as time and date. But I don't think you could use this screen in your apps to display stuff on them officially. And even if you could, it doesn't worth it to add such a functionality to your app which only a few users, comparing to the whole, could use it. Nevertheless, it would be a fun hack but in my humble opinion, not practical.
Connectivity
Now let me write a few words about the connectivity features of KaiOS phones. These “smart feature phones” usually support 3G or 4G mobile data and Bluetooth v4.x. Most of them also have got WiFi support so you won't have to waste your data plan if you are near your work or home router/access point. The other feature they usually have is Internet sharing with USB or WiFi tethering(supporting WPA 2-AES, WPA-TKIP, or no security). There is also (A)GPS but at least for me it doesn't work well every now and then and everywhere I try it. Some suggest it's not as good as some of an Android phone.
Both my KaiOS phones, the late Bananaphone and the Tough support 4G mobile data on the primary SIM card and I suppose 3G or H on the other SIM card. Of course, you probably could have 4G on both cards using this trick from the BananaHackers wiki(the origin of it is the BananaHacker website, however, added there, by Ivan Alex HC).
4G or 3.9G?
The 4G connectivity of some KaiOS device is not like a real 4G. According to my experience and reports from a friend of mine named Ivan Pasev, KaiOS limits(or has the limitation on) the maximum bandwidth you can use. It's still faster than 3G but probably slower than the typical 4G you would have on most Android phones.
Other hardware features
Physical ports
KaiOS devices in general have got a microUSB port supporting USB 2.0 only which can be used for debugging, sideloading apps, Internet sharing, charging, and EDL if your device has got a Qualcomm chipset. They also come with a 3.5mm audio jack for audio input and output. Nothing new compared to other phones. Huh?
Camera
Compared to Android or iOS phones, the Camera(s) of a KaiOS device hasn't got anything to say. Nokia 8110 4G(aka the BananaPhone), 8000 4G, 2720 Flip, and 800 Tough have got only a single 2 Megapixels rear camera with no front one. 6300 4G has got only a rear VGA camera with no flash.
However, according to KaiOSTech's device list, there are many other devices with both rear and a pretty weak front or selfie camera. I would like to just name a few:
- Akeza 4G, front: VGA, rear: VGA
- KaiOS ONE, front: VGA, rear: VGA
- Digit 4G Bold, front: VGA, rear: VGA
- myPhone Up Smart LTE, front: VGA, rear: 5MP
- ...
Processor, Memory and Graphical processor
I am lucky to have a Nokia which uses a Qualcomm Snapdragon processor with 512MB of RAM. Many devices have got only 256MB. Newer Nokia phone models like 8000 4G use a higher version or model quad-core Snapdragon instead of dual-core like my 800 Tough.
On the other hand, not all are lucky like I am. According to the BananaHackers wiki(which its content mostly comes from bananahackers.net written by the founders of this community including Ivan Alex HC), there are devices with Mediatek based or Spreadtrum based chipsets. Which in some people's opinion are not as good as Qualcomm's. I cannot comment on this since I'm not much of a mobile hardware geek. Also, there are devices whose chipset was never specified anywhere as far as we know.
Regarding GPU, the KaiOS devices of Nokia which have got 512MB of RAM and Adreno as graphical processor unit, can run Christian Waadt's AirshipCombat 3D single and multiplayer game very well. It's an action shooter 3D game for KaiOS and a few community members, especially one, were addicted to it, at least for a while! I'm not sure if Christian has the game's server still up so that you could still test the multiplayer part of the game. But you always can test its mission-based single-player mode. You can read or see more about this game through this link on BananaHackers' webstore and perhaps download it and sideload it to your device. There is another 3D game for KaiOS, named Marble3D or something a lot like Neverball, which I was playing on my late Bananaphone and was very fun, fast and smooth.
But that's not the end of the story! While these two 3D games were running smoothly on my device with Snapdragon and 512MB of memory, I remember Christian had reported that he had problems running his game on devices with 256MB instead of 512. I don't remember if he finally solved the problems or not. But if you are going to write a 3D game for these devices, I would recommend you get in touch with Christian. He is(or at least used to be) available on BananaHackers chatrooms available through Discord and Matrix(here's a link only to app development room, in the case your client does not support Matrix spaces)
Farooq's dream KaiOS device
I always wished there was some non-Jio KaiOS device available in my country. With a soft keypad like you see in that photo of the lovely JioPhone. Perhaps with 8GiB or 12GiB of internal memory instead of 4, a quad-core processor, and at least 1GB of memory(RAM). But not always things go according to our wishes and not always everything's in our hands.
Software properties
As you have read earlier in this post of mine, KaiOS has come from the ashes of Mozilla's late FirefoxOS which is basically a big browser with multiple tabs(called web apps). FirefoxOS was for a variety of Android touch devices. KaiOS, however, excluding KaiOS 3.0, doesn't support touch at all. And for KaiOS 3.0 which is still not out at the time of writing this post, there are whispers that it would support touch devices. But we can't be certain till a while later we see KaiOS 3.0 devices.
So where to start?
Obviously, you need to know programming and coding if you want to write apps for KaiOS. So I'm not writing here about how to get started in this Computer Science area. If you don't know to program, you should already learn that. Like you cannot go to the third level before you haven't passed the second one. And there's no lift! It doesn't matter what language or technology you start in my opinion. It just does matter that you start. If your goal is writing apps for KaiOS or Front-end development, you could start with Javascript but there might be other options as well which I have written a little bit about them in the later sub-sections.
What language(s) should I learn?
First of all, English and I am serious! You'll need English to read the stuff on the Internet and learn from there as well as being in touch with other community members. CS is not the only area of science that requires people to learn English before anything. Nowadays, English is the language of science and scientists and if you want to access sources of knowledge you must learn it. Just like one had to learn Persian and Arabic languages in the Islamic Golden Age, in the past pre-modern days if he or she wanted to gather knowledge from the others.
As you now know, KaiOS apps are web applications. This means most likely you want to go with Javascript, CSS, and HTML. There is another option, too: Write in like C, C++, or Rust and compile them to some sort of Assembly! In theory, you can do so for a variety of languages. But in reality, there might be no good toolchain or compiler or possibly nothing at all for your favorite language.
But what is this “Assembly”? I'm referring to asm.js and WebAssembly or WASM which you could compile your apps to one of them. asm.js is a subset of Javascript. Note that just KaiOS 3.0 and later support WebAssembly. On KaiOS 2.5 or so you could use just asm.js which is slower than WASM. You can read this post on Mozilla Hacks if you want to ask why.
Does it mean you could abandon the sloppy Javascript? I'm unaware since I've never entered this area. But I am certain about a few things:
You probably can use a language like Rust to write almost all parts of your app and abandon HTML, CSS, and JS. For example, see egui project on Github which doesn't use HTML at all. Everything in pure Rust using WebGL compiled to WebAssembly. See their demo here with a browser supporting WASM.
You surely can have certain parts of your web app in, for example, C++. By using a C++ library compiled to asm.js(or WASM for KaiOS 3.0).
I'm going with the sloppy Javascript. So any frameworks I could use?
This section is for those who want to go with Javascript for whatever reason. Perhaps they are starting programming and Javascript is way easier than a language like Rust. Or perhaps just because they want to write a simple app and don't want to bother with compiled languages.
You can write your dream web app for KaiOS using vanilla Javascript and not using any framework. This brings a great performance compared to using most frameworks. Also, you won't have a build or compile process before you could test your app in the browser. But not using any framework ruins maintainability overtime when the code size grows. In my opinion and experience, if your web app is going to get bigger than small or trivial, it would be much better if you had used some framework.
However, you may not go with any framework out there. Compared to normal web app development, there are a few things you'd better consider including these:
There is no mouse or touch on KaiOS devices. This means the navigation and control are completely done by keys. Nevertheless, there is an exception: you could enable “emulated cursor” in your app's manifest. After that user will have a cursor that could move it using D-pad and click anywhere using the
Enter
orOkay
key. But that is not convenient for users at all and also you won't be able to use the full capacity of the device inputs. Not to mention that it is impossible for something like Christian's AC3D which I've named in the “Processor, Memory and Graphical processor” sub-section.As I said in the “Display/Screen”, the screen resolution is pretty low. About 10 pixels shorter in height if you have enabled the status bar in the manifest. Most likely about 10 pixels less for Softkey labels.
The most important thing: Performance, performance, and performance! Firstly you've got only 256-512MB of RAM some of which the operating system itself uses. Secondly, the processor used by KaiOS devices is not so powerful. 2 or 4 cores running at 1.0 to 1.4 GHz usually. And the third concern is that you are developing for mobile with small batteries with a capacity of about 1500-2500mAh. You absolutely don't want to drain all the power saved in the device's battery by using some nasty and heavy framework doing hundreds or thousands of unnecessary or avoidable operations in a second.
So after all these, especially the last one which is performance, you have to chicken out many frameworks, probably including ReactJS. And with any other framework, you would want to optimize it enough especially for memory consumption unless you want the OOM killer to commit an unforgiving crime(from your point of view as the developer of the app and not as a user) and murder your app!
I personally use InfernoJS after some experiences with pure JS(no framework) in many of my apps like https://notabug.org/bananaphone/vm-irc, Fooplot, SimpleQuran or toys like TalkingBot. Inferno is a fork of the famous ReactJS optimized for mobile and high performance. According to benchmarks on Inferno website, it is just a bit worse than Javascript with no framework while it brings good features of ReactJS(it is unclear, at least for me, that such a performance is gained by disabling normalization or not). This framework is also has been suggested in KaiOSTech's developer FAQ here. And I've heard by some, Inferno is what KaiOSTech itself uses for stock apps of its operating system. However, I can't confirm or deny that.
After all these, InfernoJS is not the only option you've got. I've seen many using other frameworks. I will name a few in brief:
garredow uses Preact for his foxcasts-lite podcast app.
tbrrss uses Svelte for his PodLP podcast app.
speeduploop, one of the founders of the BH community, uses Mithril for his ADBroot app. Just look at the small code size!
According to the benchmark on Inferno website and many other benchmarks which you can easily find using your favorite search engine, for example this one on Medium, all these frameworks provide better performance compared to ReactJS.
Let me end this part with a few words regarding other concerns you should have:
The CSS you use is important too. You'd better not forget that! KaiOS, excluding v3.0, hasn't got Quantum engine
The library and modules you use are just as important as the framework you use. They must be optimized for performance especially memory. Remember the OOM killer? However, sometimes you have not got many choices. For example for Chooj it seems the only option I've got so far is matrix-js-sdk. Also, you might need to modify the library you want to use, a little or more than a little, to suit your requirements. Again for Chooj, I have to somehow make mozSystem property enabled in XMLHttpRequest or CORS will block the requests I make.
The reasons why you might not want to develop for KaiOS
I've written a separate blog post about reasons one(mostly a user) would not want to use a KaiOS device. Writing apps is useless if there are no users to use them. Right? However, there is no absolute good or bad operating system. I highly recommend reading that post or at least the titles inside if you are thinking to spend time and effort developing apps for KaiOS, especially as a real job and not only a fun thing.
Hardware requirements for the app development
So you are sure you want to develop for KaiOS? Firstly you need a PC or laptop or something with a comfortable and fast keyboard to code on. The good news is that you do not need 8GB of RAM only for Android Studio or 4GB for Flutter! You only need enough for these:
A Firefox tab which you test your app there in most cases.
2 or 3 more browser tabs to search stuff on the Internet and read them.
WebIDE to deploy your app to your KaiOS device and also to debug it. You probably could use command-line tools like Luxferre's gdeploy or Fabrice's b2gclitool which eat less of your valuable RAM.
A Matrix client to join BananaHackers Matrix rooms so that you could get in touch with the community and perhaps ask questions from them. Fortunately, there are a variety of Matrix clients for many operating systems including but not limited to KaiOS, Windows, Android, GNU/Linux, and OS X. From Terminal-based Weechat to graphical and memory hungry Element. The choice is yours. See a list of clients here
At last the Operating System you use also will consume memory. If you don't have much memory available, you could go for a pretty light-on-memory but yet well-supported Linux distro. For example those with XFCE or LXDE as graphical shells. You could alternatively use just a window manager like Openbox or my favorite tiling WM, i3 which eat much less memory compared to something even like XFCE.
Another device you need for KaiOS app development is obviously a KaiOS device. But not any device. Of course, you should be able to install your app on your KaiOS device through your other device, say your laptop. This process is called sideloading and you need to enable debugging mode on your device to sideload apps. The process of getting debug mode enabled is not the same for all devices. On some nearly impossible or really hard and on some is easy like prey. You can read stuff on the wiki or the website.
If you need quick advice, most community members, including myself, will suggest Nokia phones for development. The reason behind this, other than the fact that a Nokia device is unlikely to be unavailable in your region, is that enabling debug mode on Nokia devices is as easy as dialing *#*#33284#*#*
and voila! A bug icon will appear in the status bar meaning now you can sideload apps to your device through your computer! There are, however, at least two confirmed exceptions: Nokia 2720 Flip and 800 Tough if you upgrade their firmware to v30
(do not confuse with KaiOS v3.0 that's a different thing). Fortunately, before the OTA update become available in my region, a friend told me not to upgrade to firmware v30. And thanks to him, I did not.
Links collection
While I tried to put as many links as possible in the content to give you clues for further reading, there are many links which either did not fit in the content, or I think I would better repeat them here.
BananaHackers wiki and website: Contains handy resources on rooting different KaiOS devices, developing on them, code snippets, device APIs, and much more. You can contribute and add content too! Just ask for a wiki account and permission to edit and add pages. Any good contribution to the wiki shall be appreciated!
BananaHackers chatrooms on Matrix and Discord: You can keep in touch with the community, ask from them or answer their questions and share the progress on your work with them. As always don't ask to ask just ask!
Unofficial KaiOS development wiki by alego4710: Contains useful resources regarding app development for KaiOS.
B2G docs on Wayback machine: These pages are super helpful. At least the APIs part has been so helpful for all of us. It is so unfortunate that Mozilla removed these from MDN. If the Wayback machine link did not work for you, there is an alternative link from the University of Chicago. And finally you might want to check out this Github repository to self-host these or for offline use.
Adrian's KaiUI: It has got UI components for creating KaiOS apps. It is in ReactJS but you could easily use the (S)CSS files and port to other React-like frameworks. For example in my project, Chooj, I have ported many of those which I needed to InfernoJS. See this directory on Chooj's repository
nadim's KaiUI: It has got fewer components compared to Adrian's. It still seems nice.
KaiUI topic on Github: You can see other KaiUIs.
Tom's blog about KaiOS: You can find many interesting information here about KaiOS devices and also app development for them. Tom is the developer of PodLP, a very popular podcast app for KaiOS and one of the most popular apps in 2020
Got any other useful resources? Feel free to tell me about them by emailing me and I will add them to the collection.
Last words
I am not a professional developer and my knowledge is limited. Feel free to contact me, either by commenting under this post or emailing me or pinging me on Matrix, if you think something was written not right by me or perhaps some of my writings were not clear enough.
While I would be happy to answer your questions regarding app development for KaiOS if you contact me somehow, I highly recommend that you ask in the chatrooms and if you want my attention, you could ping or mention me there. This way others could enter the discussion. Perhaps their answers are faster or more correct than mine. Also, others could use your answered question and benefit from it. Of course, this does not mean I will not answer your questions in private whenever I can.