Search code examples
javaandroidjavadoc

Android Studio Javadoc Generation error: cannot find symbol R


I am trying to generate javadocs for a larger android project - using android studios built-in "Tools > Generate JavaDoc". I have tried different scopes (my module, a custom scope containing only the java files I created, Project Files, ...) but everytime there is a class included which uses import com.my-app.R; or a generated class such as SomeFragmentBinding for ViewBinding, I get an

error: cannot find symbol from javadoc...

Apart from this problem the usual building and executing of the app is completely successful and works like a charm, although I get some some warnings regarding my database layout. Also I am using Hilt for Dependency Injection, but I don't really think that is related?

Now I am a complete noob using gradle and my attempts to configure the javadoc task myself have failed - and from what I have found online this should generally work out-of-the-box.


Solution

  • Had the same issue. Here is how I solved it:

    1. In your build.gradle file, add this line

      implementation files(pathtosdk)

    2. Go to Tools -> Generate Javadocs. In the command line args, add this line

      -sourcepath pathtosdk

    To find the pathtosdk;

    • Change from Android to Project.
    • Open up External Libraries
    • Open up the directory that's named like "Android "
    • You should see an android.jar file
    • Right click and copy the absolute path. That is your pathtosdk.