Where is the R.java file in Android Studio?
Asked Answered
W

14

58

Where is the R.java file in Android Studio?

Wash answered 15/2, 2015 at 1:24 Comment(1)
All you need to do is type R. to see the autocompletion suggestions.Altar
D
52

Based on the new stable release of Android Studio (3.6) we have: enter image description here

So, now to find your generated resource classes you need the following steps:

1) Open your project.

2) Go to your module build path.

3) Open the outputs/apk/debug/app-name-debug.apk file.

4) Choose your classes.dex file.

5) Look at the down placed area and go to your full package path.

6) You can see all bytecoded resource classes. So, scroll down to what you are looking for.

enter image description here

7) Expand the resource class you need to proceed (for example, let it be R.id)

enter image description here

8) Go to you id's.

enter image description here

That's it.

UPDATE:

If you would like to see actual id integer number you should follows steps below:

1) By (7) Go to the resource class you need to proceed and right click to show the context menu

2) Choose "Show Bytecode" to see the flexible dialog "DEX Byte Code for R$id", for example, for id class

enter image description here

3) Scroll down to the actual id to look its number

enter image description here

Dragelin answered 7/4, 2020 at 12:9 Comment(5)
That's the correct answear in 2020 (Android Studio 3.6), but how can I read actual id? like button17 = 52444873 ?Annamariaannamarie
if somebody wonders: "The new Android Gradle Plugin generates the corresponding bytecode directly and does not make the intermediate R.java file." forums.bignerdranch.com/t/…Calicut
Also look at classes2.dex and classes3.dex for your package. If you search an id, probably you won't find it there, because it can belong to another package. See https://mcmap.net/q/329083/-where-is-the-r-java-file-in-android-studio for a short way.Kinchinjunga
For me it was classes2.dex, and classes.dex didn't contain my app package at allCherriecherrita
For me, selecting resources.arsc in the APK gave me a table with the type of resource (id, drawable, color, attr, etc) on the left and on the right the ID shown in the Crash and the Name of the resource.Sandstrom
T
40

Although the current Android Gradle Plugin doesn't generate a R.java anymore you can still inspect the corresponding class file (see Sergey V.`s answer).

However, if you (like probably in most cases) just want to look up the generated IDs for your resources, there is an easier way:

In the project pane on the left hand side switch from Android to Project view using the drop-down at the top. Then navigate to app/build/intermediates/runtime_symbol_list/<insert build type here>/R.txt. This file lists all IDs generated by AGP during the build process.

Taiwan answered 17/4, 2020 at 17:22 Comment(6)
Thanks! A correct answer. It will look like int drawable bonus_item 0x7f0800f1.Kinchinjunga
This is the short and corrrect answerVey
This directory doesn't exist anymore, however stable_resource_ids_file does.Rouvin
@MartinZeitler This might depend on the AGP version used or some flag in your build configuration. I've tested with 8.3.0, and I actually see both directories.Taiwan
The strange thing is, that SingleArtifact.RUNTIME_SYMBOL_LIST reads: Added in 8.3.1... which kind of contradicts the date of your answer.Rouvin
Maybe it just wasn't available as a separate artifact before within AGP. 🤷Taiwan
B
18

I use Android Studio 3.3.2

\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\android\support\constraint\R.java

enter image description here

Beffrey answered 11/3, 2019 at 12:54 Comment(3)
That's right,thanks so much.BTW,I'm using AS 3.5.2.Benefactor
There is no not_namespaced_r_class_sources folder in AS 3.6.1Frances
@Frances Look at answer by Sergey V. down here.Calicut
K
18

As noted above, "The new Android Gradle Plugin generates the corresponding bytecode directly and does not make the intermediate R.java file".

Using the ubuntudroid solution you can find an id also this way. Find R.txt and copy absolute path. Project > app > build > intermediates > runtime_symbol_list > debug > R.txt. Then right click and select Copy Path..., 1. Absolute Path Ctrl+Shift+C.

enter image description here

This way you will obtain a path to R.txt, for instance, "C:\Users\user\AndroidStudioProjects\your_project\app\build\intermediates\runtime_symbol_list\debug\R.txt". Copy the path without R.txt to a text file for future references, for example, with Notepad++.

Press Ctrl+Shift+F to find in directory. Insert an id and the path.

enter image description here

== Old answer ==

Change a project view from Android to Project or Project Files. Find one of these two files.

enter image description here

Then you can revert back to Android view.

Kinchinjunga answered 29/8, 2019 at 13:57 Comment(0)
E
13

//The picture

I use Android Studio 2.3.3. The R.java file is shown in the picture above.

