2016-03-07 6 views
5

मेरे पास एंड्रॉइड लाइब्रेरी प्रोजेक्ट है जो अन्य एंड्रॉइड लाइब्रेरी प्रोजेक्ट्स पर निर्भर करता है। मुझे पुस्तकालय के लिए जावाडोक उत्पन्न करने की ज़रूरत है, लेकिन यह विफल हो जाती है क्योंकि ग्रेडल .aar स्थानों पर जावाडोक क्लासपाथ पथ डालता है लेकिन जावडोक अपेक्षा करता है .jar फ़ाइलें।एंड्रॉइड लाइब्रेरी के लिए जावाडोक कैसे उत्पन्न करें जब इसकी निर्भरताएं भी हैं जो अरबी पुस्तकालय भी हैं?

सरलीकृत Gradle फ़ाइल:

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.2" 

    configurations { 
     javadocDeps 
    } 

    defaultConfig { 
     minSdkVersion 7 
     targetSdkVersion 23 
     versionCode 1 
     versionName "0.1.0" 
    } 
} 

dependencies { 
    compile 'com.android.support:support-v4:23.2.0' 
    compile 'com.android.support:appcompat-v7:23.2.0' 
    compile 'com.nineoldandroids:library:2.4.0' 
    compile 'com.annimon:stream:1.0.7' 
    javadocDeps 'com.android.support:support-annotations:23.2.0' 
    javadocDeps 'com.nineoldandroids:library:2.4.0' 
    javadocDeps 'com.android.support:support-v4:23.2.0' 
} 

task sourcesJar(type: Jar) { 
    from android.sourceSets.main.java.srcDirs 
    classifier = 'sources' 
}  

task javadoc(type: Javadoc, dependsOn: explodeAars) { 
    source = android.sourceSets.main.java.srcDirs 
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 
    classpath += configurations.javadocDeps 
} 

task javadocJar(type: Jar, dependsOn: javadoc) { 
    classifier = 'javadoc' 
    from javadoc.destinationDir 
} 

artifacts { 
    archives javadocJar 
    archives sourcesJar 
} 

3 समाधान संभव:

1) किसी भी तरह हर आर पुस्तकालय यह/intermidiates निर्माण निर्भर करता है से classpath पथ classes.jar में जोड़ने के लिए/विस्फोट-आर/पुस्तकालय /version/jars/classes.jar मुझे नहीं पता कि इन पथों को जावाडोक कार्य में कैसे शामिल किया जाए।

2) मैन्युअल रूप से आर फ़ाइल से classes.jar खोल और उन्हें जावाडोक कार्य

3) बहुत गंदे हैक के classpath के लिए जोड़ - पुस्तकालय के लिए hardcoded रास्तों - लेकिन मुझे लगता है कि यह इतना गलत है।

ग्रेडल डीएसएल के साथ 1 या 2 कैसे प्राप्त करें?

+0

क्या आप एंड्रॉइड स्टूडियो का उपयोग कर रहे हैं? टूल में है> जावाडॉक को एक सुविधाजनक टूल जेनरेट करने के लिए जवाडोक को चुनने के लिए जेनरेट करें। – xiaomi

+0

मैं एंड्रॉइड स्टूडियो का उपयोग करता हूं लेकिन यह कार्य दूरस्थ जेनकींस उदाहरण पर स्वचालित रूप से किया जाना चाहिए। यह कार्य लाइब्रेरी को jcenter/mavenCentral – curioushikhov

उत्तर

4

@rve का समाधान अब एंड्रॉइड स्टूडियो 2.3/ग्रैडल 3.3 पर टूट गया है क्योंकि exploded-aar अब मौजूद नहीं है (बिल्ड निर्देशिका के अंदर कोई विकल्प नहीं है)।

यदि आपके द्वारा संचालित आर्य आपके प्रोजेक्ट में एक मॉड्यूल नहीं है, तो आपको क्लासपाथ में संदर्भित करने से पहले कक्षाओं को निकालने की आवश्यकता होगी (मूल रूप से intermediates/exploded-aar मैन्युअल रूप से फिर से बनाएं)।

तो आर आप पर निर्भर बस अपनी परियोजना में एक और मॉड्यूल है आप भी अपने जावाडोक कार्य है कि मॉड्यूल के संकलन कार्य पर निर्भर करता है बनाने के लिए और संदर्भ कि मॉड्यूल के intermediates/classes/release (यदि आप जावाडोक उदाहरण के लिए assembleRelease पर निर्भर करता है बनाने के) कर सकते हैं । उस वर्कअराउंड का एक उदाहरण: https://github.com/Microsoft/mobile-center-sdk-android/pull/345/files

