创建包含javadoc和sources的Android库AAR

时间:2014-10-23 15:30:04

标签: android gradle android-studio android-gradle

我的团队正在开发一个Android库,用于我们开发的一些示例应用程序。该库创建为AAR文件。这是它的build.gradle

apply plugin: 'com.android.library'
apply from: 'deploy.gradle'

android {
    compileSdkVersion 20
    buildToolsVersion '20.0.0'
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'LICENSE'
        exclude 'NOTICE'
    }
    defaultConfig {
        // Excluded for brevity
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
        // if true, check all issues, including those that are off by default
        checkAllWarnings true
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v13:20.0.+'
    compile 'com.google.android.gms:play-services:5.+'
    compile 'com.squareup.retrofit:retrofit:1.6.1'
}

以下是应用程序build.gradle的依赖项部分

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile ('com.mycompany.myapp:0.6.5-SNAPSHOT@aar') {
        transitive = true
        downloadJavadoc = true
        downloadSources = true
    }
}

我可以使用所有的lib类,但是我看不到Javadocs和源代码。如何打包我的AAR,使其包含源代码和Javadoc?

1 个答案:

答案 0 :(得分:10)

似乎暂时无法完成。但是,在deploy.gradle中添加这些gradle任务,会创建-javadoc.jar和-sources.jar。

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
}

task androidJavadocsJar(type: Jar) {
    classifier = 'javadoc'
    baseName = artifact_id
    from androidJavadocs.destinationDir
}

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

artifacts {
//    archives packageReleaseJar
    archives androidSourcesJar
    archives androidJavadocsJar
}

之后,需要手动导入源和javadoc。根据{{​​3}} 和this thread它们无法自动导入。