1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
apply plugin: 'com.android.library'
def vispVersionName = "@VISP_VERSION@"
def vispVersionCode = ((@VISP_VERSION_MAJOR@ * 100 + @VISP_VERSION_MINOR@) * 100 + @VISP_VERSION_PATCH@) * 10 + 0
android {
compileSdkVersion @ANDROID_COMPILE_SDK_VERSION@
namespace "org.visp"
ndkVersion "@ANDROID_NDK_VERSION@"
defaultConfig {
minSdkVersion @ANDROID_MIN_SDK_VERSION@
targetSdkVersion @ANDROID_TARGET_SDK_VERSION@
versionCode vispVersionCode
versionName vispVersionName
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=@ANDROID_STL@"
targets "visp_jni_shared"
}
}
}
configurations {
javadocDeps
customConfig.extendsFrom implementation
}
buildFeatures {
aidl true
}
buildTypes {
debug {
packagingOptions {
doNotStrip '**/*.so' // controlled by ViSP CMake scripts
}
}
release {
packagingOptions {
doNotStrip '**/*.so' // controlled by ViSP CMake scripts
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
jniLibs.srcDirs = ['../../jni']
java.srcDirs = ['src'] // TODO Use original files instead of copied into build directory
aidl.srcDirs = ['src']
res.srcDirs = ['@VISP_SOURCE_DIR@/modules/java/android_sdk/android_gradle_lib/res']
manifest.srcFile 'AndroidManifest.xml'
}
}
externalNativeBuild {
cmake {
path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
}
}
}
dependencies {
javadocDeps 'com.android.support:support-annotations'
javadocDeps 'com.nineoldandroids:library'
javadocDeps 'com.android.support:support-v4'
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier = 'sources'
}
import java.nio.file.Files
import java.nio.file.Paths
import java.io.FileOutputStream
import java.util.zip.ZipFile
task javadoc(type: Javadoc) {
dependsOn ":visp:generateDebugRFile"
dependsOn ":visp:generateReleaseRFile"
dependsOn ":visp:compileReleaseAidl"
dependsOn ":visp:compileReleaseSources"
source = android.sourceSets.main.java.srcDirs
// To avoid error due to @hide tag not recognized by javadoc
options.tags = [ "hide" ]
classpath += configurations.customConfig
doFirst {
// Add the compiled aidl files
android.libraryVariants.all { variant ->
classpath += files(variant.javaCompile.classpath.files)
source += variant.javaCompile.source
}
// Remove the *.aidl from the source list because we use the compiled versions for the doc generation
def aidlDependencies = source.filter { it.name.endsWith('.aidl') }
source -= aidlDependencies
}
afterEvaluate {
// Wait after evaluation to add the com.android classpath
// to avoid "buildToolsVersion is not specified" error
classpath += files(android.getBootClasspath())
classpath += files(android.libraryVariants.collect { variant ->
variant.javaCompileProvider.get().classpath.files
})
// 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/outputs/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 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()
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
|