मैं वास्तव में चाहता हूं कि कोई बेहतर समाधान के साथ आता है।

5

एंड्रॉयड स्टूडियो के लिए यह केवल काम करता है 2.3 और/या Gradle से अधिक उम्र से अधिक उम्र 3,3

जार AARs से आप जावाडोक कार्य के लिए निम्न doFirst जोड़ सकते हैं जोड़ने के लिए:

task javadoc(type: Javadoc) { 
    source = android.sourceSets.main.java.srcDirs 
} 
.doFirst { 
    classpath += fileTree(dir: "$buildDir/intermediates/exploded-aar/", include:"**/classes.jar") 
} 

यह सभी एएआर से जावाडोक क्लासपाथ में सभी .jar फ़ाइलों को जोड़ देगा। (आपके प्रस्तावित समाधानों से विकल्प 1)

+4

पर अपलोड करने के लिए उपयोग किया जाता है यह अब एंड्रॉइड स्टूडियो 2.3/ग्रैडल 3.3 के साथ टूटा हुआ है। विस्फोट-एआर निर्देशिका अब मौजूद नहीं है। –

+0

एक साइड नोट: यह एंड्रॉइड ग्रेडल प्लगइन 2.3.3 – NemoOudeis

6

मैं classes.jar प्रत्येक आर फ़ाइल में निकालने, और जावाडोक कार्य के classpath में जोड़कर Guillaume Perrot के समाधान को स्वचालित करने में कामयाब रहे।

यह आर निर्भरता और Android स्टूडियो 2.3 और Gradle 3,3

import java.nio.file.Files 
import java.nio.file.Paths 
import java.io.FileOutputStream 
import java.util.zip.ZipFile 

task javadoc(type: Javadoc) { 
    source = android.sourceSets.main.java.srcDirs 
    classpath += configurations.compile 
    classpath += configurations.provided 

    afterEvaluate { 
     // Wait after evaluation to add the android classpath 
     // to avoid "buildToolsVersion is not specified" error 
     classpath += files(android.getBootClasspath()) 

     // Process AAR dependencies 
     def aarDependencies = classpath.filter { it.name.endsWith('.aar') } 
     classpath -= aarDependencies 
     aarDependencies.each { aar -> 
      // Extract classes.jar from the AAR dependency, and add it to the javadoc classpath 
      def outputPath = "$buildDir/tmp/aarJar/${aar.name.replace('.aar', '.jar')}" 
      classpath += files(outputPath) 

      // Use a task so the actual extraction only happens before the javadoc task is run 
      dependsOn task(name: "extract ${aar.name}").doLast { 
       extractEntry(aar, 'classes.jar', outputPath) 
      } 
     } 
    } 
} 

// Utility method to extract only one entry in a zip file 
private def extractEntry(archive, entryPath, outputPath) { 
    if (!archive.exists()) { 
     throw new GradleException("archive $archive not found") 
    } 

    def zip = new ZipFile(archive) 
    zip.entries().each { 
     if (it.name == entryPath) { 
      def path = Paths.get(outputPath) 
      if (!Files.exists(path)) { 
       Files.createDirectories(path.getParent()) 
       Files.copy(zip.getInputStream(it), path) 
      } 
     } 
    } 
    zip.close() 
} 
+0

ग्रेट जॉब के साथ लाइब्रेरी प्रोजेक्ट्स के लिए काम नहीं करता है! ऐसा लगता है कि मेरे लिए अच्छा काम करता है! ग्रेडल 3.3 का उपयोग करना। –

+0

यह मेरे लिए काम नहीं करता है, लेकिन मैं कैनरी चैनल (एंड्रॉइड स्टूडियो 3.0-बीटा 7) में ग्रेडल प्लगइन 3.0 का उपयोग कर रहा हूं। मुझे संकलित करने के लिए "प्रदत्त" कॉन्फ़िगरेशन को हटाना पड़ा, लेकिन परिणाम पहले जैसा है - जावाडोक पीढ़ी विफल हो जाती है क्योंकि बाहरी निर्भरता हल नहीं होती है। – JHH

+0

