Preparing Windows for Android App Development
Important Developing Android app is not simple, the most important part is to prepare your computer properly first. It might take a while but this will ensure smooth development and save you a lot of time afterwards. Please be patient, read and follow the instructions completely and carefully.
To prepare your Windows for developing Android apps, you must install all the components required to build and run the apps, including Java Development Kit (JDK) and Android Software Development Kit (Android SDK). Android SDK provides the command line utilities, build systems, emulators and many handy tools for Android development.
The Android SDK in turn is dependent on the JDK (the JRE alone is not sufficient).
Installing Java Development Kit (JDK)
Install Java Development Kit (JDK) 8 or later.
Installing Android SDK
Install Android Studio, make sure you choose the package including Android SDK and make sure you run the installer as administrator.
Setting environment variables
Cordova's CLI tools require some environment variables to be set in order to function correctly. The CLI will attempt to set these variables for you, but in certain cases you may need to set them manually. The following variables should be updated:
- Set the JAVA_HOME environment variable to the location of your JDK installation, e.g. C:\Program Files\Java\jdk1.8.0_111
Note If you have also installed older versions of JDK (e.g. JDK 7), you should remove or rename the installed folder (e.g. C:\Program Files\Java\jdk1.7*) or Cordova may not detect your JDK version correctly.
- Set the ANDROID_HOME environment variable to the location of your Android SDK installation
- Add the Android SDK's tools and platform-tools directories to your PATH
These steps may vary depending on your installed version of Windows. Close and reopen any command prompt windows after making changes to see them reflected
- Click on the Start menu in the lower-left corner of the desktop
- In the search bar, search for Environment Variables and select Edit the system Environment Variables from the options that appear:
- In the window that appears, click the Environment Variables button
To create a new environment variable:
- Click New... and enter the variable name and value, e.g. set ANDROID_HOME as C:\Program Files (x86)\Android\android-sdk (substitute the paths with your actual local Android SDK installation's location).
To set your PATH
- Select the PATH variable and press Edit.
- Add entries for the relevant locations to the PATH, e.g. (substitute the paths with your actual local Android SDK installation's location):
C:\Program Files (x86)\Android\android-sdk\platform-tools
C:\Program Files (x86)\Android\android-sdk\tools
Installing Google USB Driver
To test the generated apps directly on an Android mobile device, you should also download and install the Google USB Driver. Firstly, you need to download the Google USB Driver package in the Android SDK. To do this:
- Open the Android SDK Manager (All Programs > Android SDK Tools > SDK Manager) (Run as administrator)
- Under the Extras folder, check the option Google USB Driver from within the SDK Manager
- Click the Install packages button
For more information about Google USB Driver, please read Google USB Driver.
After installing the package, the files are downloaded and stored under the .\extras subdirectory in the SDK root directory. The driver is not yet installed and you must perform the installation manually. To install the USB driver, please read Installing a USB Driver.
Setting up a Device for Development
To make your mobile device detectable by Windows, it is important to enable USB debugging on your device. (See Using Hardware Devices for details.)
- On Android 4.0 and newer, it's in Settings > Developer options. (On Android 4.2 and newer, Developer options is hidden by default. To make it available, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.)
- When plugged in over USB, you can verify that your device is connected by opening a command prompt and executing
adb devices from your SDK platform-tools/ directory. If connected, you'll see the device name listed as a "device".
- If the device is not detected, check your USB connection options on your device. By default, your device will be in Charging only mode. If not, try to switch back to Charging only mode and try again.
Creating and Running Your First Android Project on Mobile Device
After installing Android Studio and the Google USB Driver and making sure your device is detected, you can proceed to verify if the configuration is correct by creating and running your first Android Application directly on your mobile device.
- In Android Studio, create a new project:
- If you don't have a project opened, in the Welcome to Android Studio window, click Start a new Android Studio project.
- If you have a project opened, select File > New Project.
- In the New Project screen, enter the following values:
- Application Name: "My First App"
- Company Domain: "example.com"
Android Studio fills in the package name and project location for you, but you can edit these if you'd like.
- Click Next.
- In the Target Android Devices screen, keep the default values and click Next.
The Minimum Required SDK is the earliest version of Android that your app supports, which is indicated by the API level. To support as many devices as possible, you should set this to the lowest version available that allows your app to provide its core feature set. If any feature of your app is possible only on newer versions of Android and it's not critical to the core feature set, enable that feature only when running on the versions that support it (see Supporting Different Platform Versions).
- In the Add an Activity to Mobile screen, select Empty Activity and click Next.
- In the Customize the Activity screen, keep the default values and click Finish.
After some processing, Android Studio opens and displays a "Hello World" app with default files.
- Make sure you have plugged in your mobile device to your PC with an USB cable,
- Make sure your PC is connected to internet,
- In Android Studio, click Run from the toolbar.
- In the Select Deployment Target window, select your device (make sure it is under Connected Devices and it is not detected as offline), and click OK.
After some building and deployment process (probably take a while), the blank app should be running in your mobile device.
If above works, your Windows is now properly set up. You may proceed to create your first app from a database by following Quick Start.