The Generated Source Sets
Inside the src/
directory are “source sets”. These identify different directories of source code (and related files) that will be used in different circumstances:
There are three source sets that will be created by default for an Android project: main/
, androidTest/
and test/
.
main/
The source set that you will spend most of your time in is main/
. This represents the “main” source code for your app. For most apps, this source set contains all of your code (and related files) that make up the app itself:
Your Java and Kotlin code will go in a java/
directory inside of the source set. Here, we see one Kotlin file, named MainActivity.kt
(where the .kt
part is left off in the tree).
You will also find:
- Resources, in the
res/
directory, which are files that are not source code but contribute to your app, such as your icons and other images, as we will see in an upcoming chapter -
AndroidManifest.xml
, which is the “table of contents” of what is in your app, as we will see in another upcoming chapter - Optionally other things (
assets/
,jni/
,aidl/
, etc.), though these will not be seen in every Android project
androidTest/
The androidTest/
source set can have its own Java/Kotlin source code, resources, and manifest file. Typically, it only has Java and Kotlin source code:
This source set’s files will not go into your app. Instead, they are for testing your app, to make sure that your app does what it is supposed to do.
test/
There is a very similar source set, named test/
, in a typical Android project:
As with androidTest/
, test/
can contain its own Java and Kotlin code. And, as with the androidTest/
source set, the test/
code is not part of your app, but instead is for testing your app.
The difference between androidTest/
and test/
is in where your tests run:
-
androidTest/
tests run inside of an Android device or emulator -
test/
tests run directly on your development machine, in a Java virtual machine
We will explore that distinction in greater detail, along with the test code in our starter project, later in the book.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.