com.android.tools.build:gradle:3.0.0-beta7 और इसलिए gradle-4.1 के साथ, मुझे कई अलग-अलग समस्याएं मिलती हैं। सबसे पहले, java.nio कक्षाओं में से कुछ उपलब्ध नहीं हैं, इसलिए मैं आपके पथ को 'पथ' और 'फ़ाइलें' के बिना पुनः लिखता हूं। अगली समस्या यह थी कि नई कॉन्फ़िगरेशन 'एपीआई' और 'कार्यान्वयन' हल करने योग्य नहीं हैं, इसलिए मुझे 'संकलन' निर्भरताओं का उपयोग करने का सहारा लेना पड़ा। ऐसा करने के बाद भी यह विफल रहता है क्योंकि इसे अपनी खुद की आर कक्षा नहीं मिल सकती है। मैन्युअल रूप से जोड़ने/निर्माण/जेनरेट/स्रोत/आर/डीबग करने के बाद मुझे एक कामकाजी जावाडोक मिला। लेकिन मुझे वास्तव में काम करने के नए निर्देशों की आवश्यकता है .. – JHH

1

मैं नए एंड्रॉयड स्टूडियो 3.0-beta7 चला रहा हूँ, और उपयोग करने के लिए @ nicopico का जवाब करने की कोशिश की आर मॉड्यूल के लिए काम करने लगता है, लेकिन यह विफल रहा है कई अलग-अलग त्रुटियों के साथ, इसलिए यहां इसका एक अनुकूलन है जो गैर-मौजूद java.nio उपयोगिताओं पर भरोसा नहीं करता है।

task javadoc(type: Javadoc) { 
    failOnError false 
    source = android.sourceSets.main.java.srcDirs 
    // Also add the generated R class to avoid errors... 
    // TODO: debug is hard-coded 
    source += "$buildDir/generated/source/r/debug/" 
    // ... but exclude the R classes from the docs 
    excludes += "**/R.java" 

    // TODO: "compile" is deprecated in Gradle 4.1, 
    // but "implementation" and "api" are not resolvable :(
    classpath += configurations.compile 

    afterEvaluate { 
     // Wait after evaluation to add the android classpath 
     // to avoid "buildToolsVersion is not specified" error 
     classpath += files(android.getBootClasspath()) 

     // Process AAR dependencies 
     def aarDependencies = classpath.filter { it.name.endsWith('.aar') } 
     classpath -= aarDependencies 
     aarDependencies.each { aar -> 
      System.out.println("Adding classpath for aar: " + aar.name) 
      // Extract classes.jar from the AAR dependency, and add it to the javadoc classpath 
      def outputPath = "$buildDir/tmp/exploded-aar/${aar.name.replace('.aar', '.jar')}" 
      classpath += files(outputPath) 

      // Use a task so the actual extraction only happens before the javadoc task is run 
      dependsOn task(name: "extract ${aar.name}").doLast { 
       extractEntry(aar, 'classes.jar', outputPath) 
      } 
     } 
    } 
} 

// Utility method to extract only one entry in a zip file 
private def extractEntry(archive, entryPath, outputPath) { 
    if (!archive.exists()) { 
     throw new GradleException("archive $archive not found") 
    } 

    def zip = new java.util.zip.ZipFile(archive) 

    zip.entries().each { 
     if (it.name == entryPath) { 
      def path = new File(outputPath) 

      if (!path.exists()) { 
       path.getParentFile().mkdirs() 

       // Surely there's a simpler is->os utility except 
       // the one in java.nio.Files? Ah well... 
       def buf = new byte[1024] 
       def is = zip.getInputStream(it) 
       def os = new FileOutputStream(path) 
       def len 

       while ((len = is.read(buf)) != -1) { 
        os.write(buf, 0, len) 
       } 
       os.close() 
      } 
     } 
    } 
    zip.close() 
} 

यह मुझे परेशान है कि हम एक पुस्तकालय के लिए एक पागल जावाडोक निर्माण करने के लिए यह सब कोड की जरूरत है, लेकिन कम से कम मैं इस काम के मिला है। हालांकि, मुझे config.api और config.implementation के लिए वर्कअराउंड खोजने की आवश्यकता नहीं है।

+0

अलग प्रश्न भी पूछा गया: https://stackoverflow.com/questions/46810769/how-to-get-dependencies-from-a-gradle-plugin-using-api-or-implementation-dir – JHH

संबंधित मुद्दे

 संबंधित मुद्दे