49

Where is the R.java file in Android Studio? Can someone please help with this? I already tried google for the answer but can't find any solution.

TheChessDoctor
  • 621
  • 1
  • 5
  • 8

12 Answers12

44

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

Sergey V.
  • 921
  • 2
  • 12
  • 23
  • 1
    That's the correct answear in 2020 (Android Studio 3.6), but how can I read actual id? like button17 = 52444873 ? – Karol Żygłowicz Apr 08 '20 at 15:39
  • 2
    if somebody wonders: "The new Android Gradle Plugin generates the corresponding bytecode directly and does not make the intermediate R.java file." https://forums.bignerdranch.com/t/cant-find-r-java-in-android-studio-3-6-newest-release/17266 – bomben Apr 12 '20 at 08:00
  • 1
    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://stackoverflow.com/a/61277205/2914140 for a short way. – CoolMind Sep 23 '20 at 09:48
24

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.

ubuntudroid
  • 3,395
  • 6
  • 34
  • 55
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

Ahmed Ashour
  • 4,462
  • 10
  • 33
  • 49
OulinaArt
  • 314
  • 2
  • 12
13

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.

CoolMind
  • 22,602
  • 12
  • 167
  • 196
12

//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.

0xCursor
  • 2,230
  • 4
  • 14
  • 32
Niamatullah Bakhshi
  • 1,361
  • 13
  • 26
  • 2
    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. – Rakib Jan 03 '19 at 07:46
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
alijandro
  • 10,957
  • 2
  • 48
  • 67
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

Pang
  • 9,073
  • 146
  • 84
  • 117
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
Anggrayudi H
  • 14,378
  • 11
  • 50
  • 80
1

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

Patrick Mevzek
  • 9,491
  • 15
  • 33
  • 49
Belal Khan
  • 1,884
  • 2
  • 20
  • 30
1
  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
AlexPes
  • 852
  • 11
  • 17
0

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

Shubhamhackz
  • 5,977
  • 5
  • 42
  • 65
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

Bad0
  • 123
  • 1
  • 10