- Get started with native Android development on Windows
- Install Android Studio
- Create a new project
- Java or Kotlin
- Minimum API Level
- Instant app support and Androidx artifacts
- Project files
- Use C or C++ for Android game development
- Design guidelines
- Fluent Design System for Android
- How to Build Android Kernel on Windows 10
- Requirements
- Setting up the Linux Environment
- For ARM Devices
- For ARM 64 Devices
- Getting the Source Files for your Device
- Building the Kernel
- For ARM Devices
- For ARM 64 Devices
- For Mediatek (MTK) Devices
- ARM and ARM64 Devices
- Mediatek Devices
- Making the Kernel Boot
- Adding Features to Your Kernel
- General Tips and Tricks
- The advanced methods:
- Accessing your Ubuntu folders from Windows 10
Get started with native Android development on Windows
This guide will get you started using Windows to create native Android applications. If you would prefer a cross-platform solution, see Overview of Android development on Windows for a brief summary of some options.
The most straight-forward way to create a native Android app is using Android Studio with either Java or Kotlin, though it is also possible to use C or C++ for Android development if you have a specific purpose. The Android Studio SDK tools compile your code, data, and resource files into an archive Android package, .apk file. One APK file contains all the contents of an Android app and is the file that Android-powered devices use to install the app.
Install Android Studio
Android Studio is the official integrated development environment for Google’s Android operating system. Download the latest version of Android Studio for Windows.
- If you downloaded an .exe file (recommended), double-click to launch it.
- If you downloaded a .zip file, unpack the ZIP, copy the android-studio folder into your Program Files folder, and then open the android-studio > bin folder and launch studio64.exe (for 64-bit machines) or studio.exe (for 32-bit machines).
Follow the setup wizard in Android Studio and install any SDK packages that it recommends. As new tools and other APIs become available, Android Studio will notify you with a pop-up, or check for updates by selecting Help > Check for Update.
Create a new project
Select File > New > New Project.
In the Choose your project window, you will be able to choose between these templates:
Basic Activity: Creates a simple app with an app bar, a floating action button and two layout files: one for the activity and one to separate out text content.
Empty Activity: Creates an empty activity and a single layout file with sample text content.
Bottom Navigation Activity: Creates a standard bottom navigation bar for an activity. See the Bottom Navigation Component in Google’s material design guidelines.
Learn more about selecting an activity template in the Android Studio docs.
Templates are commonly used to add activities to new and existing app modules. For example, to create a login screen for your app’s users, add an activity with the Login Activity template.
The Android operating system is based on the idea of components and uses the terms activity and intent to define interactions. An activity represents a single, focused task that a user can do. An activity provides a window for building the user interface using classes based on the View class. There is a lifecycle for activities in the Android operating system, defined by a set of six callbacks: onCreate() , onStart() , onResume() , onPause() , onStop() , and onDestroy() . The activity components interact with one another using intent objects. Intent either defines the activity to start or describes the type of action to perform (and the system selects the appropriate activity for you, which can even be from a different application). Learn more about Activities, the Activity Lifecycle, and Intents in the Android docs.
Java or Kotlin
Java became a language in 1991, developed by what was then Sun Microsystems, but which is now owned by Oracle. It has become one of the most popular and powerful programming languages with one of the largest support communities in the world. Java is class-based and object-oriented, designed to have as few implementation dependencies as possible. The syntax is similar to C and C++, but it has fewer low-level facilities than either of them.
Kotlin was first announced as a new open-source language by JetBrains in 2011 and has been included as an alternative to Java in Android Studio since 2017. In May 2019, Google announced Kotlin as it’s preferred language for Android app developers, so despite being a newer language, it also has a strong support community and has been identified as one of the fastest growing programming languages. Kotlin is cross-platform, statically typed, and designed to interoperate fully with Java.
Java is more widely used for a broader range of applications and offers some features that Kotlin does not, such as checked exceptions, primitive types that are not classes, static members, non-private fields, wildcard-types, and ternary-operators. Kotlin is specifically designed for and recommended by Android. It also offers some features that Java does not, such as null references controlled by the type system, no raw types, invariant arrays, proper function types (as opposed to Java’s SAM-conversions), use-site variance without wildcards, smart casts, and more. The Kotlin documentation offers a more in-depth look at the comparison to Java.
Minimum API Level
You will need to decide the minimum API level for your application. This determines which version of Android your application will support. Lower API levels are older and therefore generally support more devices, but higher API levels are newer and therefor provide more features.
Select the Help me choose link to open a comparison chart showing the device support distribution and key features associated with the platform version release.
Instant app support and Androidx artifacts
You may notice a checkbox to Support instant apps and another to Use androidx artifacts in your project creation options. The instant apps support is not checked and the androidx is checked as the recommended default.
Google Play Instant apps provide a way for people to try an app or game without installing it first. These instant apps can be surfaced across the Play Store, Google Search, social networks, and anywhere you share a link. By checking the Support instant apps box, you are asking Android Studio to include the Google Play Instant Development SDK with your project. To learn more about Google Play Instant apps and how to create an instant-enabled app bundle, see the Android documentation.
AndroidX artifacts represents the new version of the Android support library and provides backwards-compatibility across Android releases. AndroidX provides a consistent namespace starting with the string androidx for all available packages.
AndroidX is now the default library. To uncheck this box and use the previous support library requires removing the lastest Android Q SDK. See Uncheck use Androidx artifacts on StackOverflow for instructions, but first note that the former Support Library packages have been mapped into corresponding androidx.* packages. For a full mapping of all the old classes and build artifacts to the new ones, see Migrating to AndroidX.
Project files
The Android Studio Project window, contains the following files (be sure that the Android view is selected from the drop-down menu):
app > java > com.example.myfirstapp > MainActivity
The main activity and entry point for your app. When you build and run your app, the system launches an instance of this Activity and loads its layout.
app > res > layout > activity_main.xml
The XML file defining the layout for the activity’s user interface (UI). It contains a TextView element with the text «Hello World»
app > manifests > AndroidManifest.xml
The manifest file describing the fundamental characteristics of the app and each of its components.
Gradle Scripts > build.gradle
There are two files with this name: «Project: My First App», for the entire project, and «Module: app», for each app module. A new project will initially only have one module. Use the module’s build.file to control how the Gradle plugin builds your app. Learn more in the Android docs, Configure your build article.
Use C or C++ for Android game development
The Android operating system is designed to support applications written in Java or Kotlin, benefiting from tooling embedded in the system’s architecture. Many system features, like Android UI and Intent handling, are only exposed through Java interfaces. There are a few instances where you may want to use C or C++ code via the Android Native Development Kit (NDK) despite some of the associated challenges. Game development is an example, since games typically use custom rendering logic written in OpenGL or Vulkan and benefit from a wealth of C libraries focused on game development. Using C or C++ might also help you squeeze extra performance out of a device to achieve low latency or run computationally intensive applications, such as physics simulations. The NDK is not appropriate for most novice Android programmers however. Unless you have a specific purpose for using the NDK, we recommend sticking with Java, Kotlin, or one of the cross-platform frameworks.
To create a new project with C/C++ support:
In the Choose your project section of the Android Studio wizard, select the Native C++* project type. Select Next, complete the remaining fields, then select Next again.
In the Customize C++ Support section of the wizard, you can customize your project with the C++ Standard field. Use the drop-down list to select which standardization of C++ you want to use. Selecting Toolchain Default uses the default CMake setting. Select Finish.
Once Android Studio creates your new project, you can find a cpp folder in the Project pane that contains the native source files, headers, build scripts for CMake or ndk-build, and prebuilt libraries that are a part of your project. You can also find a sample C++ source file, native-lib.cpp , in the src/main/cpp/ folder which provides a simple stringFromJNI() function returning the string «Hello from C++». Additionally, you will find a CMake build script, CMakeLists.txt , in your module’s root directory required for building your native library.
To learn more, see the Android docs topic: Add C and C++ code to your project. For samples, see the Android NDK samples with Android Studio C++ integration repo on GitHub. To compile and run a C++ game on Android, use the Google Play Game services API.
Design guidelines
Device users expect applications to look and behave a certain way. whether swiping or tapping or using voice-controls, users will hold specific expectations for what your application should look like and how to use it. These expectations should remain consistent in order to reduce confusion and frustration. Android offers a guide to these platform and device expectations that combines the Google Material Design foundation for visual and navigational patterns, along with quality guidelines for compatibility, performance, and security.
Fluent Design System for Android
Microsoft also offers design guidance with the goal of providing a seamless experience across the entire portfolio of Microsoft’s mobile apps.
Fluent Design System for Android design and build custom apps that are natively Android while still uniquely Fluent.
How to Build Android Kernel on Windows 10
Appual’s has a few great guides on Android development, such as How to Build a Custom ROM from Android Open Source Project – but these guides are usually geared towards a pure Linux build environment.
In this guide, we are going to show you how to build an Android kernel on Windows 10 – yes, we will still be using a Linux build environment, but it will be a Linux subsystem within Windows 10. So if you are a Windows 10 user interested in developing for Android, follow our guide carefully.
In this guide, we will specifically be learning how to build a kernel for ARM and MediaTek devices, adding features, and a basic overview of using Git.
Requirements
- Windows 10 x64 (with Fall Creator’s update)
Setting up the Linux Environment
- On Windows 10, go to Settings > Update and Security > For Developers > enable Developers Mode.
- Now go to Control Panel > Programs > Turn Windows Features On or Off > enable Windows Subsystem for Linux.
- Reboot your PC.
- Launch the Linux subsystem, and allow it to go through the download process. Set a password and don’t lose it.
- Now go to the Windows app store, and download Ubuntu.
- Launch Ubuntu on the Windows 10 desktop, and it will request a username and password.
- In Ubuntu, launch the native terminal and type the following command: apt-get update
- This will proceed to update all repos for apps and dependencies.
- Next in the terminal type: sudo apt-get install -y build-essential kernel-package libncurses5-dev bzip2
- In order to check if all dependencies were correctly installed, type ‘gcc’ in the terminal (no quotes).
- If “gcc” is already installed, you should see “gcc : fatal error : no input file”
- Now you can type ‘make’ in the terminal. If “make” is already installed, you should see “make: *** no target specified and no makefile found. stop.”
- Next type ‘git’, and iff “git” is already installed, you should see bunch of basic git commands.
- Now we need some toolchains (there are several types, including GCC, Linaro, and a handful of custom ones). Some devices may require different toolchains, for example, not all device kernels will boot or compile with GCC.
For ARM Devices
We will be using GCC 4.7 for this.
- Open the Linux terminal and type: mkdir kernel
- Now type: cd kernel
- (it doesn’t have to be ‘kernel’, this is for simplicity sake, you can name it whatever you want.)
- Now type: git clone https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7
For ARM 64 Devices
You need a 64-bit kernel compiler for ARM 64 devices, for example aarch64.
Getting the Source Files for your Device
This is a tricky part, as you need to find a GitHub repo that hosts your kernel source. You will of course need to search for it, most likely it can be found on XDA forums.
On the upper left side, you should see “Branch: Completed by xxxx”.
There are different versions of a kernel / project, usually separated by “Testing”, “Beta”, “Final Release”, etc.
The kernel folders are typically as follows:
- /arch/arm/configs: This contains various config files for the device, such as governors, etc.
- /output/arch/arm/boot/: This is where the zimage will be stored.
- build.sh: A script that will simplify the building process.
- /arm-cortex-linux-gnueabi-linaro_5.2-2015.11-2: This is typically a toolchain placed in the kernel source, thus making it easier to find.
You are going to need to download your kernel source.
Open the Linux terminal and make sure that you are in the kernel folder you previously created (cd kernel).
Then type in terminal: “git clone “URL of the github kernel” -b “name of the branch”
Building the Kernel
To make it easier, you can navigate to the location in the file explorer. It should be /home/user ID/kernel (or whatever you named the kernel folder).
You should see two folders inside, for the toolchain and the kernel source. Go inside the kernel source folder.
For ARM Devices
In a terminal, type the following commands:
Here is an overview of what these commands do, to make this easier in the future.
- #!/bin/bash: Tells the script to run in shell command
- export ARCH=arm: Defining which kernel architecture type it is (For example arm64 etc)
- export CROSS_COMPILE= : Locate where the toolchain is. It must match the exact path, and the dash in the end is really mandatory.
- mkdir output: This creates a directory for saving the compiled zimage
- make -C $(pwd) O=output : Defining defconfig for guiding kernel compilation.
- make -j4 -C $(pwd) O=output: When the building process begins, -j# tells it how fast to try and compile. Typically, you set this number according to your CPU. Setting on -j32 on a budget CPU, for example, would probably cause massive instability.
- cp output/arch/arm/boot/Image $(pwd)/arch/arm/boot/zImage: This is for moving image to a second path.
For ARM 64 Devices
For Mediatek (MTK) Devices
When you have completed the steps necessary to your kernel architecture, you can type in the terminal: sudo bash build.sh
You will then enter your user password, and the compiling process will begin.
It may take a while but typically not very long, compiling a kernel is not like compiling an entire Android ROM. This is really CPU dependent – for example, an AMD Phenom X4 3.4GHz with 8GB of RAM should take around 10 minutes to compile from start to finish.
When it finishes, it should notify you with a message like “zimage is ready”.
ARM and ARM64 Devices
Go to “/Output/arch/arm/boot/” to find your zimage.
Mediatek Devices
Go to “/arch/arm/boot/” to find your zimage.
Not all kernel builds will result in a Zimage file, it can sometimes be built as other image formats.
Important: If you are going to compile again, it is recommended that you enter the commands make clean and make mrproper before you begin the compile process again.
Making the Kernel Boot
There are two options for you to choose.
You can either use the anykernel method (as defined by XDA user @osm0sis in this XDA thread). You should read the entire tutorial, but a summary of the steps is as follows:
- Place zImage in the root (dtb and/or dtbo should also go here for devices that require custom ones, each will fallback to the original if not included)
- Place any required ramdisk files in /ramdisk and modules in /modules (with the full path like /modules/system/lib/modules)
- Place any required patch files (generally partial files which go with commands) in /patch
- Modify the anykernel.sh to add your kernel’s name, boot partition location, permissions for included ramdisk files, and use methods for any required ramdisk modifications (optionally, also place banner and/or version files in the root to have these displayed during flash)
- `zip -r9 UPDATE-AnyKernel2.zip * -x .git README.md *placeholder`
The other method you have available is unpacking the boot.img from the same ROM (such as CM, TouchWiz, EMUI, etc.) and the same Android version. You would then swap the Zimage. Again, this is a really complicated process and you should read the exact tutorial, but a summary of the steps is:
- Unzip.
- Either use the command-line “unpackimg ”, or simply drag-and-drop the image. This will split the image and unpack the ramdisk to a subdirectory.
- Alter the ramdisk as you like.
- The repackimg batch script requires no input and simply recombines the previously split zImage with the newly packed modified ramdisk using all the original image information (which was also split and saved).
- The cleanup batch script resets the folder to its initial state, removing the split_img+ramdisk directories and any new packed ramdisk or image files.
Before you flash your kernel, you should create a backup of your stock boot.img, and then flash your kernel to see if it allows your Android system to boot.
Adding Features to Your Kernel
Adding features to your kernel is a great way to spice it up. There are a lot of things you can tweak, such as CPU governors, IO schedulers, overclocking the GPU, audio enhancements, etc.
An example for adding a governor is here (this governor is codenamed Intellimm).
We can see in the first 2 text boxes that in “arch/arm/configs/” “msm8974_sec_defconfig” and “cm_msm8974_sec_defconfig” have been modified.
Between the lines 140 and 141 of this files this text has been added : “CONFIG_CPU_FREQ_GOV_INTELLIMM=y”
(This line is for enabling Intellimm when you’re compiling your kernel)
Same technique applies to the other text boxes (what has been added and deleted and it’s location)
Depending on the features you add, more or less files can be modified, added or deleted.
So to sum it up, a Commit let’s you see all the changes which have been made and everything else!
General Tips and Tricks
How to change the kernel name and version:
The simple method:
Edit this line in your defconfig file:
The advanced methods:
Navigate to the Makefile in the root folder of your kernel source.
Add these lines:
DO NOT modify the lines Version, PatchLevel, Sublevel, or Extraversion.
Alternative method:
Go to scripts/mkcompile_h and add these lines:
Solving PATH problems:
If you encounter the error “Is your path correct?”, try this in the Linux terminal:
Accessing your Ubuntu folders from Windows 10
Your path to Ubuntu should typically be:
But you should not edit files directly from Windows, as this will typically break the permissions on them – you would then need to reset the permissions from within Linux terminal.