简体   繁体   中英

Android - failed to generate Javadoc with Android Studio Bumblebee

I'm trying to generate Javadoc using latest Android Studio via built in tool: Tools=>Generate Javadoc... Whatever I choose from a tool's parameters window there are a lot of errors thrown, regarding to the scope I choose it varies from 50 to 100 and all of them related to Android OS or Dalvik VM. Here are some of them:

error: package android.util does not exist

error: cannot find symbol... symbol:class Context

error: package android.app does not exist

error: package dalvik.system does not exist

Target Android SDK is 31. Latest Java release installed. Did someone experienced the same issue? What am I doing wrong? Thanks in advance.

First of all, sorry for my English (I use Google translation). I just spent 5 days on this error and found a solution that works (for me...).

The latest versions of Android Studio (including Bumblebee) do not generate technical documentation correctly. Here is the procedure to generate it correctly.

In Android Studio, open the project. First of all, identify all R imports and just replace R with * (example: import com.example.coah.*). Start by following the classic javadoc generation process:

  • Tools > Generate JavaDoc
  • scope: Module
  • uncheck "Include JDK and library sources in -sourcepath"
  • Output directory: give the path to the folder that will receive the doc (create this folder beforehand outside the project folder)
  • Other command line arguments: -encoding utf8 -docencoding utf8 -charset utf8

Make OK. Normally documentation generation failed with "exit code 4". In the output window, at the very top and on the very right (drag the horizontal scrollbar), click on "@C:\Users\xxx\AppData\Local\Temp\javadoc_args":

You get a preview of the contents of the file.

Copy the content and paste it into a text file. Open the file. It starts with "-classpath" followed by quotes and a list of file paths. The problem comes from the fact that in this list, the android.jar file is missing, which is normally found in: C:\Users\xxx\AppData\Local\Android\Sdk\platforms\android-32\android.jar Check the presence of this file in the user folder (replace xxx by the name of the user): it may not be android-32 but android-30, or other. Once the right path has been found, it must be added to the classpath, in the first position, just after the quotes and without forgetting to add a ";" at the end to separate it from the next path. Please note that the "" must also be replaced by "/".

Save file. Open a command window in admin mode and go to the project folder, src\app\main\java folder. Still in the javadoc output window in Android Studio, copy the first complete command line (which generates the doc) and paste it into the command window, replacing just what is after @ with the path to the file text that has just been created (which contains, among other things, the classpath).

It is possible that there are errors and warnings, but the doc is still generated.

Emds

Emds solution helped a lot over here, using it we can solve this problem more easily.

As they said here, main problem is android.jar file is not being included in classpath somehow. So to resolve this we can simply copy path of android.jar (with name too) and then generate a dependency in project for it.

  • To do this go to File -> Project Structure -> Dependencies

  • There click on + sign in "All Dependencies" section and select "Jar/AAR Dependency".

  • Then select "app" for module and in next screen enter android.jar path (path you copied before) and click OK.

  • Build gradle again and generate Javadoc. It should do the trick.

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