In the left upper side, there is a select list. Select the [project] option so that you can see all the folders and files.

Electrotechnology answered 3/8, 2017 at 17:18 Comment(4)
I feel sorry for the OP. I seriously doubt he/she was asking for a screenshot of the actual R file. The answer should clearly explain how it is generated as well.Zonazonal
There was never a "screenshot of the actual R file" here (whatever that means -- a screenshot of the contents?). There is a screenshot of the R file's location in the directory tree, showing where to find it. This is exactly what the OP asked - "Where is the R file?" not "How is the R file generated?" If you would like an explanation of the latter, feel free to add one, but that's not a defect of this answer.Pitchford
The server in which the picture was deployed to has been removed or is no longer valid. This is up to Stackoverflow to restore back the images. i.sstatic.net/IGLud.jpgElectrotechnology
Sorry, my comment was in reply to user2453382's comment. Your picture looks fine, and when I look at the edit history of the answer, there was never any other screenshot there, so user2453382's comment doesn't seem to make any sense. The link to imgur.com/IGLud.jpg was there before their comment.Pitchford
G
6

R.java is the generated file by ADT or Android studio. It will be located under app\build\generated\source\r directory.

./app/build/generated/source/r/debug/android/support/v7/appcompat/R.java
./app/build/generated/source/r/debug/your/packagename/name/R.java
Genitive answered 15/2, 2015 at 1:43 Comment(1)
there is no directory called r under source. see other answers - the source is no longer generated, only bytecode, if your AGP version is 3.6 or above.Cherriecherrita
K
5
  1. In my project in Android Studio 4.1 enter image description here

  2. R.jar that you can actually unzip resides in app build folder, as follows:

    jar -xf R.jar

enter image description here

  1. Once the jar is unpacked you can find R.java inside of app package: enter image description here
Kiva answered 27/10, 2020 at 12:48 Comment(0)
W
3

I am using Android Studio 2.2.3 , the R.java file is shown in the picture below. Goto in the left upper side there is a selecting list ,

  1. select [package]
  2. Open "App Folder"
  3. com.example.saeedanwar.myapplication;
  4. r

screenshot

Wallinga answered 3/11, 2017 at 3:21 Comment(0)
M
2

If you're using Mac or Linux, try the following command line on your terminal:

find . -name "R.*"

It will print something like:

./app/build/intermediaries/runtime_symbol_list/debug/R.txt
./app/build/intermediaries/compile_and_runtime_not_namespaced_r_class_jar/debug/R.jar
Mess answered 16/2, 2021 at 8:8 Comment(0)
J
1

It is inside app\build\generated\source\r folder

Jarred answered 15/2, 2015 at 1:42 Comment(0)
O
1

This answer will be in a constant state of flux until Android standardize a method of matching their annoying decimal/hexadecimal id references to a tangible resource such as my_layout.xml.

For Android Studio Dolphin | 2021.3.1 Patch 1 have a look at this file:

/project/package/build/intermediates/stable_resource_ids_file/debug/stableIds.txt

It is produced by RUN (not just BUILD). Sample:

layout/mtrl_picker_header_fullscreen = 0x7f0d00de
string/cancel = 0x7f1101f0
style/ThemeOverlay.MaterialComponents.MaterialCalendar = 0x7f1202f3
id/gpxBtn = 0x7f0a0346
Oversoul answered 22/2, 2023 at 1:2 Comment(0)
A
0

Project/app/build/generated/source/r/debug/com.android.'projectname'/R.java

Audrey answered 23/1, 2017 at 5:12 Comment(0)
N
0

--The R.Java that contains your xml layouts and views id's in Android Studio 3.5.3 -- Project/app/build/generated/not_namespaced_r_class_sources/debug/r/com/"your package"/R.java

Nannettenanni answered 21/1, 2020 at 8:7 Comment(0)
S
0

Nowadays, the AGP generates R.class files directly and there's no R.java out-of-the-box. But we can decompile the class files to get a glimpse of R.java's former structure. Note that this method won't show the actual resource IDs, but some of the other answers cover that bit. The steps below are tested on Android Studio Hedgehog | 2023.1.1.

  1. Locate R.jar (there may also be a release folder):

R.jar

  1. Right-click the file (or the debug folder) and from the pop-up menu choose Open In -> Terminal.
  2. Execute, from the terminal, jar -xf R.jar to extract the folders into cwd, which will give you something like this:

R.class

  1. Double-click the R class above and it will open in the editor as decompiled code.

  2. (Optional) remove the newly extracted folders because they will become obsolete when you continue working on the project.

Sicken answered 4/3 at 22:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.