For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.


Run a Cordova Project in Android Studio

Develop your Cordova app with MobileFirst for Android using Android Studio.


Before you begin

You must have a Cordova app project set up with Apache Cordova CLI (see Creating a new Cordova app without the MobileFirst template).


Procedure

  1. If you have not already done so, from the command line run

    cordova prepare

    This creates the mfpclient.properties file in the assets folder. If this file does not exist, we cannot run your app.

  2. Open the project in Android Studio.
    1. From Android Studio select File->New->Import Project.
    2. Navigate to the build.gradle file in project name and click OK.
  3. In the project navigator pane the project looks like this:

    Table 1. Android Studio navigation pane
    Android Studio navigation pane Description of selected files

    Android Studio

    AndroidManifest.xml

    One of the functions of the AndroidManifest.xml file is list the start up code for the app.

    MainActivity.java

    The start up code for the app.

    config.xml

    Various configurations including:

    • Calls hooks.
    • Points to the default html page:

      <content src="index.html" />

    www

    Contains the JavaScript, HTML, and CSS files loaded into the WebView.

    index.html

    The initial html page loaded by the WebView, defined in the config.xml file.

    mfpclient.properties

    The file containing information for connecting to the MobileFirst server. See

  4. Run your application to view it in the emulator.
    1. From the Run menu choose Run Android.
    2. Choose a device from the Device Chooser dialog.
    The app is displayed in the emulator.


What to do next

You now have your Cordova project set up in Android Studio. You must register your app before we can start writing your code. See Registering Cordova applications to MobileFirst Server.

Parent topic: Developing Cordova apps for Android