AAPT and R class in Android

SHISHIR
2 min readNov 14, 2023

AAPT stands for Android Asset Packaging Tool. This is one of the default command-line build-tool with the Android SDK located in android_sdk/build-tools/version. It used to package and build all the the resources under res directory such as XML layout files, images and non-java code resources into binary format required by the Android OS. AAPT generates R class in android during build process. R class is very familiar to us that we use almost everywhere while doing Android app development like

val nameTv = findViewById<TextView>(R.id.tvName)

This R.class is Autogenerated by AAPT and contains resources IDs for all the resources of res/directory. Without which you cannot access any resources (drawable, layout, xmls etc). It is named R because stands for Resource.

Any resource you access by R.$FOLDER.$RESOURCE like R.id.tvName, R.layout.activity_main, R.drawable.bg_card etc.

If we create any component, id for the corresponding component is automatically created in this file. This id can be used in the activity source file to perform any action on the component.

R.java class looks like below.

public final class R {
public static final class id {
public static final int tvName = 17039345;
}

public static final class string {
public static final int text_yes = 17039360;
public static final int text_no = 17039361;
public static final int text_ok = 17039363;
}

public static final class layout {
public static final int activity_main = 17367040;
public static final int activity_home = 17367060;
public static final int fragment_home = 17367042;
}

public static final class drawable {
public static final int bg_green_button = 17301508;
}
}

--

--

SHISHIR

{ 'designation' : 'Lead Software Engineer' , 'hobby' : [ 'Music', 'Photography', 'Travelling' ] ,’email’: ‘shishirthedev@gmail.com’ }