How to find the R file in Android Studio 2020?

3.6k Views Asked by At

I've search on here how to do it but I found sources from 2015 and the layout of Android Studio has changed since then. Where is the R file in Android Studio.enter image description here

5

There are 5 best solutions below

0
On

See Where is the R.java file in Android Studio?.

  1. Turn to Project view and find app/outputs/apk/debug/app-name-debug.apk.

enter image description here

  1. Find your package name among classes*.dex files.

enter image description here

  1. Expand the package and find R$id (see picture 1).

  2. Right-click and press Show Bytecode.

  3. You will see a file where you can find needed id. Click inside the file, press Ctrl+F and paste id.

enter image description here

1
On

R is Generated class in android and after you build your project this class will be create first build your project after that 4 times click on shift button on your keyboard. in new windows search 'R' class and in list find R.java class that's it

https://i.stack.imgur.com/PdC0d.png

0
On

According to the docs; for improving the efficiency and build performance of gradle; the plugin now generates the JAR directly instead of generating intermediate R.java files. In previous gradle plugins; R.java would be generated for all the dependencies which you include in your app.gradle file or external dependencies. These R classes were then compiled alongside the app's other java classes; which would create overheads and unnecessary or redundant compilations thereby slowing down the build performances of the application.

The Android Gradle plugin simplifies the compile classpath by generating only one R class for each library module in your project and sharing those R classes with other module dependencies.

The new optimization that is done may improve build performance for projects with many dependencies significantly, and improve the indexing speed also thus requiring faster and efficient builds in android studio.

When I tried to decompile the R jar file which is located at your_project_directory\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug using jd-gui; I was able to get the R.class implementation containing id's of the Views which I used for my application just like we would get in earlier versions of gradle.(which confirmed the linking.)enter image description here

NOTE:

If your application is using AAPT2; then you can generate the R.java and Proguard rules intermediate files. To get the command syntax; you can use options from aapt2 link command.

1
On

It is present at the location :

ProjectName\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug

In the above directory as R.jar

enter image description here

1
On

The new Android Gradle Plugin generates the corresponding bytecode directly and does not make the intermediate R.java file.

Source

https://android-developers.googleblog.com/2020/02/android-studio-36.html

enter image description here