简体   繁体   中英

How to get R.java from android project

I am trying to get R.java file for my android project. My android studio setup is as below

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. I tried clean and build, Invalidate cache and restart but it is not working. How can I get the R.java file?

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.

Where is the R.java file in Android Studio?

the R.java file in android studio 3.4

I can't find R.java folder, has it been renamed in version 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.
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.

Newer versions of Android Studio & the Gradle plugin no longer generates an actual R.java file.

But you can specify the AAPT parameter to actively generate

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

start from Android Studio 3.6. Based on this post: Can't find R.java in Android Studio 3.6(newest release) .

Additionally, Android Gradle plugin has made significant performance improvement for annotation processing/KAPT for large projects. This is caused by AGP now generating R class bytecode directly, instead of.java files.

source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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