Building a Ti Mobile App: GrillTime, part 4

Let’s put some final polish on our app so that it could be distributed
in the store.

Android: application restart is required

The bane of Titanium developers everywhere, this nasty little message
comes up when you launch your app from the post-install dialog. While it’s
all harmless, and doesn’t actually indicate that your app has crashed, it
sounds an awful lot like a crash alert. Not a nice way for a user to
get a good first impression of your app.

Luckily, recent versions of Titanium provide a fix for this problem. Just
add this to tiapp.xml:

I hope in the near term this will be a default behavior for all Titanium-built
android apps. Even though the fix is perfectly good, it’s not immediately obvious
to new developers, so they may struggle unnecessarily with this issue.

Android: allowing installation on SD cards

While GrillTime is a simple app, it ships with a lot of heavy graphics,
due to the photography I selected for the backgrounds. So it would be
nice for the user to be able to install the app onto an external storage
card if his device has one.

Just add this to tiapp.xml:

<manifest android:installLocation=”auto”>

By default, your manifest will not specify anything for android:installLocation.
According to the android documentation,
not specifying anything for android:installLocation
will limit the app to installation on internal storage.

Specifying “auto” will allow the user to move the app to external storage if
he wishes to do so.

Disable analytics

In a free app like this, I have no need for analytics, and there’s no point in
having the user’s device making network requests for a grill timer, so I disabled
analytics by setting this value in tiapp.xml:

Android: target a newer SDK for Holo theme

I really like the look of the android 4 UI. I thought it would be
nice to allow my app to use that UI style when it is running on android 4.

You can add this to tiapp.xml:

Here are two screenshots of the app running on android 4, the first
with no explicit targetSdkVersion, and the second with a targetSdkVersion of 11:

Unfortunately, I found that with the Holo look and feel, my tab icons were
gone. This is a known issue
in Titanium. So I ended up removing the targetSdkVersion.

Android: minimal permissions

By default, my app is asking for a lot of permissions on android:

Since there’s no good reason that a grill timer would need to know
the user’s location or use the network, this could cause a user to
mistrust the app. It is best to reduce the requested permissions to
the bare minimum required by the app.

At first, I suspected that the permissions were due to the fact that
analytics are enabled by default. However, disabling analytics did
not change anything. The app installer was still asking for all of
those permissions.

I discovered that you have to use a custom AndroidManifest.xml. This is
not the most convenient thing to do, but it’s not hard to set up. Build
your app once for android, then grab the resulting AndroidManifest.xml
from PROJECTDIR/build/android and put it in PROJECTDIR/platform/android
(create the folder if it doesn’t already exist).

Now edit the new copy of AndroidManifest.xml to remove unwanted permissions.
By default, I had these:

(note that Titanium inserts most of these by default in every app;
I added VIBRATE and WAKE_LOCK explicitly in the tiapp.xml because my
app needs them).

I was able to reduce the list down to the two permissions I need:

Now when you install the app, it comes up with a much less scary list:

Updating the SDK

As long as I was cleaning up the app, I figured I might as well update to the
latest Titanium SDK. So I updated to 3.0.0.

I didn’t know this until later, but
3.0.0 made major changes to TabGroups — they are now part of an Action Bar.
Support for the Action Bar is very exciting in its own right, but my app doesn’t
really need an Action Bar, and I couldn’t figure out how to minimize it. So
it left a little “title bar” area above my tabs that serves no function. It
wasn’t too bad in the pre-Holo look and feel, but it looked even worse with
a Holo theme. See below for a full rundown of all the TabGroup look-and-feel

I ended up reverting to 2.1.4 to avoid having the useless little title bar
up top on android builds.

TabGroup insanity

I went down a crazy rabbit hole with the TabGroup and the Action Bar. My first step
was to change to Titanium SDK 3.0.0, which unbeknownst to me introduced a major change
to the TabGroup; the TabGroup is now paired with an Action Bar. This is an exciting
change, but not important to this app. For GrillTime, it has the net effect of putting
a small “title bar” at the top of the screen. I didn’t notice that right away.

I then set the target android SDK to 11 to access the Holo look. I saw right away that the
icons on the tabs were gone. But I left the SDK setting in place for the time being

I then worked on the permissions issue, which required that I put a custom
AndroidManifest.xml file in platform/android. So far, so good.

After taking a close look at the tabs, I noticed the Action Bar (well, I didn’t know
what it *was*, but I didn’t want it there). I also decided that the Holo look wasn’t
worth losing the icons. I thought that the Action Bar came with my target android
SDK choice. I didn’t realize it came from my choice to use Titanium SDK 3.0.0.

So here was my biggest mistake: I just commented out the element in the
AndroidManifest.xml file. I had forgotten that when Titanium generates the
AndroidManifest.xml file, it puts this in the file:

By removing it entirely, I probably had no minimum SDK version at all. Then I got a
really weird effect on my tabs, where they looked more or less like the old look, but
they were really light colored, which made them hard to read.

I finally started to piece it all together, and I took a series of screenshots to
document all the various combinations of Titanium SDK and minimum android SDK

Titanium SDK 2.1.4
custom AndroidManifest.xml
no targetSdkVersion

Notice the really bright, hard-to-read tabs.

Titanium SDK 2.1.4

no AndroidManifest.xml

(defaults to targetSdkVersion = 8)

Titanium SDK 2.1.4
custom AndroidManifest.xml
targetSdkVersion = 11

Notice no icons on the tabs

Titanium SDK 3.0.0
no AndroidManifest.xml
(defaults to targetSdkVersion = 8)

Notice the Action Bar above the tabs

Titanium SDK 3.0.0
custom AndroidManifest.xml
targetSdkVersion = 11

Notice the Action Bar above the tabs; I guess without any buttons on the action bar, it’s just an empty bar with an app icon…

Ready to deploy

At this point, our app is ready to publish in the iTunes app store or the google play store. I may eventually publish it in the google play store just for fun. I probably won’t spend $99 to put it in the iTunes store, though. I hope you’ve found this tutorial informative, and that maybe it helps you deal with some of the nuances of building cross-platform apps with Titanium.

Source repository at github

Part 1
Part 2
Part 3

Leave a comment

Your email address will not be published. Required fields are marked *