Chapter 2

Configuring Your Mobile System

IN THIS CHAPTER

check Getting and using CppDroid

check Working with other mobile IDEs

check Using CppDroid to write code

check Getting CppDroid help

At one time, developers relied exclusively on desktop systems to perform useful tasks because desktops provided the required computing power. Laptops came next, but essentially a laptop is a smaller form of a desktop. Today, however, developers rely on all sorts of mobile devices to write code. Even though someone could conceivably use a smartphone for the task, the majority of this activity occurs on high-powered tablet computers. The reason relates not so much to the power, but the form factor. A tablet offers more screen real estate to see your code and observe how it works. Keeping these two goals in mind and looking at the available Integrated Development Environments (IDEs), this chapter relies on Google CppDroid to make the leap from desktop systems to Android-powered tablet systems, such as the ASUS ZenPad 3S 10.

However, you shouldn’t get the idea that CppDroid is the only game in town. You also find a description of a few other offerings in this chapter, and you can certainly try them if you like. The consistent issue with all of these offerings, though, is that they all currently lack C++ 20 support, so some book examples won’t run on your tablet at all. If you want to ensure maximum compatibility with the book’s code, procedures, and screenshots, you still need to rely on Code::Blocks running GCC.

After you get CppDroid installed, you need to know how to perform some basic tasks with it. This chapter doesn’t provide a complete tutorial on using CppDroid, which is why it also discusses how to obtain help. However, you do discover how to interact with the book’s code in this chapter, which is an essential part of the learning experience.

Obtaining CppDroid

