/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.  Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\page android_support.html
\title Android
\brief Provides information about Android support in Qt 5.

Qt for Android enables you to run Qt 5 applications on devices with Android
v2.3.3 (API level 10) or later. Here is a list of supported items:
\list
 \li \l{Qt Widgets} and \l{QML Application Developer Resources}{QML}
     applications
 \li QML media player functionality in \l{Qt Multimedia}
 \li A set of commonly used sensors with \l{Qt Sensors}
 \li Deploying your application to a device from
     \l{Qt Creator Manual}{Qt Creator}
\endlist

\section1 Getting Started

In order to use Qt for Android, you will need the following external tools:

\list
\li \l{http://developer.android.com/sdk/index.html}{The Android SDK Tools}
\li \l{http://developer.android.com/tools/sdk/ndk/index.html}{The Android NDK}
\li \l{http://ant.apache.org/bindownload.cgi}{Apache Ant} v1.8 or later
\li \l{http://openjdk.java.net}{OpenJDK} v6 or later
\li Android Debug Bridge (ADB) driver on the Windows platform to enable USB
    debugging. The default USB driver on Windows does not allow debugging. You
    can download the ADB driver from the device manufacturer's support website.
    For example, the ADB driver for Google Nexus 7 can be downloaded from
    \l{http://support.asus.com}.

    After installing the driver, try running a few basic
    \l{http://developer.android.com/tools/help/adb.html}{adb} commands and check
    whether your device responds to it.
\endlist

\note You must set the \c{JAVA_HOME} environment variable to the JDK install
directory path so that Qt Creator finds the binaries required to build your
application.

After installing these tools, update the Android SDK to get the API
and tools packages required for development. You can update the SDK using the
\l{http://developer.android.com/tools/help/android.html}{android} tool that
comes with the SDK Tools package. For example, on Ubuntu the following command
starts the \l{http://developer.android.com/sdk/installing/adding-packages.html}
{Android SDK Manager}, which enables you to select the packages you want
to install:

\code
 ./android update sdk
\endcode

After the SDK is updated, install the Qt 5.1 binaries using the
\l{Qt Installation Program}{Qt installation program} and configure Qt Creator
to develop for Android. For more information, see
\l{Qt Creator: Connecting Android Devices}.

\note You must select at least one of the two Qt libraries for Android
(x86 and ARMv7) from the \gui{Qt 5.1.0} component tree in the
\gui{Select Components} page of \l{Qt Installation Program}
{Qt installation program}. By default, Qt libraries for ARMv7 are selected.

Test your setup by running one of the desktop examples. You can list all the
examples tested for Android using the \c{android} keyword in the search field
under the \gui{Examples} tab in Qt Creator \gui{Welcome} mode.

\section1 Porting an Existing Qt Application

Most Qt applications should be portable to Android with ease, unless they
depend on a specific hardware or software feature not supported by Android.
If your application is not using any such feature, deployment is probably the
only step that demands some changes to your application.

Like most UI applications, Qt applications also depend on resources such as
images, icons, translation files, and so on. These resources must be made
available on the device as they are required for the application to function
effectively.

The most convenient option is to bundle the resources into a qrc file,
which gets built into the application binary. This approach reduces the porting
effort considerably and provides faster access to the resources. It is
also a cross-platform approach, which makes porting to other platforms easier.

By default, all Qt applications can access the contents of a qrc file using
the ":/" prefix or the URL scheme prefix, "qrc:". To know more about qrc files
and how they are handled, see
\l{The Qt Resource System}{the Qt Resource System}.

The other approach is to deploy the resources into the package's \c{assets}
directory. It is the best option if you want to achieve better
interoperability with the Android APIs. You can access all resources in the
directory using the "assets:" prefix. Unlike qrc, this approach is not a
cross-platform solution.

The following step-by-step instructions guide you to port an existing Qt Quick
application to Android using the qrc approach:

\list 1
 \li Open the existing project in Qt Creator v2.7.1 or later, and configure it
     with "Android for ARM" kit. For more information, see
     \l{Qt Creator: Configuring Projects}
 \li Update all local directory imports in the \c{qml} files to use a local
     namespace. For example, to import the QML documents in the "contents"
     directory relative to \c{main.qml}, use the following import statement:

     \code
      import "contents" as Contents
     \endcode
 \li Identify all the resources used by your application and add them to one
     or more qrc files.
     Qt Creator updates your qmake project file with the "RESOURCES"
     variable listing the qrc files you added.
 \li To load or refer to the resources in the qrc file from a C++ file,
     use the "qrc:" prefix with the URL. For example, to load
     the \c{main.qml} file from \c{resources.qrc}, you can use the following
     code in your \c{main} function:
     \code
      QQuickView viewer;
      viewer.setSource(QUrl("qrc:qml/main.qml"));
      viewer.show();
     \endcode

     \note QML documents can refer to the contents in qrc files using the
     relative path to the document. Such references do not require the
     "\c{qrc:}" or "\c{:/}" prefix.
 \li Update the "Run" settings for your project as described in the
     \l{Qt Creator: Specifying Run Settings}

     \note You can change the default settings for application icons and
     identifier.
 \li If your application uses imports or plugins which depend on special Qt
     modules, these Qt modules should be added to the .pro file. For example, if
     your app uses the \l{Qt Multimedia} import in QML, you should add the
     following to your .pro file:
     \code
     QT += multimedia
     \endcode
 \li Save the changes to your project and run the application.
\endlist

Qt Creator deploys your application on the Android device, if the
device is detected by the PC. Otherwise, it tries to run the application on an
AVD (Android Virtual Device). You will be prompted to create one if there are no
AVDs found.

\section1 Related Information
\list
 \li \l{Platform and Compiler Notes - Android}{Platform Notes}
 \li \l{Qt Creator: Deploying Applications to Android Devices}
 \li \l{Android GNU C++ run-time licensing}
\endlist
*/
