Learn About R.java File and Dalvik Virtual Machine in Android

Introduction

 
This article explains the R.java file and Dalvik virtual machine in Android. This file is automatically generated by the Android asset packaging tool that contains resource ids of all the resources. If you create any component in the activity_main.xml file then the ids of all the components are automatically generated inside the R.java file.
 
The following is an example of a generated R.java file in Android Studio that contains the ids of the resuorce component. I just use an example of when we create a button in our XML file. The R.java file is then created with id as in the following:
  1. package android.support.v7.appcompat;  
  2. public final class R   
  3. {  
  4.  public static final class anim   
  5.  {  
  6.   public static final int abc_fade_in = 0x7f040000;  
  7.   public static final int abc_fade_out = 0x7f040001;  
  8.   public static final int abc_slide_in_bottom = 0x7f040002;  
  9.   public static final int abc_slide_in_top = 0x7f040003;  
  10.   public static final int abc_slide_out_bottom = 0x7f040004;  
  11.   public static final int abc_slide_out_top = 0x7f040005;  
  12.  }  
  13.  public static final class attr   
  14.  {  
  15.   public static final int actionBarDivider = 0x7f010000;  
  16.   public static final int actionBarItemBackground = 0x7f010001;  
  17.   public static final int actionBarSize = 0x7f010002;  
  18.   public static final int actionBarSplitStyle = 0x7f010003;  
  19.   public static final int actionBarStyle = 0x7f010004;  
  20.   public static final int actionBarTabBarStyle = 0x7f010005;  
  21.   public static final int actionBarTabStyle = 0x7f010006;  
  22.   public static final int actionBarTabTextStyle = 0x7f010007;  
  23.   public static final int actionBarWidgetTheme = 0x7f010008;  
  24.   public static final int actionButtonStyle = 0x7f010009;  
  25.   public static final int actionDropDownStyle = 0x7f010062;  
  26.   public static final int actionLayout = 0x7f010059;  
  27.   public static final int actionMenuTextAppearance = 0x7f01000a;  
  28.   public static final int actionMenuTextColor = 0x7f01000b;  
  29.   public static final int actionModeBackground = 0x7f01000c;  
  30.   public static final int actionModeCloseButtonStyle = 0x7f01000d;  
  31.   public static final int actionModeCloseDrawable = 0x7f01000e;  
  32.   public static final int actionModeCopyDrawable = 0x7f01000f;  
  33.   public static final int actionModeCutDrawable = 0x7f010010;  
  34.   public static final int actionModeFindDrawable = 0x7f010011;  
  35.   public static final int actionModePasteDrawable = 0x7f010012;  
  36.   public static final int actionModePopupWindowStyle = 0x7f010013;  
  37.   public static final int actionModeSelectAllDrawable = 0x7f010014;  
  38.   public static final int actionModeShareDrawable = 0x7f010015;  
  39.   public static final int actionModeSplitBackground = 0x7f010016;  
  40.   public static final int actionModeStyle = 0x7f010017;  
  41.   public static final int actionModeWebSearchDrawable = 0x7f010018;  
  42.   public static final int actionOverflowButtonStyle = 0x7f010019;  
  43.   public static final int actionProviderClass = 0x7f01005b;  
  44.   public static final int actionViewClass = 0x7f01005a;  
  45.   public static final int activityChooserViewStyle = 0x7f01001a;  
  46.   public static final int background = 0x7f010047;  
  47.   public static final int backgroundSplit = 0x7f010049;  
  48.   public static final int backgroundStacked = 0x7f010048;  
  49.   public static final int buttonBarButtonStyle = 0x7f01001b;  
  50.   public static final int buttonBarStyle = 0x7f01001c;  
  51.   public static final int customNavigationLayout = 0x7f01004a;  
  52.   public static final int disableChildrenWhenDisabled = 0x7f010061;  
  53.   public static final int displayOptions = 0x7f010040;  
  54.   public static final int divider = 0x7f010046;  
  55.   public static final int dividerHorizontal = 0x7f01001d;  
  56.   public static final int dividerPadding = 0x7f010057;  
  57.   public static final int dividerVertical = 0x7f01001e;  
  58.   public static final int dropDownListViewStyle = 0x7f01001f;  
  59.   public static final int dropdownListPreferredItemHeight = 0x7f010063;  
  60.   public static final int expandActivityOverflowButtonDrawable = 0x7f010054;  
  61.   public static final int height = 0x7f010020;  
  62.   public static final int homeAsUpIndicator = 0x7f010021;  
  63.   public static final int homeLayout = 0x7f01004b;  
  64.   public static final int icon = 0x7f010044;  
  65.   public static final int iconifiedByDefault = 0x7f01005c;  
  66.   public static final int indeterminateProgressStyle = 0x7f01004d;  
  67.   public static final int initialActivityCount = 0x7f010053;  
  68.   public static final int isLightTheme = 0x7f010022;  
  69.   public static final int itemPadding = 0x7f01004f;  
  70.   public static final int listChoiceBackgroundIndicator = 0x7f010067;  
  71.   public static final int listPopupWindowStyle = 0x7f010023;  
  72.   public static final int listPreferredItemHeight = 0x7f010024;  
  73.   public static final int listPreferredItemHeightLarge = 0x7f010025;  
  74.   public static final int listPreferredItemHeightSmall = 0x7f010026;  
  75.   public static final int listPreferredItemPaddingLeft = 0x7f010027;  
  76.   public static final int listPreferredItemPaddingRight = 0x7f010028;  
  77.   public static final int logo = 0x7f010045;  
  78.   public static final int navigationMode = 0x7f01003f;  
  79.   public static final int paddingEnd = 0x7f010069;  
  80.   public static final int paddingStart = 0x7f010068;  
  81.   public static final int panelMenuListTheme = 0x7f010066;  
  82.   public static final int panelMenuListWidth = 0x7f010065;  
  83.   public static final int popupMenuStyle = 0x7f010064;  
  84.   public static final int popupPromptView = 0x7f010060;  
  85.   public static final int progressBarPadding = 0x7f01004e;  
  86.   public static final int progressBarStyle = 0x7f01004c;  
  87.   public static final int prompt = 0x7f01005e;  
  88.   public static final int queryHint = 0x7f01005d;  
  89.   public static final int searchDropdownBackground = 0x7f010029;  
  90.   public static final int searchResultListItemHeight = 0x7f01002a;  
  91.   public static final int searchViewAutoCompleteTextView = 0x7f01002b;  
  92.   public static final int searchViewCloseIcon = 0x7f01002c;  
  93.   public static final int searchViewEditQuery = 0x7f01002d;  
  94.   public static final int searchViewEditQueryBackground = 0x7f01002e;  
  95.   public static final int searchViewGoIcon = 0x7f01002f;  
  96.   public static final int searchViewSearchIcon = 0x7f010030;  
  97.   public static final int searchViewTextField = 0x7f010031;  
  98.   public static final int searchViewTextFieldRight = 0x7f010032;  
  99.   public static final int searchViewVoiceIcon = 0x7f010033;  
  100.   public static final int selectableItemBackground = 0x7f010034;  
  101.   public static final int showAsAction = 0x7f010058;  
  102.   public static final int showDividers = 0x7f010056;  
  103.   public static final int spinnerDropDownItemStyle = 0x7f010035;  
  104.   public static final int spinnerMode = 0x7f01005f;  
  105.   public static final int spinnerStyle = 0x7f010036;  
  106.   public static final int subtitle = 0x7f010041;  
  107.   public static final int subtitleTextStyle = 0x7f010043;  
  108.   public static final int textAllCaps = 0x7f010055;  
  109.   public static final int textAppearanceLargePopupMenu = 0x7f010037;  
  110.   public static final int textAppearanceListItem = 0x7f010038;  
  111.   public static final int textAppearanceListItemSmall = 0x7f010039;  
  112.   public static final int textAppearanceSearchResultSubtitle = 0x7f01003a;  
  113.   public static final int textAppearanceSearchResultTitle = 0x7f01003b;  
  114.   public static final int textAppearanceSmallPopupMenu = 0x7f01003c;  
  115.   public static final int textColorSearchUrl = 0x7f01003d;  
  116.   public static final int title = 0x7f01003e;  
  117.   public static final int titleTextStyle = 0x7f010042;  
  118.   public static final int windowActionBar = 0x7f010050;  
  119.   public static final int windowActionBarOverlay = 0x7f010051;  
  120.   public static final int windowSplitActionBar = 0x7f010052;  
  121.  }  
  122.  public static final class bool   
  123.  {  
  124.   public static final int abc_action_bar_embed_tabs_pre_jb = 0x7f050000;  
  125.   public static final int abc_action_bar_expanded_action_views_exclusive = 0x7f050001;  
  126.   public static final int abc_config_actionMenuItemAllCaps = 0x7f050002;  
  127.   public static final int abc_config_allowActionMenuItemTextWithIcon = 0x7f050003;  
  128.   public static final int abc_config_showMenuShortcutsWhenKeyboardPresent = 0x7f050004;  
  129.   public static final int abc_split_action_bar_is_narrow = 0x7f050005;  
  130.  }  
  131.  public static final class color   
  132.  {  
  133.   public static final int abc_search_url_text_holo = 0x7f060003;  
  134.   public static final int abc_search_url_text_normal = 0x7f060000;  
  135.   public static final int abc_search_url_text_pressed = 0x7f060001;  
  136.   public static final int abc_search_url_text_selected = 0x7f060002;  
  137.  }  
  138.  public static final class dimen   
  139.  {  
  140.   public static final int abc_action_bar_default_height = 0x7f080000;  
  141.   public static final int abc_action_bar_icon_vertical_padding = 0x7f080001;  
  142.   public static final int abc_action_bar_stacked_max_height = 0x7f080002;  
  143.   public static final int abc_action_bar_stacked_tab_max_width = 0x7f080003;  
  144.   public static final int abc_action_bar_subtitle_bottom_margin = 0x7f080004;  
  145.   public static final int abc_action_bar_subtitle_text_size = 0x7f080005;  
  146.   public static final int abc_action_bar_subtitle_top_margin = 0x7f080006;  
  147.   public static final int abc_action_bar_title_text_size = 0x7f080007;  
  148.   public static final int abc_action_button_min_width = 0x7f080008;  
  149.   public static final int abc_config_prefDialogWidth = 0x7f080009;  
  150.   public static final int abc_dropdownitem_icon_width = 0x7f08000a;  
  151.   public static final int abc_dropdownitem_text_padding_left = 0x7f08000b;  
  152.   public static final int abc_dropdownitem_text_padding_right = 0x7f08000c;  
  153.   public static final int abc_panel_menu_list_width = 0x7f08000d;  
  154.   public static final int abc_search_view_preferred_width = 0x7f08000e;  
  155.   public static final int abc_search_view_text_min_width = 0x7f08000f;  
  156.  } 

Dalvik virtual machine

 
Dalvik is the name of a town in Iceland that was Written by Dan Bornstein. The Dalvik Virtual Machine runs the .dex file provided by the dex compiler. Let's see the process. First, the Java class file goes to the Java compiler and this compiler converts the Java file into the class file. Now the dx (Dex Compiler) tool converts the .class file into the .dex file. This .dex file will run on the Dalvik Virtual Machine and then it is converted into the .apk file by the Android asset packaging tools. The following figure shows how the Dalvik Virtual Machine works.
 
Dalvik virtual machine.png


Similar Articles