Android Studio: How to attach javadoc

前端 未结 10 1839
一向
一向 2020-12-04 09:47

It might be very trivial question, But I couldn\'t find any option to attach javadoc/source with local jar dependencies (in libs folder) in android project. I can\'t believe

相关标签:
10条回答
  • 2020-12-04 10:28

    I had problem with answer from Matyas that I wasn't seeing my local .jar library in the External Libraries list, because it only show maven attached libs.

    Solution is mentioned here: https://code.google.com/p/android/issues/detail?id=73087#c26

    1. Right click on the "Structure" tab and check "Split Mode" (so you can open both "Project" and "Structure" tabs at same time).
    2. Open both "Project" and "Structure" tabs at the same time.
    3. In "Project" tab select "Android" perspective and then select your module folder (e.g. "app")
    4. In "Structure" window you should now see list of all libraries, including your local *.jar

    Continue as in answer from Matyas:

    1. Right click on wanted library and select "Library Properties..."
    2. If you have *.jar with javadocs locally, you can press "add" button (green "+") and search for the file on your disk (you don't have to type "file://" path manually).
    0 讨论(0)
  • 2020-12-04 10:32

    Still a current issue as of my posting it seems:

    https://code.google.com/p/android/issues/detail?id=73087

    0 讨论(0)
  • 2020-12-04 10:32

    I wasted so much time on this too...

    Here's a gradle task which finds source and javadoc by location/naming convention, and registers them in the .idea files on sync. It belongs in the root gradle file's allProjects section. As-is, it expects to find [projectname]/libs/lib.jar next to lib-sources.jar and/or lib-javadoc.jar. Also, as noted in comments, if your javadocs not pathed at "/" inside the jar, you may need to change the script to add "docs/html" (for example) at the end of "jar://$doc!/".

    allprojects {
    
        task addJavaDoc {
            afterEvaluate {
                // Specify paths, this will be run per non-root project
                def projectDir = project.getProjectDir().getCanonicalPath()
                def rootDir = project.getRootDir().getCanonicalPath()
                def lib = projectDir + '/libs'
    
                // println lib // Uncomment this to troubleshoot
                // Get any jar dependencies register in the lib folder
                fileTree(include: ['*.jar'], exclude: ['*-source.jar', '*-javadoc.jar'], dir: lib ).each { File jar ->
                    def jarName = jar.getName()
                    def moduleName = jarName.substring(0, jarName.lastIndexOf("."))
                    // IntelliJ does this to file names when making the xml files
                    def escapedName = moduleName.replace("-", "_").replace(".", "_")
                    def xmlFile = "$rootDir/.idea/libraries/${escapedName}.xml"
                    // println xmlFile // Uncomment this to troubleshoot
                    if (new File(xmlFile).exists()) {
                        ['javadoc', 'sources'].each {String docType ->
                            // Get sources or java doc by naming convention, (expects name-sources or name-javadoc
                            def doc = "$lib/$moduleName-${docType}.jar"
                            // println doc // Uncomment this to troubleshoot
                            if(new File(doc).exists()) {
                                def xml = new XmlParser().parse(xmlFile);
                                def xmlTag = docType.toUpperCase()
                                // Perform xml replacement by convention
                                xml.library[xmlTag].replaceNode {
                                    "$xmlTag" {
                                        root(url: "jar://$doc!/")
                                    }
                                }
                                // Write out changes
                                new XmlNodePrinter(new PrintWriter(new FileWriter(xmlFile))).print(xml)
                                // Notify that changes worked
                                println "Fixed up reference to $doc"
                            }
                        }
                    }
                }
            }
        }
    }
    

    Also, if you are using jcenter or mavencentral, javadocs and sources should work for downloaded jars without using that task, but you may have to add this in each non-root gradle file:

    apply plugin: 'idea'
    
    idea{
        module {
            downloadJavadoc = true
            downloadSources = true
        } 
    }
    
    0 讨论(0)
  • 2020-12-04 10:33

    There is a solution, This procedure take place through terminal ,

    I have tested solution in MAC OS.

    1) Move to your project folder

    2) ls -al (to show hidden files)

    3) Move to .idea folder , Command : cd .idea

    4) Move to libraries folder , Command : cd libraries/

    5) Now you can see list of all xml files for your libs or jars. Edit it like , vi open androidasync_2_1_7.xml

    6) In the editor screen , For inserting

    Press i 
    

    Now you see <SOURCES /> tag we have to provide a path here like,

    <SOURCES>
      <root url="file://$PROJECT_DIR$/androidasync/src/main/java" />
    </SOURCES>
    

    For exiting

    Press Esc
    
        :wq //for exiting and saving
        :q! //for exiting without saving
    

    7) Restart Android studio (Sometime it needed also sync gradle).

    0 讨论(0)
提交回复
热议问题