To build source code in Android Studio, you compile your Kotlin, Java, or C/C++ files into an installable app (an APK or an Android App Bundle) through Gradle, and you can trigger that build with the Build > Make Project menu, the hammer icon, or the Run button. The key condition is a valid, synced Gradle project: your modules, dependencies, and build configuration must resolve before compilation can start. Once they do, Android Studio hands the work to the Android Gradle plugin, which compiles resources and code, packages everything, and lets you deploy the result to an emulator or a physical device.
This guide walks through the whole path—setting up prerequisites, building a standard Kotlin/Java project, adding native C/C++ code, building Android Studio itself from its open source, and fixing the errors that stop a build cold. It also explains what "build" actually means under the hood so the steps make sense rather than feel like button-pushing.
What "building source code" actually means in Android Studio
When you press a build button, Android Studio doesn't simply turn one file into one program. The Android build system compiles app resources and your source code, then packages them into APKs or Android App Bundles that you can test, deploy, sign, and distribute. That packaging step is why a build involves several moving parts: a resource compiler, a code compiler, a packaging tool, and a signing step.
Gradle is the orchestrator. It reads your project's build scripts, figures out which tasks must run in which order, and executes them. The Android Gradle plugin (AGP) teaches Gradle the Android-specific tasks. Your source code is organized into source sets—groupings of code and resources per module—which Android Studio creates automatically when you add a module. That matters later: if a file sits in the wrong source set, it may never be compiled.
There are two broad meanings of "build" you should keep separate:
Building your app—compiling your project's code into a runnable APK/AAB. This is what most people mean, and it's the main focus here. Building Android Studio itself—compiling the IDE from its open source in the Android Open Source Project (AOSP). This is a much heavier, specialized task that the source evidence also covers, so it gets its own section.
Sort out which one you need before following steps, because the prerequisites are wildly different.
Prerequisites before your first build in Android Studio
Every step below assumes a working baseline. Skipping these is the most common reason a "build" fails before it starts.
A synced project. Gradle must have finished syncing. If you see "Gradle sync failed," fix that first; a build cannot run on an unsynced project. A compatible JDK. Whether your code is Java, Kotlin, or both, there are several places you must choose a JDK or Java language version for your build. Mismatches between the JDK running Gradle and the Java version your source targets produce some of the most confusing errors. Check File > Settings > Build, Execution, Deployment > Build Tools > Gradle for the Gradle JDK, and your module's build file for compileOptions/kotlinOptions. The Android SDK components your project targets. If the required SDK platform or build tools version is missing, Gradle will tell you and offer to install it. A device or emulator if you intend to run, not just compile. For native code: the NDK and CMake or ndk-build. To compile and debug native code you need the Android Native Development Kit (NDK) and build tools.
If any of these are missing, the build output window will name the problem. Read it before changing anything—more on that in the troubleshooting section.
Building a standard Kotlin or Java project, step by step
This is the everyday path for an app written in Kotlin, Java, or both, with no native code.
1: Open the project and let Gradle sync. Watch the status bar. Success looks like a clean sync with no red error banners; the Build tool window stays quiet until you ask it to build. 2: Confirm your build variant. Use Build > Select Build Variant (or the Build Variants panel) to choose debug or release and the flavor you want. Building release usually requires signing configuration; debug is signed with a default key so it installs immediately. 3: Trigger a compile. Choose Build > Make Project or click the hammer icon. This compiles changed sources and assembles the app without deploying it. Expect a "BUILD SUCCESSFUL" line in the Build output at the end. 4: Or build and run in one step. Click Run (the green triangle). This builds, installs on the selected device or emulator, and launches the app. Success is the app appearing on screen; failure shows up in the Build and Logcat windows. 5: Inspect the output. Builds land under your module's build/outputs/ directory—apk/ for APKs and bundle/ for AABs. Seeing the file there is a concrete way to confirm the build produced an artifact. 6: Clean when things get stale. Build > Clean Project deletes generated outputs so the next build starts fresh. Use it when a change seems ignored or outputs look corrupted—not as a habit, since it forces a full rebuild.
A simple success check: after step 3, the Build window's last lines should read "BUILD SUCCESSFUL," and the build time should be plausible relative to the size of your changes. If you instead see "BUILD FAILED," jump to the troubleshooting section rather than re-running blindly.
Building a project that includes C and C++ source code
If your app includes native code, the flow changes. You add C and C++ by placing the code in a cpp directory in your project module; when you build, that code compiles into a native library that Gradle packages with your app, and your Kotlin or Java code calls it through the Java Native Interface (JNI).
Here's the workable order for a fresh project:
1: Download the NDK and build tools through the SDK Manager. Both are required to compile and debug native code. 2: Create the project with C/C++ support, or add native files to an existing module. Skip file creation if you already have native code or are importing a prebuilt library. 3: Write or place your C/C++ sources in the module's cpp directory. 4: Configure CMake so your native source compiles into a library. A CMakeLists.txt build script is required if you're importing and linking against prebuilt or platform libraries. If your existing native library already has a CMakeLists.txt or uses ndk-build with an Android.mk, you can skip this. 5: Point Gradle at the build script. Gradle uses that script to import your source and package the native library into the app. 6: Call the native functions from Kotlin or Java via JNI, then click Run to build and deploy.
Two constraints to respect. First, Android Studio supports CMake, which suits cross-platform projects, and also supports ndk-build, which can be faster but only targets Android. Second, using both CMake and ndk-build in the same module is not currently supported—pick one per module. If your project still relies on the deprecated ndkCompile tool, migrate to CMake or ndk-build.
Success check: the build log shows the native compilation tasks completing, and the app runs without an UnsatisfiedLinkError when it calls into the library. That error is the classic signal that the native library wasn't packaged or the JNI signature doesn't match.
Building Android Studio itself from source code
This is a different job entirely, and it's where many people get lost because "build Android Studio" sounds like building an app. It isn't. Android Studio is open source, and like the Android operating system, source is released to AOSP after each stable release; as of Android Studio 1.4, the IDE follows that same source-release model.
To get the code, you use the repo tool to check out the source, initialize against the manifest with the studio-master-dev branch, and sync. The checkout pulls in three key project groups: the Android plugin source under /tools/adt/idea, the IntelliJ IDE base under /tools/idea/, and shared library dependencies under /tools/base/.
Building from source centers on Bazel. You need to be able to run the revision-controlled Bazel executable located in /tools/base/bazel/—verify it with tools/base/bazel/bazel version from the studio-main/ directory. Then confirm Bazel can actually execute build tasks by running a small target, such as bazel build /tools/adt/idea/android:profiler-artifacts.
Windows requires extra setup before the command-line build works. You need Python 2.7 or higher on your PATH, msys2 installed at c:\tools\msys2\ (Bazel specifically looks there; otherwise you get a build error), and the Visual Studio 2015 build tools. You also need Git for Windows configured with "Use Git from the Windows Command Prompt" and Windows-style checkout with Unix-style line endings, long-path support enabled via git config --global core.longpaths true, and git-repo installed and on your PATH. The Android SDK is also required. One caveat in the source: the Bazel step does not currently apply to AOSP builds, where required binaries are checked in as prebuilts—so if you're building from AOSP, ignore that section.
Stop condition: if Bazel can't run at all after these checks, or if you're missing a documented platform prerequisite and can't install it, that's the point to consult the Android Studio build documentation rather than improvising changes to the build configuration. This is a specialized toolchain, not a typical app project.
Where builds go wrong and how to fix them
Distinguish the symptom from the cause before changing anything, and start with reversible checks.
"Gradle sync failed" before any build. Usually a dependency, plugin version, or JDK mismatch. Symptom is a failed sync; fix it at the sync level, not by rebuilding. Reversible check: run File > Sync Project with Gradle Files and read the first error, not the cascade after it. "BUILD FAILED" with a compile error. A real code error. The output points to the file and line. This is expected and correct behavior; fix the code. Unresolved symbols that clearly exist. Often a stale build or a source-set problem. Try Clean Project then rebuild—a reversible step—before deeper investigation. Native build failures. Usually a missing CMakeLists.txt, a wrong path in the Gradle config, or mixing CMake and ndk-build in one module (unsupported). Check these before touching your C/C++ logic. Build succeeds but the app crashes on native calls. Suspicion falls on packaging or JNI signatures rather than compilation. Release build fails while debug works. Almost always signing configuration, which debug builds bypass.
A useful discipline: read only the first error in the Build output. Later lines are often downstream noise. Fix the first, rebuild, and re-read.
Practical tips that save time
Keep these habits to make builds predictable:
Use the Build tool window's tree view to see which task failed, rather than scrolling a wall of text. Prefer Make Project for a fast compile check and Run when you actually need the app deployed—this avoids unnecessary installs. Keep your Gradle JDK consistent across machines if you collaborate, since JDK drift is a silent source of "works on my machine" failures. And when switching between native and standard builds, remember the CMake-or-ndk-build-per-module rule so you don't create an unsupported configuration.
For reproducibility, note that a build's inputs include your Gradle and AGP versions, the JDK, and the SDK/NDK versions. Two machines with different versions of these can produce different results from identical source. When a build behaves oddly after an update, checking those versions against a known-good setup is faster than guessing.
FAQ
Does "Make Project" install the app? No. It compiles and assembles without deploying. Use Run to build and install on a device or emulator.
Can I use both CMake and ndk-build in one module? No—that combination isn't currently supported. Choose one per module.
Is building Android Studio the same as building my app? No. Building your app uses Gradle; building Android Studio from source uses Bazel and a much larger toolchain, with extra prerequisites such as msys2 on Windows.