How to find the R file in Android Studio 2020?
Asked Answered
C

5

7

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

Clavier answered 10/5, 2020 at 22:39 Comment(3)
Since there have been many Android Studio versions published so far in 2020... what version are you using?Arkhangelsk
Android Studio 3.6.3Clavier
It does not always seem to be generated in source form. I do not know the rules for which modules do and do not have R.java generated (other than it is not tied to whether Kotlin is involved). I assume it is related to some specific Gradle settings. If it is generated, I am seeing it in the module's` build/generated/not_namespaced_r_class_sources/debug/processDebugResources/r/your/application/id/R.java, where your/application/id/ would be directories based on your application ID.Arkhangelsk
F
12

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.

Forespent answered 13/5, 2020 at 12:15 Comment(0)
S
5

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

Strap answered 18/5, 2020 at 4:13 Comment(1)
But sometimes it still does generate R.java, as I noted in a comment on the question.Arkhangelsk
T
3

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

Twentyfourmo answered 13/5, 2020 at 11:35 Comment(1)
i am having the namespace error. whenever i create android library i find namespace error which lead me to this error. how can i solve namespace error.Lucite
R
3

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

Redbird answered 16/3, 2021 at 11:35 Comment(0)
K
-4

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.sstatic.net/PdC0d.png

Karole answered 13/5, 2020 at 11:15 Comment(1)
Your screenshot is showing the platform implementation of R, not a project's generated R. Your answer also does not show where the generated R.java would be on the filesystem, and your answer does not explain the rules by which R.java is or is not generated.Arkhangelsk

© 2022 - 2024 — McMap. All rights reserved.