简体   繁体   English

Android - 无法使用 Android Studio Bumblebee 生成 Javadoc

[英]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.我正在尝试通过内置工具使用最新的 Android Studio 生成 Javadoc:工具 => 生成 Javadoc... 无论我从工具的参数 window 中选择什么,都会引发很多错误,关于 Z31A1FD140BE4BEF2D11E121EC9 不同到 100 并且所有这些都与 Android OS 或 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.目标 Android SDK 为 31。安装了最新的 Java 版本。 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...).我刚刚在这个错误上花了 5 天时间,并找到了一个可行的解决方案(对我来说......)。

The latest versions of Android Studio (including Bumblebee) do not generate technical documentation correctly.最新版本的 Android Studio(包括 Bumblebee)无法正确生成技术文档。 Here is the procedure to generate it correctly.这是正确生成它的过程。

In Android Studio, open the project.在 Android Studio 中,打开项目。 First of all, identify all R imports and just replace R with * (example: import com.example.coah.*).首先,识别所有 R 导入并将 R 替换为 *(例如:import com.example.coah.*)。 Start by following the classic javadoc generation process:首先遵循经典的 javadoc 生成过程:

  • Tools > Generate JavaDoc工具 > 生成 JavaDoc
  • scope: Module scope:模块
  • uncheck "Include JDK and library sources in -sourcepath"取消选中“在 -sourcepath 中包含 JDK 和库源”
  • Output directory: give the path to the folder that will receive the doc (create this folder beforehand outside the project folder) Output 目录:给出将接收文档的文件夹的路径(事先在项目文件夹之外创建此文件夹)
  • Other command line arguments: -encoding utf8 -docencoding utf8 -charset utf8其他命令行arguments:-encoding utf8 -docencoding utf8 -charset utf8

Make OK.确定。 Normally documentation generation failed with "exit code 4".通常,文档生成失败并显示“退出代码 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":在 output window 中,在最顶部和最右侧(拖动水平滚动条),单击“@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.它以“-classpath”开头,后跟引号和文件路径列表。 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. 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用户文件夹中是否存在此文件(将 xxx 替换为用户名):它可能不是 android-32 而是 android-30 或其他。 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 ";"找到正确的路径后,必须将其添加到类路径中,在第一个 position 中,就在引号之后,并且不要忘记添加“;” 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.在管理员模式下打开命令 window 和 go 到项目文件夹 src\app\main\java 文件夹。 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). 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除其他外,还包含类路径)。

It is possible that there are errors and warnings, but the doc is still generated.可能存在错误和警告,但仍会生成文档。

Emds EMDS

Emds solution helped a lot over here, using it we can solve this problem more easily. Emds 解决方案在这里帮了很多忙,使用它我们可以更轻松地解决这个问题。

As they said here, main problem is android.jar file is not being included in classpath somehow.正如他们在这里所说,主要问题是 android.jar 文件以某种方式未包含在类路径中。 So to resolve this we can simply copy path of android.jar (with name too) and then generate a dependency in project for it.所以要解决这个问题,我们可以简单地复制 android.jar 的路径(也有名称),然后在项目中为它生成一个依赖项。

  • To do this go to File -> Project Structure -> Dependencies为此,go 到文件 -> 项目结构 -> 依赖项

  • There click on + sign in "All Dependencies" section and select "Jar/AAR Dependency".在“所有依赖项”部分和 select“Jar/AAR 依赖项”中单击 + 号。

  • Then select "app" for module and in next screen enter android.jar path (path you copied before) and click OK.然后 select 模块的“应用程序”,在下一个屏幕中输入 android.jar 路径(您之前复制的路径)并单击确定。

  • Build gradle again and generate Javadoc.再次构建 gradle 并生成 Javadoc。 It should do the trick.它应该可以解决问题。

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

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