简体   繁体   English

如何从 android 项目中获取 R.java

[英]How to get R.java from android project

I am trying to get R.java file for my android project.我正在尝试为我的 android 项目获取 R.java 文件。 My android studio setup is as below我的 android 工作室设置如下

Android studio - 4.0
Gradle version - 6.1.1
Android studio gradle plugin version - 4.0.0

Project is building without any erros but when I go in exploper and look for the folder app/build/generated/not_namespaced_r_resources it is not generated.项目正在构建,没有任何错误,但是当我在 exploper 中的 go 并查找文件夹app/build/generated/not_namespaced_r_resources时,它没有生成。 I tried clean and build, Invalidate cache and restart but it is not working.我尝试清理并构建,使缓存无效并重新启动,但它不起作用。 How can I get the R.java file?如何获取 R.java 文件?

This is the build log这是构建日志

Executing tasks: [:app:assembleDebug] in project D:\abc\asdf

> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:processDebugGoogleServices UP-TO-DATE
> Task :app:mergeDebugResources UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:extractDeepLinksDebug UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:processDebugResources UP-TO-DATE
> Task :app:compileDebugJavaWithJavac UP-TO-DATE
> Task :app:compileDebugSources UP-TO-DATE
> Task :app:mergeDebugShaders UP-TO-DATE
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets UP-TO-DATE
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:mergeDebugJavaResource UP-TO-DATE
> Task :app:checkDebugDuplicateClasses UP-TO-DATE
> Task :app:mergeLibDexDebug UP-TO-DATE
> Task :app:desugarDebugFileDependencies UP-TO-DATE
> Task :app:mergeExtDexDebug UP-TO-DATE
> Task :app:dexBuilderDebug UP-TO-DATE
> Task :app:mergeProjectDexDebug UP-TO-DATE
> Task :app:mergeDebugJniLibFolders UP-TO-DATE
> Task :app:validateSigningDebug UP-TO-DATE
> Task :app:mergeDebugNativeLibs UP-TO-DATE
> Task :app:stripDebugDebugSymbols NO-SOURCE
> Task :app:packageDebug UP-TO-DATE
> Task :app:assembleDebug UP-TO-DATE

BUILD SUCCESSFUL in 1s
23 actionable tasks: 23 up-to-date

I have referred below SO thread and tried everything but nothing works.我在下面提到了 SO 线程并尝试了所有方法,但没有任何效果。

Where is the R.java file in Android Studio? Android Studio 中的 R.java 文件在哪里?

the R.java file in android studio 3.4 android studio 3.4 中的 R.java 文件

I can't find R.java folder, has it been renamed in version 3.3? 我找不到 R.java 文件夹,在 3.3 版中是否已重命名?

Is there any known bug with this?这有什么已知的错误吗?

Newer versions of Android Studio & the Gradle plugin no longer generates an actual R.java file.较新版本的 Android Studio 和 Gradle 插件不再生成实际的 R.Z93F725A074238FE1C889F4 文件。
I've read an actual post about it somewhere, but can't find it at the moment, maybe someone else does.我在某处读过一篇关于它的实际帖子,但目前找不到,也许其他人找到了。

The needed bytecode is generated directly, and is hidden behind the scenes.需要的字节码是直接生成的,并且隐藏在幕后。

That is also the reason that you can't use "Go to declaration or usages" on the "R" part of "R.string.my_text", the class simply does not exist.这也是您不能在“R.string.my_text”的“R”部分使用“转到声明或用法”的原因,class 根本不存在。

Newer versions of Android Studio & the Gradle plugin no longer generates an actual R.java file.较新版本的 Android Studio 和 Gradle 插件不再生成实际的 R.Z93F725A074238FE1C889F4 文件。

But you can specify the AAPT parameter to actively generate但是可以指定AAPT参数来主动生成

android {
    ...
    aaptOptions {
        additionalParameters "--java", "$buildDir/generated/r"
    }
    ...
}
    

start from Android Studio 3.6.从 Android Studio 3.6 开始。 Based on this post: Can't find R.java in Android Studio 3.6(newest release) .基于这篇文章: Can't find R.java in Android Studio 3.6(最新版本)

Additionally, Android Gradle plugin has made significant performance improvement for annotation processing/KAPT for large projects.此外,Android Gradle 插件对大型项目的注释处理/KAPT 进行了显着的性能改进。 This is caused by AGP now generating R class bytecode directly, instead of.java files.这是因为 AGP 现在直接生成 R class 字节码,而不是.java 文件。

source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM