Tutorial #3 - Manifest Changes

As we build EmPubLite, we will need to make a number of changes to our project’s manifest. In this tutorial, we will take care of a couple of these changes, to show you how to manipulate the AndroidManifest.xml file. Future tutorials will make yet more changes.

Android Studio users will also get their first chance to work with the build.gradle file.

This is a continuation of the work we did in the previous tutorial.

You can find the results of the previous tutorial and the results of this tutorial in the book’s GitHub repository.

Some Notes About Relative Paths

In these tutorials, you will see references to relative paths, like AndroidManifest.xml, res/layout/, and so on.

Android Studio users should interpret these paths as being relative to the app/src/main/ directory within the project, except as otherwise noted. So, for example, Step #1 below will ask you to open AndroidManifest.xml — that file can be found in app/src/main/AndroidManifest.xml from the project root.

Step #1: Supporting Screens

Our application will restrict its supported screen sizes. Tablets make for ideal ebook readers. Phones can also be used, but the smaller the phone, the more difficult it will be to come up with a UI that will let the user do everything that is needed, yet still have room for more than a sentence or two of the book at a time.

We will get into screen size strategies and their details later in this book. For the moment, though, we will add a <supports-screens> element to keep our application off “small” screen devices (under 3” diagonal size).

Android Studio users can double-click on AndroidManifest.xml in the project explorer.

As a child of the root <manifest> element, add a <supports-screens> element as follows:


<supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="false"
    android:xlargeScreens="true"/>

Step #2: Blocking Backups

If you look at the <application> element, you will see that it has a few attributes, including android:allowBackup="true". This attribute indicates that EmPubLite should participate in Android’s automatic backup system.

That is not a good idea, until you understand the technical and legal ramifications of that choice, which we will explore much later in this book.

In the short term, change android:allowBackup to be false.

Step #3: Ignoring Lint

Even after that change, the application element name may have a beige background. If you hover your mouse over it and look at the explanatory tooltip, you will see that it is complaining that this app is not indexable, and that you should add an ACTION_VIEW activity to the app.

This is ridiculous.

First, this app (hopefully) will never wind up on the Play Store, and so Google’s “app indexing” capability will never be relevant.

Second, developers should not be adding random activities to their app, just based off of some tooltip.

Put your text cursor somewhere inside the application element name and press Alt-Enter (or the equivalent on macOS). This should bring up a popup window showing some “quick fixes” for the problem:

Quick Fixes
Figure 55: Quick Fixes

Choose the “suppress Lint” option. Then, press Ctrl-Alt-L (or the equivalent on macOS) to reformat the file. You will wind up with something like:

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.commonsware.empublite"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools">

  <supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="false"
    android:xlargeScreens="true" />

  <application
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:ignore="GoogleAppIndexingWarning">
    <activity android:name=".EmPubLiteActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
  </application>

</manifest>
(from EmPubLite-AndroidStudio/T3-Manifest/EmPubLite/app/src/main/AndroidManifest.xml)

The <application> element now has a tools:ignore="GoogleAppIndexingWarning" attribute, and the root <manifest> element defines the tools XML namespace. The net effect is that we are telling the build tools — specifically the Lint utility – that it should ignore this particular issue.

In Our Next Episode…

… we will make some changes to the resources of our tutorial project