Slow Android emulators to test Android programs may be a thing of the past on my current Windows system. I downloaded and installed Windows Subsystem for Android. It's a convenient way to test out apps you've created without having to resort to installing VirtualBox and Android x86 or using other alternatives such as Qemu or some of the very slow Android app emulators.

If you want to try out other Android apps on your Windows system, you can do that as well. It may not look like there's a wide variety of apps to choose from at first glance. Windows Subsystem for Android comes with Amazon Appstore instead of Google Play store. I've seen some reports of getting Google Play store working but it doesn't seem worth the effort and really isn't necessary. If you're just going to test your own apps, you don't need an entire app store. However, it is fairly easy to get F-Droid installed on Windows Subsystem for Android. Most of the apps from F-Droid work very well in an emulator. F-Droid had more than enough apps for my needs. Also, there are other repositories such as IzzyonDroid that can be added to F-Droid giving even more options to choose from. Finally, there are sites, such as APKPure, that will allow you to download apk files directly. Once you have the apk file, you can install the app yourself.

The basics for installing apk files in Windows Subsystem for Android follow. First, download a copy of the Google Android platform tools for Windows. adb is the program that is required from the platform tools. Start up an Android app, any Android app, in Windows Subsystem for Android. This makes sure that Windows Subsystem for Android is currently running. At the command line, type:
adb connect 127.0.0.1:58526

Once a successful connection is made, most apk files can be installed from the command line using a command similar to the following:
adb install file.apk
Substitute the actual name of the apk file for file.apk in the command.

What if you have an xapk file instead of an apk file? Rename it to a zip extension. Use a tool like unzip to extract the files in the xapk. Use the command adb install-multiple with a list of the extracted apk files.

That's all there is to it. Once that's done, you can easily install Android apps and run them on Windows. I found some actually run better on Windows than on a phone. However, some did not fit the screen well and some required Bluetooth which is not yet supported in Windows Subsystem for Android. Still, you can run quite a nice selection of apps and you can use it to test your own Android apps as you develop them.
I just got used to VirtualBox and ended up having to switch to QEMU. VirtualBox seems to run better than QEMU. I tried to load several operating systems in QEMU that ran fine under VirtualBox and they failed. Decided to try a Debian netinst because that works well with most machines. Then I had to figure out all over again how to get files between the host and guest systems. It's harder to find documentation on what you're looking for with QEMU as compared to VirtualBox.

The first step is to download and install qemu someplace. I'm assuming it's in the path. Otherwise, you need to specify where to run it from.

Next step, create a virtual disk to install the operating system to. The following creates a 2 GB image file in raw format. You can choose other formats.

qemu-img create linuximage.img 2G

I'm using an ISO for 64 bit Linux, so I use qemu-system-x86_64. For 32 bit systems, I can use qemu-system-i386. There are options like qemu-system-i386w.exe which I was wondering about. Turns out these are for use on Windows systems. They prevent bringing up a console when as well as a window when running. However, I typically run everything from the command line, so there's no advantage to this. Windows programs running in console don't create a new console. I recommend sticking with the standard versions without the w especially if you're running from the command line or on a non-Windows system.

I downloaded a Debian netinst ISO and put it in the iso directory. This is the command I used to start QEMU so I could install Debian to the linuximage.img file.

qemu-system-x86_64 -hda linuximage.img -cdrom iso\debian-10.10.0-i386-netinst.iso -device ac97 -net nic,model=ne2k_pci -net user -rtc base=localtime -m 1G -boot order=dc -usbdevice tablet

The -m option specifies RAM and I gave it 1 Gigabyte. Once you run the command, hopefully the operating system should boot from the ISO as if it was a CD. You can then proceed to install it to linuximage.img which should appear as the first hard drive on your system. Once the system is installed, you probably want to Power Down and/or Quit QEMU.

Use the following command to boot from the image rather than running from the ISO file.

qemu-system-x86_64 -hda linuximage.img -device ac97 -net nic,model=ne2k_pci -net user -rtc base=localtime -m 1G  -boot order=c -usbdevice tablet

The -usbdevice tablet setting seems to help smooth out mouse support which didn't work well without it.

