问题
I'm just trying to learn android development, and am using the latest version of android studio, however, I cannot find the R.java
file in my folder tree view:
I've also cleaned and rebuilt my project but still, I can see neither the .../source/R
folder nor the R.java
file.
回答1:
Try this:
\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\<package_name_tree>\R.java
package_name_tree means : If package is a.b.c
the goto: /a/b/c/R.java
回答2:
i'm learning Android apps as well and i was searching for the R class like you
but i found out that in new versions it dosn;t exit
you can read about here https://developer.android.com/studio/releases/gradle-plugin
Faster R class generation for library projects: Previously, the Android Gradle plugin would generate an R.java file for each of your project's dependencies and then compile those R classes alongside your app's other classes. The plugin now generates a JAR containing your app's compiled R class directly, without first building intermediate R.java classes. This optimization may significantly improve build performance for projects that include many library subprojects and dependencies, and improve the indexing speed in Android Studio.
回答3:
From this tutorial.
Android
R.java
is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory.If you create any component in the
activity_main.xml
file, id for the corresponding component is automatically created in this file. This id can be used in the activity source file to perform any action on the component.
Hence you should not worry about the R.java
file, as this will be generated automatically when you will build the project. The R.java
might not be generated in some cases though, mostly if there is an error in your layout files. Check your layout files and look for errors in there. Fix the error and you should be able to get the reference of the R.java
file in your activity.
To import the R.java
file in your activity, use the automatic import option. In most cases, Alt + Enter
does the trick for you for automatic import.
If you are still having trouble finding the R.java
, you might consider invalidating the cache of the Android Studio from File -> Invalidate Caches/Restart
.
Hope that helps!
回答4:
As of gradle plugin version 4.0.0 and Android Studio 4.0
R.java is now generated as a compiled R.jar file in this directory: project_dir/app/build/intermediates/compile_and_runtime_not_namespaced_r_class_jar/debug/R.jar
You can use a java decompiler like jd-gui if you want to view the source of the R.java that should have been generated in previous versions of Android Studio
来源:https://stackoverflow.com/questions/57398794/the-r-java-file-in-android-studio-3-4