Many IDEs are available for you to use to work with C/C++ code. However, most of them rely on the Windows, Linux, Mac OS X, and Solaris platforms (with Solaris appearing as an option far less often than the others). In addition, most of them are paid options, with Code::Blocks (http://www.codeblocks.org/) and Visual Studio Code (https://code.visualstudio.com/) being notable exceptions. However, to program on your Android device, you need an IDE that works with Android and provides some sort of cloud-based storage for the most part (PC-based IDEs use local storage). CppDroid offers a good Android-based solution that you can use in both online and offline mode without problem. Plus, the free option actually does work (but with limits; see the “Free versus paid software” sidebar for details). The following sections give you insights into working with CppDroid.

Understanding why CppDroid is such a great choice

You can find a number of C/C++ IDEs for Android in the Google Play Store. However, the choices come down to three products for most people (in order of preference):

  • CppDroid
  • C4Droid
  • CxxDroid

Remember None of these products will completely replace a desktop IDE, but CppDroid comes very close. For example, CppDroid is the only one of the three products that has built-in support for graphics. You can obtain graphics support in CxxDroid using Qt (https://www.qt.io/) and a nonstandard header, graphics.h, but this means working in a manner that doesn’t easily translate between desktop and mobile device. You can also use CxxDroid with Simple DirectMedia Layer (SDL) (https://www.libsdl.org/). C4Droid supports SDL using only a non-standard graphics.h file. You use Qt to develop business graphics software, while SDL works great for 2-D games.

If you want to develop 3-D games, you must use DirectX through Wine (https://www.androidpolice.com/2020/01/21/windows-compatibility-layer-wine-hits-v5-0-on-android/) or OpenGL (https://developer.android.com/guide/topics/graphics/opengl). There are add-ons, such as Unity (https://developer.android.com/games/develop/build-in-unity) and Unreal (https://docs.unrealengine.com/en-US/Platforms/Mobile/Android/index.html), but they actually layer on DirectX or OpenGL, so you’re still using one of these two technologies, despite using them indirectly. Using any of these products on Android is difficult, and you should plan plenty of time to integrate these APIs into your IDE.

It’s helpful to know precisely what CppDroid provides. Table 2-1 lists basic functionality, whether this functionality comes only with the paid version, and a brief overview of what you obtain with the basic functionality. As you work with CppDroid, you encounter some deficiencies, especially when running the standardized code in this book, but you also discover that you can run a lot of it without any sort of modification.

TABLE 2-1: CppDroid Features

Feature

Paid Only

Description

Add-ons manager

Even though CppDroid comes with all the basics you need, at some point you’ll want to go beyond the basics, which is where add-ons come into play. An add-ons manager makes the task of knowing what you need to add a lot easier. Plus, you can easily get rid of items that you no longer need.

Auto indentation

Trying to keep your code readable means using indentation to see things like the start and finish of an if statement or other code block. Having configurable auto indentation means that you can choose how the code is indented, but you don’t have to indent it manually.

Auto pairing

Locating a missing parenthesis or brace can drive you slowly nuts. Configurable auto pairing means that you determine how elements are paired, but the IDE helps you ensure that nothing needed to compile the code is missing.

Auto updates

Getting the latest software updates helps you write code that works with the newest trends in C/C++ development. You also get bug fixes, which is essential for the reliability and security of the code you create.

C/C++ code examples included

X

Because working with tablet-based IDEs can sometimes come with quirks, having a full set of C/C++ code examples is essential. These examples show how to work around the quirks so that you can execute your C/C++ code with just a few small modifications when necessary.

C++ tutorial and learn guide included

X

If you plan to work offline, it’s essential to have a tutorial and learning guide for those times when you almost, but not quite, remember how to perform a particular task. Of course, you’ll also want to keep this book handy.

Code complete

X

Automatically suggests how to complete statements that you type based on previous content. This feature reduces potential typos and makes you considerably more efficient, especially when working on the tiny keyboards found in tablets.

Compile C/C++ code

In some cases, such as when working with a web-based IDE, the C++ code you create is interpreted by ROOT (see https://en.wikitolearn.org/ROOT_for_beginners for more information about ROOT). Some tablet IDEs also require ROOT, but with CppDroid you get fully compiled C/C++ code output instead.

Dropbox support

X

Sharing your code with others is a lot easier when you have Dropbox support.

File and tutorial navigator

This feature provides an index into the documentation to tell you about C/C++ code constructs, including variables and methods.

Google Drive support

X

Working from anywhere on a single piece of code means having access to that code from every environment you use. If your desktop system also supports Google Drive, you can switch between your desktop and tablet as the need arises.

Portrait/landscape UI

A tablet presents a constrained screen real estate environment. When an IDE forces you to use it in landscape mode only, you often see the IDE informational panes at the expense of seeing the code. Working in portrait mode lets you ignore most of the IDE panes while focusing on the code.

Problem fix suggestions

X

You get suggestions for a variety of coding issues, even if those issues may not necessarily result in a compilation error.

Real-time diagnostics (warnings and errors)

X

Real-time diagnostics enable you to find certain classes of errors in your code without having to compile it. The IDE monitors what you type and can point out issues like typos without compilation, which saves considerable time.

Smart syntax highlighting

Highlighting makes your code stand out so that you can see things like variables and keywords more easily.

Static analysis

X

Static analysis helps locate truly difficult-to-find bugs that include: memory leaks, mismatching allocation and deallocation, uninitialized variables usage, and array index out-of-bounds errors.

Theme-based code syntax highlighting

X

Themes let you highlight code syntax in a manner that makes sense to you. If you have visual problems, using themes can turn a difficult viewing experience into one that works well with your vision. The use of themes means that no one is stuck using a particular theme to highlight syntax; you see it the way that works best for you.

Works offline

The ability to work without an Internet connection means that you gain flexibility in where you can work. However, it also means that you must have access to everything you need as part of the local installation, which is something that CppDroid provides at the expense of additional local storage use.

Getting your copy of CppDroid

You obtain CppDroid from the Google App Store by searching for CppDroid. Unfortunately, it doesn’t support every version of Android, so you may not actually see it if your device doesn’t support it. Figure 2-1 shows how the page appears when you find it. To obtain a copy, all you need to do is tap Install.

Snapshot of locating CppDroid in the Google Play Store.

FIGURE 2-1: Locating CppDroid in the Google Play Store.

Ensuring you get a good install

After the CppDroid app installs on your tablet, you see the Open button as usual. However, instead of opening the app, you see something like the view in Figure 2-2. To work offline, CppDroid needs to install a number of libraries on your system. This process can take a while, so just wait for it to complete.

Snapshot of loading the CppDroid libraries for offline use.

FIGURE 2-2: Loading the CppDroid libraries for offline use.

Considering Other Alternatives

You aren’t limited to working with CppDroid, even though it’s the tablet IDE used for the book. Most tablet IDEs will let you perform a basic set of tasks that will work well for the majority of the book examples. The only time you’ll encounter difficulty is when working with examples that use new C++ features, rely on graphics in some way, or employ standard features not found in the tablet IDE. One of the advantages of these alternatives is that they might support your device when CppDroid doesn’t. The following sections tell you about the best alternatives that provide maximum compatibility with the book examples.

Working with C4Droid

C4Droid has many of the same features as CppDroid. For example, it compiles your C/C++ code, so you don’t need ROOT support. However, you can use it if desired. As with CppDroid, the app targets the educational market, but C4Droid doesn’t enjoy the strong community support that CppDroid does (see the article at https://www.androidrank.org/compare/c4droid_c_c_compiler_ide/cppdroid_c_c_ide/com.n0n3m4.droidc/name.antonsmirnov.android.cppdroid for details). In contrast to CppDroid, no free version of C4Droid exists, but when compared to the price charged for most desktop IDEs, C4Droid is a bargain.

Remember Beside the graphics limitations noted earlier in the chapter, C4Droid has some other limits as well. The most important of these is that it currently supports only C++ 11, which means that any newer examples in the book won’t run on it. You also need to download and separately install more products to get a fully functional IDE. The limited number of examples can also be a problem. Because the tablet environment can be different from working on the desktop, having a great list of examples can really help.

Getting multiple language support with AIDE

If you’re looking for a single IDE that can do everything you need on your tablet, Android IDE (AIDE) (https://www.android-ide.com/) might be what you need. Unlike the other IDEs listed in this chapter, this one works with a slew of languages, including Java, C/C++, HTML5, CSS, and JavaScript. AIDE is also Android Studio and Eclipse compatible (limited to API level 27), so if you plan to create Android apps using a language such as Java, this might be the right choice for you. (Unfortunately, Google is focusing on the Kotlin language for Android development and has no plans to add Kotlin support to AIDE now.)

However, with such a flexible range of features comes complexity, which seems to be the major criticism of AIDE. The well-designed tutorials tend to help a little, but obviously not enough for a novice developer. Many users also complain that there is a plug-in for every need and all the plug-ins are paid, so this IDE can nickel-and-dime you to death.

Remember The C/C++ language support for AIDE comes from the Android Java C++ APK 3.2, which means that you can expect differences in support from the GNU Compiler Collection (GCC) used with Code::Blocks for the desktop application in this book. You may find that some examples won’t work properly because of these differences, but all the simple (earlier) examples will work fine.

Using web-based IDEs

You can use a web-based IDE from any device, including your desktop, so in some cases, they represent the best in terms of device compatibility. A web-based IDE also provides an interpreted environment through ROOT in most cases. Consequently, when learning to develop apps in C/C++, you get instant feedback, which can save considerable time. As shown in Figure 2-3, the web-based offerings also tend to provide a simple interface that allows you to get right to work.

The example in Figure 2-3 is JDoodle (https://www.jdoodle.com/online-compiler-c++17/), which is one of the best C/C++ online offerings. This particular online IDE supports 72 programming languages. How well it supports all of them depends on the interpreter used. For the most part, you find that the JDoodle IDE provides an acceptable method of working with the code in the book. Because it also supports C++ 17, you can also run more of the examples than you can using a C/C++ app.

Snapshot of the web-based IDEs tend to provide a very simple interface.

FIGURE 2-3: Web-based IDEs tend to provide a very simple interface.

Remember The problem with every one of the web-based IDEs is that you must use them online. In addition, there is a very good chance you won’t be able to save your code, so they’re mostly useful for experimentation and not long-term learning. However, even with these issues, here are some of the web-based IDEs you might consider as replacements for CppDroid in addition to JDoodle:

Touring the Essential CppDroid Features

After you have CppDroid downloaded, you want to begin working with it. The following sections get you started with the basic features you need to work with the examples in this book. However, the IDE provides a lot more functionality than you find here, so spending time with the various examples and tutorials is a good idea as well.

Getting started with CppDroid

When the libraries are finally loaded, you see a screen similar to the one shown in Figure 2-4. The top left of this screen displays the name of the file (which you can change if you want). The top right contains buttons to Save, Compile, and Run your app.

Along the bottom of the screen, you see the current phase of working with your code:

  • Diagnostics: Shows errors that occur in your typing.
  • Analysis: Outputs the results of a compilation.
  • Output: Displays the output from your app.
Snapshot of accessing the basic CppDroid user interface features.

FIGURE 2-4: Accessing the basic CppDroid user interface features.

Snapshot of using the menu to locate the CppDroid features and options. Tap the ellipsis button in the top-right corner and you see the menu shown in Figure 2-5. To obtain full functionality from CppDroid, you need to tap the Purchase entry and select the optional features you want to buy (see Table 2-1 for details). Choosing Premium will give you access to all the extra features at a reduced cost.

image

FIGURE 2-5: Use the menu to locate the CppDroid features and options.

Accessing an example

CppDroid comes with both examples and tutorials you can use to learn more about the IDE and C/C++ in general. The tutorials work much like the examples—just with more content. To access the Hello World example, choose … ⇒  Project ⇒  Examples ⇒  C++ ⇒  For Beginners ⇒  HelloWorld. The display will now contain the code shown in Figure 2-6.

Snapshot of loading an example provides a quick way to see code in action.

FIGURE 2-6: Loading an example provides a quick way to see code in action.

To compile this code, you touch the lightning icon. After it has compiled, you can run it by tapping the right-pointing arrow. The display will change to show the output. To clear the output, tap the left-pointing arrow in the upper left corner of the display.

Working with a simple online project

You can place the source code for this book on your Google Drive or Dropbox. Of course, you’ll still need some method of accessing it. The following steps assume that you use Google Drive, but they also work with Dropbox. (When working with Dropbox, you place the code in the Dropbox\Apps\CppDroid folder.)

  1. Choose … ⇒  Project ⇒  Open ⇒  From Google Drive.

    You may have to log in at this point. After you log in, you may see a dialog box like the one shown in Figure 2-7 in which you give permission to access Google Drive from CppDroid. Tap Allow to allow the access. (This is a one-time step.)

  2. Locate the folder containing the code you want to access.

    You see one or more .cpp files. For example, when working with the book’s source code, you might choose the BookI\Chapter03\SayHello folder.

  3. Highlight the file you want to open and then tap Select.

    CppDroid opens the file for you. Figure 2-8 shows an example of the HelloWorld.cpp file for Book 1, Chapter 3.

At this point, you can compile and run your application just as if you used Code::Blocks. The only difference is that you’re doing it on your tablet.

Snapshot of giving permission to access the Google Drive.

FIGURE 2-7: Give permission to access your Google Drive.

Snapshot of the file which is available for use with local copy of CppDroid.

FIGURE 2-8: The file is available for use with your local copy of CppDroid.

Accessing your source code

To begin creating a new source code file, you choose … ⇒  File ⇒  New. When you create a new file, CppDroid automatically gives it a default name. You can change the name by choosing … ⇒  File ⇒  Rename. A single file can be part of a project, but you can also make a single file the entire project. For example, a Hello World app would consist of a single file.

You can store your source code locally, on Google Drive, or on Dropbox. When working online, the process is the same as when working with online source as described in the “Working with a simple online project” section of the chapter. The following list tells how you can store your source code locally to make it available at all times.

  • To create a new project: Choose … ⇒  Project ⇒  New. When you see the New Project dialog box shown in Figure 2-9, type a project name and then tap either Create C Project or Create C++ Project.
  • To open an existing project: Choose … ⇒  Project ⇒  Open, select one of the project sources: Recent, From Device, From Dropbox, or From Google Drive, and then select the project you want to open.
  • To save an existing project: Choose … ⇒  Project⇒  Save or … ⇒  Project ⇒  Save As. When using Save As, you can choose a different location, such as Dropbox or Google Drive, and a new project name.
  • To close an existing project: Choose … ⇒  Project ⇒  Close. CppDroid automatically saves your project to the default location with the current name if you haven’t done so.
  • To delete an existing project: Choose … ⇒  Project ⇒  Delete while the project is open for editing.
Snapshot of defining a new local project.

FIGURE 2-9: Define a new local project.

Considering differences with the desktop environment

When you compare CppDroid with Code::Blocks, you find that CppDroid provides a much simpler interface with far fewer features. It works as a means to write code while on the road and for testing simple applications. You can’t use CppDroid as a full-fledged development environment simply because it doesn’t contain the features that such an environment provides, especially when it comes to things like debugging. In fact, the limits clearly present themselves on the Actions menu shown in Figure 2-10, where CppDroid limits you to completing code, performing analysis, compiling, and running the code with or without arguments.

Snapshot of the list of actions in CppDroid are somewhat limited.

FIGURE 2-10: The list of actions in CppDroid is somewhat limited.

Tip Even with the limits, you can easily work with any example in the book that consists of a single file or doesn’t rely on the latest C++ functionality. You need the desktop environment, however, to make most multifile examples work and to perform complex tasks. By working through the examples in this book on your tablet, you gain insights into what is and isn’t possible for CppDroid, giving you another useful tool that you can use to code wherever and whenever you want.

Obtaining CppDroid Help

No matter how simple and straightforward the interface, no matter how many examples and tutorials supplied, every app will generate some number of questions. Consequently, you need access to help at some point to make things work. The following sections offer a quick overview of the help available for CppDroid.

Working with the Help documentation

The oddest part about working with CppDroid is that there isn’t an actual Help file. When you open the … ⇒  Help menu, you see the options shown in Figure 2-11.

Snapshot of a list of help sources for CppDroid.

FIGURE 2-11: A list of Help sources for CppDroid.

The CppDroid blog contains the latest entries by the app author. What the blog provides is a running commentary of the problems that the developer is seeing and what is being done to fix them. You also see side posts on topics such as the number of people currently using CppDroid and other projects that the author is contemplating. Even so, this is where you go when you have a problem with the product and hope that the developer is addressing it. Figure 2-12 shows an example of the sort of blog posts you see.

Snapshot of the developer uses blog posts to help you find bug fixes.

FIGURE 2-12: The developer uses blog posts to help you find bug fixes.

Tip When you find no apparent help for a particular problem, you choose the Post Feedback option on the Help menu to send the developer an email. Oddly enough, you may find that you have a hard time getting through with anything other than Gmail.

Getting community support

You can find a lot of articles about CppDroid online on various websites. The articles provide you with insights on how to use CppDroid and often answer questions that users have about it. In addition, you can find help using CppDroid at these sites:

Tip You might find additional locations for CppDroid information online. If you find one of these places and it seems to have good, consistent information, please let me know at John@JohnMuellerBooks.com so that I can share the information with other readers.

Using the free examples

The free examples often provide you with insights into how CppDroid works. For example, you may wonder how the static analysis feature works. To see a demonstration of static analysis, choose … ⇒  Project ⇒  Examples ⇒  C++ ⇒  For Developers ⇒  Static Analysis. After the file loads, choose … ⇒  Actions ⇒  Analyze. Figure 2-13 shows the results.

Snapshot of using an example to see how the static analysis feature works.

FIGURE 2-13: Use an example to see how the static analysis feature works.

Notice that the output shows various problems with the code, such as the printf format string requires 2 parameters, but 3 are given at line 43, column 0 near the bottom of the screen. The output helps you locate problems with your code and fix them before you compile it.

Accessing the tutorials

The tutorials provide a multistep process for working with C++ within CppDroid. When you choose … ⇒  Project⇒  Tutorials ⇒  C++ ⇒  For Beginners, you see two tutorial options:

  • CPlusPlus.com C++ Tutorial
  • LearnCpp.com C++ Tutorial

Both tutorials give you help with getting over the C++ learning curve from within the CppDroid environment. The IDE changes to show a tutorial outline in the left pane and the associated text in the right, as shown in Figure 2-14. You work directly from within the CppDroid environment, which means that you can better understand how CppDroid works when you finish.

Snapshot of the tutorials that take you through basic processes within CppDroid.

FIGURE 2-14: The tutorials take you through basic processes within CppDroid.