Now comes the hard part, I wanted to move files back and forth from the new system. If the files are fat32 (such as a ReactOS image, you can mount the image and read the files. That doesn't help much with operating systems that use other disk formats. You can load images as floppies or cdroms (typically read only) or add another hard drive. So, the idea was to add a second drive that was formatted using a format the host system could read. I created another image and attempted to format it in using the Guest operating system in a way that the host could read. That failed. I recommend mounting the image and letting the host operating system format it. Then, the guest operating system can be set to access it as a second drive.

To do this on Window, I used a program called ImDisk.
https://sourceforge.net/projects/imdisk-toolkit/
Latest versions of Windows are supposed to allow you to mount an image as well.

I created a new image using:
qemu-img create drive.img 2G

Once I mounted the image using ImDisk, the operating system asked if I wanted to format the image and I let it do the formatting. Then, I could access the image using QEMU. Make sure the drive is not mounted on the host system before using it with the guest system and vice versa.

qemu-system-x86_64 -hda linuximage.img -hdb drive.img -device ac97 -net nic,model=ne2k_pci -net user -rtc base=localtime -m 1G  -boot order=c -usbdevice tablet

When I tried formatting the drive using Linux in QEMU, it wanted to access the new drive as /dev/sdb1. When I just use the image created from Windows, it used /dev/sdb.

Once you've created and formatted the extra image, you can access it in your virtual operating system. If you're running Linux virtually, you'll need steps like these.

mkdir -p /mnt/data
mount -o defaults /dev/sdb /mnt/data

They needed to be performed as root or you need to get sudo working properly first. Directory creation only has to be performed once. The mount needs to be done each time you activate the operating system and want to access the image unless you add the information to auto mount it in /etc/fstab. You can also unmount the drive using umount.

Once the drive is mounted, you can move files to and from it. You can see if there's anything on the image using:
ls -l /mnt/data
Copy or move files from /mnt/data or whatever location you mount the drive at as well.

While I couldn't access an image I formatted in the guest system, I did want to go through the steps. It worked fine from within the host and was readable from there.

Install fdisk. Since I'm using fat32, I also needed to install dosfstools. I found the tools in /usr/sbin and had to run from that directory since it wasn't in my path. The commands below assume programs are in the path. They probably need to be run as root or using sudo.

fdisk -l

This shows your images so you can find their names. I set drive.img as -hdb so it shows up as /dev/sdb on a Linux system.

fdisk /dev/sdb

The fdisk program will prompt for further information.

At the fdisk command prompt, I gave it the o option. This creates a new DOS partition. The next command was n to set a partition type. I chose p for primary. I chose the default partition number 1. It brought up first and last sector options and I chose the defaults for both. At the command prompt, I chose t for partition type and gave it a hex code of b which selected W95 FAT32. At the command prompt, I selected w which wrote the changes and exited the program. From the normal command prompt, I ran the following:
mkfs.vfat -F 32 -n WINSTORAGE /dev/sdb1

This should format the image and name the image WINSTORAGE. Windows prefers upper case for disk labels.

Once done I was able to use mkdir to create a directory under /mnt to mount it. In this case it needs to be mounted as /sdb1 not not sdb. The result made an image that worked fine in the guest system but wasn't recognized on the host.

If your host system is a Linux system, it might be helpful to use a more familiar format like ext2 or ext3 instead of fat32. On the other hand, many flash drives use fat32 and most systems can read them, so it might be a useful solution as well. If you create the second image before installing the new operating system, depending on the installation process, it might recognize the extra image and incorporate it automatically. Just make sure not to reformat it when installing the operating system.

The mtools programs can be used on various operating systems and can be used with emulators and images formatted for DOS. Wondering if it could be used to format a mounted image file as fat32 on systems that don't support it natively.

I was also able to successfully create an ISO image on the host system using mkisofs and load that as a virtual CDROM on the guest.

mkisofs is available on Windows with various software. I typically installed DVDStyler and used the program it supplies. Debian and some systems typically don't supply cdrtools which contains mkisofs. Many systems use another package which emulates or gives equivalents to commands cdrtools supplies. GRML is a Debian based distribution that does offer the original cdrtools package. There are some arguments over copyright which kept cdrtools from being added to some distributions. I also found a utility that worked only on Windows that could create ISO files. It was used by some ReactOS developers. Nice thing was that it built easily from source using MinGW.

Assuming my files are in the tmp directory below the directory I'm in, I can run mkisofs with the following command to make an ISO file.
mkisofs -r -R -J -l  -o test.iso tmp

I can add the image using a command like this one.
qemu-system-x86_64 -hda linuximage.img -drive id=cdrom0,file=file,index=1,media=cdrom,file=test.iso -device ac97 -net nic,model=ne2k_pci -net user -rtc base=localtime -m 1G  -boot order=c -usbdevice tablet

Once in Linux, the cdrom can be accessed after mounting it with:
mount /media/cdrom

I've used that technique to get Debian to install successfully with QEMU. Haven't had much luck with other systems yet including other versions of Linux. I'd also like to get Androic-x86 or Bliss OS working at some point. XFDOS would be another interesting option to try.

I did finally get ReactOS running in QEMU. Reactos is tricky to load. The Reactos version used must be 0.4.14-RC or higher.

I created an image using the native QEMU format as recommended on the ReactOS site.

qemu-img create -f qcow2 reactOS.qcow2 2G

I installed ReactOS on the image by following the prompts after using this command:

qemu-system-i386 -drive if=ide,index=0,media=disk,file=reactos.qcow2 -drive if=ide,index=2,media=cdrom,file=iso\reactos-bootcd-0.4.15-dev-2847-g0ffbbab-x86-gcc-lin-dbg.iso -m 1G -device ac97 -net nic,model=ne2k_pci -net user -rtc base=localtime -usbdevice tablet -boot order=dc -serial file:reactos.log

Most of the options I picked were defaults.

After the image is formatted and the operating system is installed, power down and/or quit QEMU.

I ran the following command to complete setup after the ISO was no longer accessible from the CDROM drive. It let me set up the system.

qemu-system-i386 -drive if=ide,index=0,media=disk,file=reactos.qcow2 -drive if=ide,index=1,media=disk,file=drive.img -m 1G -device ac97 -net nic,model=ne2k_pci -net user -rtc base=localtime -usbdevice tablet -boot order=dc -serial file:reactos.log

After it's set up as desired, power down and/or quit qemu.

Now, I can run the following command to move files to and from ReactOS within QEMU using the drive.img.

qemu-system-i386 -drive if=ide,index=0,media=disk,file=reactos.qcow2 -drive if=ide,index=1,media=disk,file=drive.img -m 1G -device ac97 -net nic,model=ne2k_pci -net user -rtc base=localtime -usbdevice tablet -serial file:reactos.log

It's accessible as e:. The d: drive is still reserved for the CDROM device.

At one point when I restarted the image, it asked me to press Ctrl-Alt-Delete to get into the system. I found out you can send special keys to QEMU by pressing alt-ctrl-2 to get to a screen where you can enter commands. You can emulate keys using sendkey. I entered sendkey alt-ctrl-delete. Return to the original screen using alt-ctrl-1. This actually accomplished nothing in this case, because the screen was coming due to an error with the system, possibly the registry. I ended up having to reinstall ReactOS to fix it. Sending alt-tab this way once the system was reinstalled worked well.

ReactOS is interesting and can run some great Windows programs. However, it does crash more often than I would like. Can't help thinking a Linux system with Wine would be more stable. There are several themes, but I miss the Windows XP Silver Metallic theme. Supposedly, you can copy the .msstyle file over from a Windows XP machine to ReactOS and it should emulate the style.

Still investigating what other operating systems will run under QEMU and what commands they require.

So, that's my cheat sheet of useful QEMU commands to date. It does seem to have some advantages to VirtualBox, but so far, I haven't been able to run as many operating systems on it. You also have to decipher what to use in the command line or it may fail to run. Once you have the techniques down and the images created, it seems to work well. It seems less complicated to get files in and out than using VirtualBox Guest Additions. Unfortunately, documentation for how to accomplish it is difficult to find.
I'll be interested to see if QEMU will allow access to an extra image when running an Android operating system. VirtualBox Guest Additions typically wasn't an option for most virtual Android based operating systems. Hopefully, that's all that's needed to get a virtual operating system up in QEMU and develop/build applications natively within the guest system.
Thought I'd list some of my favorite Free, Libre and Open Source Android apps. Below is my list to date.

OpenGemmy
https://bitbucket.org/vjaka/match3/src/master/
https://play.google.com/store/apps/details?id=org.opengemmy
This will run on a computer too and can be fun to play.

MeerKat Challenge
https://f-droid.org/en/packages/eu.johncasson.meerkatchallenge/
Whack-a-mole style game.

Taponium
https://f-droid.org/en/packages/wsdfhjxc.taponium/
Another whack-a-mole style game.

Mastermindy
https://f-droid.org/en/packages/eth.matteljay.mastermindy/
Mastermind game.

Candy Memory
https://f-droid.org/en/packages/se.tube42.kidsmem.android/
Match game.

9P
https://f-droid.org/en/packages/se.tube42.p9.android/
Word game.

Cards with Cats
https://f-droid.org/packages/com.dozingcatsoftware.cardswithcats/
Spades and Hearts card games.

Vector Pinball
https://f-droid.org/en/packages/com.dozingcatsoftware.bouncy/
Doesn't always load, but it's an interesting game once you get the settings to where you're comfortable with it.

Planes Android
https://f-droid.org/en/packages/com.planes.android/
Battleship-like game.

Alex Games
https://f-droid.org/en/packages/net.alexbarry.alexgames/
Game collection.

Android Nougat Easter Egg
https://play.google.com/store/apps/details?id=com.covertbagel.neko
https://github.com/chris-blay/AndroidNougatEasterEgg
There is an Easter egg program on Android Neko. While looking through the Android source code, I ran across mention of cats and started wondering what the code was for. Looked it up online and found out there was a hidden cat game on Android Neko devices. Someone modified the game and made it available for other versions of Android. Collecting and naming cats can be a lot of fun.

Interlinear Bible
https://github.com/stefankmitph/hiot

Planisphere
https://f-droid.org/en/packages/org.tengel.planisphere/

Sky Map
https://f-droid.org/en/packages/com.google.android.stardroid/

Medito
https://meditofoundation.org/
Free Meditation app

Mindfulness Meditations
https://f-droid.org/en/packages/biz.binarysolutions.mindfulnessmeditation/
Another free meditation app

Dialer2
https://f-droid.org/en/packages/org.dnaq.dialer2/
Useful if you want a simple dialer program.

I also converted drak_klondike and xfireworks to run on Android. I think xfireworks is my favorite app followed by OpenGemmy and MeerKat Challenge.
Here are some of my favorite health related programs. The ergonomic programs are useful if you're spending long hours in front of your computer. The recipe and nutrition software can be used to improve your nutrition.

Ergonomic software

Workrave - available for Windows and Linux/POSIX operating systems
http://www.workrave.org/
https://portableapps.com/apps/utilities/workrave_portable

PrevRSI - available for Windows
http://prevrsi.sourceforge.net/

Xwrits - available for Linux/POSIX operating systems, X Windows based without a lot of GUI dependency libraries
http://www.lcdf.org/~eddietwo/xwrits/

Eyes' Thanks - available on Windows and other Qt supported platforms
https://github.com/yalov/eyes-thanks

Resto - available on Windows and other Qt supported platforms
https://github.com/Justyna-JustCode/Resto

RSIBreak - available on Linux and other KDE supported platforms
https://userbase.kde.org/RSIBreak

Gnome Break Timer - available on Linux and other GNOME supported platforms
https://gitlab.gnome.org/GNOME/gnome-break-timer/

Safe Eyes - available for POSIX compatible systems
http://slgobinath.github.io/SafeEyes/

Enso Retreat - available on Windows
https://github.com/GChristensen/retreat

Eyes Guard - available on Windows
https://github.com/avestura/EyesGuard

RestStop - available on Windows
https://gazugafan.github.io/RestStop/

WristSaver - available for Mac OSX
https://sourceforge.net/projects/wristsaver/

Stretchly - available on Windows, Linux, FreeBSD, Mac OSX and anywhere else Electron will run
https://github.com/hovancik/stretchly

BreakTimer - available on Windows, Linux, Mac OSX and Electron supported platforms
https://github.com/tom-james-watson/breaktimer-app

wnr - available on Windows, Linux, Mac OSX and Electron supported platforms
https://github.com/RoderickQiu/wnr

Chime - available on Mac OSX and Electron supported platforms
https://github.com/erdogany/chime

Aktivpause to Go - break reminder with exercises for Android
https://apt.izzysoft.de/fdroid/index/apk/org.secuso.aktivpause

Pausing Healthy - break reminder with exercises for Android
https://f-droid.org/en/packages/org.secuso.privacyfriendlypausinghealthily/

Mindfulness at the Computer is a breathing reminder - available for Windows, Linux, Mac OSX
https://sourceforge.net/projects/mindfulness-at-the-computer/

Breathing - available for Linux
https://github.com/SeaDve/Breathing

Breathe - available for Pebble
https://github.com/aaronhktan/exhale

Brethap - breathing app for Android
https://f-droid.org/en/packages/com.jithware.brethap/

Breathly - breathing app for Android
https://f-droid.org/en/packages/com.mmazzarolo.breathly/

Medito - meditation app for Android
https://apt.izzysoft.de/fdroid/index/apk/meditofoundation.medito

Mindfulness Meditation - meditation app for Android
https://f-droid.org/en/packages/biz.binarysolutions.mindfulnessmeditation/

Be Well - heart rate monitor
https://apt.izzysoft.de/fdroid/index/apk/com.bewell.lite

Virtual Magnifying Glass - available for Windows, Linux, FreeBSD, Mac OSX
https://sourceforge.net/projects/magnifier/
https://portableapps.com/apps/accessibility/virtual_magnifying_glass_portable

Adapt screen brightness/temperature on Windows and POSIX systems with Gammy:
https://github.com/Fushko/gammy
https://github.com/Fushko/gummy

Changes the color temperature of your monitor to better match that of your surroundings on Linux and Windows systems:
https://sourceforge.net/projects/redshiftgui/

Adjust colors of screen based on time of day on POSIX compatible systems:
https://wiki.archlinux.org/index.php/Redshift

Adjust colors of screen based on time of day on POSIX compatible systems:
https://github.com/maandree/blueshift

Iris Floss is a blue light reduction program for X11:
https://github.com/yurrriq/iris-floss

Gammastep adjusts screen colors for Linux systems:
https://gitlab.com/chinstrap/gammastep

Red Moon for Android:
https://github.com/LibreShift/red-moon

Fake Dawn is a gradual light alarm for Android:
https://f-droid.org/en/packages/org.balau.fakedawn/

Fall Detector for Android:
https://github.com/altermarkive/experimental-fall-detector-android-app
https://apt.izzysoft.de/fdroid/index/apk/altermarkive.guardian

Nutrition and Recipe software (cross-platform)

NUT - Nutrition software
https://sourceforge.net/projects/nut/

Gourmet - Recipe Manager
http://thinkle.github.io/gourmet/

EnRecipes - Offline recipe manager for Android.
https://f-droid.org/packages/com.vishnuraghav.EnRecipes/

Waistline - Libre calorie counter and weight tracker for Android built with Cordova
https://github.com/davidhealey/waistline
Was recently commenting on a forum about how few Open Source alternatives there are for Android devices. The Free Software Foundation even had a wiki page about how development for mobile devices was a priority. However, when I wrote to them on the subject, they didn't bother to acknowledge or answer my e-mail (until just recently, two years later).

There are some good Open Source projects out there for Android. However, many commercial apps and even the Open Source applications appear to be trying to reinvent the wheel. They're redeveloping concepts that have already been done in other languages and with other build systems. Worse yet, they're making a lot of the same programming mistakes of earlier projects without learning from them.

I truly believe that taste varies widely as far as what people like in a program or application. To one person, an expensive commercial office suite or graphics program is a highly necessary tool. To someone else, it's too complicated and tries to do too much at once. What one person feels is a compelling, action-packed and exciting video game can be boring and mindless to another person. With that said, I'm sure my taste in programs does not match what many others are looking for. Personally, I do find the Open Source applications I ported from other operating systems to Android to be among my favorite Android apps. I'd love to find to locate other projects that are working on similar ports of popular Open Source applications.

Since I'm primarily interested in C/C++ development at this time and I've always been an advocate of cross-platform programming, I've been searching for good references and examples of C/C++ application development for Android that do not lock the developer into using a specific IDE or build system. Most books on Android development are for Java or Kotlin. There are even a good number that use web apps or web development languages likes JavaScript/HTML/CSS including projects like PhoneGap, ReactNative, NativeScript, etc.

There are very few books on NDK development for Android. All of the books I've found so far detail development with Android Studio (or Eclipse for older books that have not been updated in a while). SDL is typically mentioned with NDK development even though there are other development libraries that work with Android. Some don't mention libraries like SDL at all, but then you're limited to examples similar to those provided by Google or very basic applications. There are a few interesting articles on porting applications from other operating systems to mobile devices, but I've found no books that specialize or give much in the way of advice in this area.

I've been considering writing an e-book that fills in the gaps and gives examples of how to develop cross-platform applications that easily port to Android and use NDK plus a more a standard tool-chain. The only thing holding me back is the idea that there would probably be very few developers other than myself interested in this sort of thing. Obviously groups like the FSF weren't interested or they would have taken the time to answer an e-mail. If there is interest from other developers on sharing this type of information, please let me know.

I mentioned on a forum how much I'd like to see a list of available Open Source applications for Android (preferably cross-platform portable applications written in languages other than Java). It would be nice to see what others have done and get ideas for development based on them. Since I really haven't been able to find a resource like that, I'm putting together the start of such a resource here:

C/C++ SDL based apps ported to Android:
https://github.com/pelya/commandergenius
https://sourceforge.net/projects/libsdl-android/files/apk/
Terminal emulator in Java and cli and ncurses based applications ported from other systems:
https://github.com/termux/termux-packages/tree/master/packages
VLC for Android:
https://www.videolan.org/vlc/download-android.html
List of Open Source Android applications. Includes information on language the program was written in. While there aren't a lot of C/C++ applications listed there are some:
https://github.com/pcqpcq/open-source-android-apps
Similar list for iOS Apps:
https://github.com/dkhamsing/open-source-ios-apps
Another list of Open Source applications (unfortunately no indication of the languages they were written in or the build systems required):
https://en.wikipedia.org/wiki/List_of_free_and_open-source_Android_applications
Project for mobile devices (mainly Qt based):
https://ubports.com/
Repository and app store for Open Source apps (mainly Java apps):
https://f-droid.org/en/about/
CrystaX NDK provides and alternative to Google's NDK:
https://www.crystax.net/android/ndk

If you know of other Open Source C/C++ software for Android, please advise and I'll add it to the list.


Here are a couple of interesting articles on Android. The first is a list of alternatives to Google's online app store for Android:
https://android.izzysoft.de/articles/named/android_markets_safe_to_use
The next article is about how to make Android a little more Open Source friendly by stripping it of some of the more proprietary apps:
https://android.izzysoft.de/articles/named/android-without-google-5

Another site with information on removing proprietary libraries from Android devices:
https://microg.org/
Some of the C graphics libraries are great, but I've yet to find a simple GUI that makes it easy to port some older BASIC programs that I want to be able to keep working with. I've created several iterations of my own GUI library, but have never been satisfied with the results. That's the main reason I keep investigating cross-platform GUIs, to see if someone's found a better way to do it. Of the various designs, the ideas behind the immediate mode GUIs seem the most useful for the type of programs I'm targeting. However, I can't seem to find one GUI library that provides a simple way to do what I want. So, I've decided to revisit my old GUI library designs but eliminate some of the framework constraints and some of the object oriented elements. Instead, I'm looking at a more procedural approach that uses concepts from immediate mode GUIs.

Even though I'm avoiding popular C/C++ GUI libraries, I'm not starting completely from scratch and writing everything myself. There are plenty of good graphics libraries that are very portable and make a great basic starting point for a GUI. One of the libraries I've been very impressed with is SDL. It makes a great base for porting software. I've also done a lot of work with PicoGL (a TinyGL fork). It's a convenient way to make OpenGL more portable and avoid some of the version issues. It works on low resource platforms such as handheld devices that don't have high performance video driver support. I've often found OpenGL and Mesa slow on older computers and low resource systems. PicoGL provides very good performance on these types of systems. While using Win32 is not as portable as I would like, it's not that hard to get an OpenGL window up and running on Win32. That easily allows switching between Win32/OpenGL and SDL (1.2.15 or SDL 2.x)/PicoGL. SDL can work on a variety of platforms and PicoGL can work with SDL or with other options such as nano-x, X11 or vesa framebuffer. It shouldn't be too hard to take the output from PicoGL to use with the Android bitmap API either. Another possible option for a backend is Allegro. Like SDL, it works on a variety of platforms. It would be nice to switch between SDL and Allegro as backends depending on which works best for a particular platform without needing to redesign an entire application.

The PDCurses/ncurses API provides a standard way to create console based programs that work well on a variety of platforms from DOS to Windows to FreeBSD to Linux. However, it provides only text support and no real graphics support. While it's great for porting programs written to work with it, I don't think it's the best option to use as a GUI backend. I recently came across TinyCurses which provides a subset of the API and uses SDL as a backend. PDCurses also offers SDL as a backend option. I couldn't help thinking, once a decent GUI design was finalized, it wouldn't be too hard to provide a subset of functionality similar to PDCurses/ncurses. That would allow for easy porting of some PDCurses/ncurses based applications to any platform the GUI library works on.

So, why not just use OpenGL as the backend to design a GUI library? After considering the pros and cons, I decided I don't want to be tied specifically to OpenGL as an API for 2D graphics. While it's very popular and available on several platforms, the changes from a fixed function pipeline to a programmable pipeline with its own shading language make it hard to port programs from one version to another. PicoGL makes use of old fixed function pipeline concepts. Windows OpenGL also uses the older design. Mobile devices and WebGL make use of the newer concepts and the ability to harness the GPU to do more processing. Many developers seem to be abandoning the older concepts and embracing the new programmable pipeline design. However, that leaves some nice older applications that were designed for earlier versions of OpenGL that won't port easily to the newer versions. They might require a complete redesign and rewrite. Using PicoGL is one way to make it easier to port such applications. It can do software rendering to a bitmap which can then use more modern methods (including later versions of OpenGL or SDL 2.x) to transfer the bitmap to the screen. While the idea of using OpenGL as the portable backend for a GUI library sounds good, dealing with version differences and what versions may be available on which platforms does not make it the best option for a complete cross-platform portable solution. Instead, I prefer the concept of being able to switch out backends to use what works well on a particular platform. The GUI library should encapsulate the rendering as much as possible to avoid needing to rewrite applications in order to switch to another backend.

On the other hand, many GUI libraries and some other rendering libraries (such as SDL) offer ways to interoperate with a graphics library like OpenGL. While I want my GUI library code to be cross-platform, I don't want to limit a developer to using just that API. If a programmer wants to use OpenGL or SDL2_gfx or some other library to handle 2D/3D graphics, I'd like the GUI to be able to interoperate with that choice. It would mean that the resulting application would be less portable. However, if an application is already designed to utilize SDL2_gfx, OpenGL or some other library that could work compatibly with the GUI library, it could make adding some GUI functionality to an existing application much easier.

I definitely know what I'm looking for in a cross-platform GUI. I want a simple, portable way to get text, menus, forms, file/directory picker dialog functionality to the screen. I'd like to make use of Freetype fonts. I want an internationalized way to display text and for users to input text. The text strings will probably involve a library such as gettext. I want the options to use keyboard input for those of us who prefer keyboard commands to get their work done and mouse/touchscreen input for devices such as mobile phones where a real keyboard may not be available. I need to be able to access graphics and audio information from a file system or from a zipped file (such as .apk file on Android). I don't care if the look and feel matches what's in style for a particular device or operating system. I just want it to be user-friendly and ergonomically designed.

If you're interested in GUI design or working on a GUI or gaming library of your own, I'd love to compare notes on the subject. Have an idea for what C library might make a good backend for a portable, cross-platform C based GUI? Let me know. Feel free to discuss design issues or other C/C++ topics on the CppDesign mailing list or contact me to compare design notes and share ideas ( http://www.distasis.com/connect.htm ).
I've been searching technical books and articles to find out more about writing programs for Android using the native development toolkit (NDK) and C/C++. Finding relevant information is extremely difficult. Most sources just say to use Android Studio (or for older articles, use Eclipse) and do not go into any details as to how things work beyond the IDE or wrapper script. It's extremely difficult to find documentation that explains what's going on underneath.

I'm working on porting some Open Source projects already written in C/C++ to Android. So, I find it extremely frustrating when the typical advice I read is to avoid the NDK and use Java (or Kotlin). References that state that usually go on to say that Java (or Kotlin) really is not that much slower than C/C++, so you would be getting no significant gain in performance by using it. That leads me to believe that there has to be some gain in performance (even if it is not what the authors deem 'significant') or the articles wouldn't be mentioning that C/C++ was considered faster in the first place. Such articles typically go on to state that it's much harder to work with the NDK and one is better off using languages recommended by Google. However, for developers who prefer C/C++ over Java or Kotlin development and who are already aware of potential pitfalls of the C/C++ languages and how best to avoid them, those developers could be far more proficient and productive using C/C++ over other options. So, why recommend avoiding the NDK and C/C++? Why not encourage developers to use the languages and tools they can leverage to their best advantage?

Speaking of using tools that developers are most productive with, I already have a cross-platform build system that greatly reduces the time I spend building and porting Open Source libraries. I wanted to be able to use my build system. However, IDEs (like Android Studio) don't integrate well with automated build systems. It took a lot of digging through articles and books on Android, but I was pleased to find out how to create a standalone tool chain to build Android C/C++ applications.

I was surprised at the lack of support for cross-platform compiling of certain Open Source libraries. It's difficult to find Android builds and patches to common Open Source libraries. Also, based on my experiences porting Open Source projects to Windows, I wonder how many Open Source library developers would welcome adding patches to make builds of their libraries for Android work out of the box. My past experience has proved that many library developers would prefer not to add support for more platforms. That means I'll probably end up adding my patches to my LM BLD scripts ( http://www.distasis.com/cpp/lmbld.htm ) rather than seeing the fixes I've submitted added in to the libraries themselves.

So, as I work my way through porting various Open Source applications to Android, I thought I'd share the few useful resources I found that help clarify how to build and share C/C++ Open Source applications on Android.

The best documentation I've located to date and the one I'd refer anyone interested in C/C++ programming for Android to is this one:
http://www.hanshq.net/command-line-android.html
It explains where to get the NDK and other needed libraries. It walks you through how to create an Android package (apk file) via the command line. It gives a good example of how to build a C application that can get a developer started.

If you're on a Linux system, you can use the package manager to download a version of Java. You'll need it to create Android packages. For Windows users, one option is to download a portable version of Java and make sure it's in your development path.
https://portableapps.com/apps/utilities/jdkportable

The Android developer web site actually has some decent information on how to create a stand-alone C/C++ toolchain. You currently need Python to create the toolchain, but they actually supply a version of Python for operating systems that don't easily offer one.
https://developer.android.com/ndk/guides/standalone_toolchain.html#selecting_your_toolchain
See also:
https://android.googlesource.com/platform/ndk/+/ics-mr0/docs/STANDALONE-TOOLCHAIN.html
http://mobilepearls.com/labs/native-android-api/ndk/docs/STANDALONE-TOOLCHAIN.html

When creating the stand-alone toolchain, you'll need to know what API you're targeting. More information on that is provided elsewhere:
https://source.android.com/setup/build-numbers
Typical choices are to target the latest if you want to use all the newest features in Android or target an early enough version that the results will work on a majority of the Android devices out there. Which version is best will change over time as the majority of users buy newer devices and new innovations are added to newer APIs. Even though you mention the API when creating the standalone toolchain, the only place the information seems to be stored is in the llvm wrapper. So, you may need to add -D__ANDROID_API__ and the API you want to support to your compiler flags.

You'll also need to decide whether you want to target 32 or 64 bit platforms. Keep in mind that 32 bit code will work on 64 bit platforms, but the reverse is not true. There seems to be better support for large file access on 64 bit platforms though. Note that Google is pushing for latest API targets and 64 bit support for projects that will submitted to the Google Play Store. You'll need to build your application for each target you wish to support. So, if you want your programs to work on Android devices with arm chips or x86 based chips, you'll need to build libraries and applications for more than one system.

Google is also moving toward unified headers so they don't have to support a version of the C and C++ header files for each API they support. Depending on what version of the NDK you're using, you may want to add --unified-headers when creating your standalone toolchain.

I find it useful to know what native C/C++ functionality/which libraries are supported for various versions/APIs of Android:
https://developer.android.com/ndk/guides/stable_apis

I thought this site had a good series of posts on how to port a SDL based application to Android:
http://blog.stuff-o-matic.com/post/2013/10/20/ASGP-s-Android-Port-Part-IV%3A-building-the-APK

If you're interested in using dynamic libraries, this site had some useful information:
https://www.andriydruk.com/post/introduction-to-c-for-android-developers/

Testing the results you built may be difficult. My experience with using MoSync to build C/C++ Android applications showed how slow testing an application with an emulator could be. If you install Android Studio, it gives the option to install Intel HAXM (hardware accelerated execution manager). This can help speed up Android emulation. You can find HAXM and more information on it at the Intel web site.

You can also use VirtualBox and an Android virtual machine image for testing.
Android-X86 ( http://www.android-x86.org/ ) can provide images that work with targets compiled for x86 machines.

Another option is to use adb (Android Debug Bridge) to test the results on an actual Android device. Now that Windows Subsystem for Android is available, you can also us it to run Android apps and use adb to side load the applications you want to test. Here are a couple of articles that give examples of how to work with adb:
http://nickdesaulniers.github.io/blog/2016/07/01/android-cli/
http://codeblog.vurdalakov.net/2016/12/build-and-run-native-c-cpp-android-apps-with-ndk.html

One thing to keep in mind if you're going to test on your own Android device is that Developer options must be activated on that device first. Here's an article on how to do that:
https://www.embarcadero.com/starthere/xe7/mobdevsetup/android/en/enabling_usb_debugging_on_an_android_device.html

You can also build or access Open Source console applications (even without turning on developer options) when you have a terminal emulator app installed on your system. This gives applications you're running in the terminal emulator (even one's you've built from source) the same rights at the terminal emulator. You can use command line or console based applications (such as those built with pdcurses/ncurses/netbsd-curses) with a terminal emulator. There are several terminal emulators available from the Google Play Store or F-Droid. Try some out and see which you like best.

One of the terminal emulator projects has a github project with information on some common Open Source library packages including commands for building and patches needed to compile. One thing to watch out for is that some of their patches are made directly to the standalone toolchain header files. If you don't have similar patches or add extra patches to the library's build script, you may not be able to compile successfully. One of these fixes is to help work-around 64 bit file handling support on 32 bit systems. Some Open Source projects don't build properly or need major work-arounds to handle this with earlier versions of the Android API for 32 bit systems. More information on how the Termux terminal emulator project builds their Open Source libraries and programs is available at their github site:
https://github.com/termux/termux-packages/tree/master/packages

Another interesting resource if you want to see how various C/C++ projects are built and what patching might be needed is this one:
https://github.com/pelya/commandergenius
It uses SDL 1.2/1.3 ported to Android and includes several Open Source libraries and several popular Open Source applications including DOSBox, Milkytracker, grafx2 and a SDL based X server.

A developer I correspond with wrote his own tutorial on how to build C/C++ applications using Allegro and Nano-X. He covers a lot of useful material about the NDK and C/C++ development including how to call Java functions from C/C++ and vice versa. He also explains how to use Allegro on Android.
https://wiki.allegro.cc/index.php?title=Running_Allegro_applications_on_Android

Libraries such as SDL, Allegro and Nano-X provide support for building GUI applications on Android. Nano-X offers a subset of X11 functions so GUIs like FLTK and WxWidgets will work. PDCurses can be used in conjunction with SDL. Applications built using any of these libraries could potentially be ported to Android. Not all C/C++ applications provide interfaces that are user friendly for Android or for smaller screens and devices that may lack physical keyboards. However, if you create a well designed, portable interface for your program, there's no reason why it shouldn't work well on Android systems as well as PCs (Linux, Windows, BSD, etc.). Here's more information on some GUI libraries that work on Android:
https://github.com/georgp24/microwindows-android-bin
https://wiki.libsdl.org/Android
http://liballeg.org/readme.html

More recently, I ran across Android Apps in C. It uses Android Studio which is a lot of overhead if you just want to build an application. Also seems to use WSL on Windows instead of direct development on Windows. Seems to use the standard android_native_app_glue code. However, there may be other tips and tricks that are useful when creating a C/C++ application for Android. The project is at:
https://github.com/cnlohr/rawdrawandroid

That's pretty much all my searches have turned up as far as resources I've found useful for building C/C++ applications targeted to Android devices. If you have other reference recommendations that explain how things actually work (rather than glossing over the details and using a GUI interface), please let me know. If you'd like to share or compare notes on patches, compiler/linker options for building various Open Source libraries and applications, I'd enjoy hearing from you. You can discuss C/C++ Android development further with me and other interested developers on the CppDesign mailing list.

June 2025

S M T W T F S
1234567
8 91011121314
15161718192021
22232425262728
2930     

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 3rd, 2025 07:15 pm
Powered by Dreamwidth Studios