123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- String jmeBulletNativeProjectPath = '../jme3-bullet-native'
- String localUnzipPath = jmeBulletNativeProjectPath
- String localZipFile = jmeBulletNativeProjectPath + File.separator + bulletZipFile
- String localZipFolder = jmeBulletNativeProjectPath + File.separator + bulletFolder
- String bulletSrcPath = localZipFolder + File.separator + 'src'
- String jmeAndroidPath = 'src/native/android'
- String jmeCppPath = jmeBulletNativeProjectPath + '/src/native/cpp'
- //Working directories for the ndk build.
- String ndkWorkingPath = "${buildDir}" + '/bullet'
- String jniPath = ndkWorkingPath + '/jni'
- String ndkOutputPath = ndkWorkingPath + '/libs'
- //Pre-compiled libs directory
- String bulletPreCompiledLibsDir = 'libs'
- if (!hasProperty('mainClass')) {
- ext.mainClass = ''
- }
- dependencies {
- compile project(':jme3-bullet')
- }
- // Java source sets for IDE acces and source jar bundling / mavenization
- sourceSets {
- main {
- java {
- srcDir jmeCppPath
- srcDir jmeAndroidPath
- }
- }
- }
- // Download bullet if not available
- task downloadBullet(type: MyDownload) {
- sourceUrl = bulletUrl
- target = file(localZipFile)
- }
- // Unzip bullet if not available
- task unzipBullet(type: Copy) {
- def zipFile = file(localZipFile)
- def outputDir = file(localUnzipPath)
- // println "unzipBullet zipFile = " + zipFile.absolutePath
- // println "unzipBullet outputDir = " + outputDir.absolutePath
- from zipTree(zipFile)
- into outputDir
- }
- unzipBullet.dependsOn {
- def zipFile = file(localZipFile)
- // println "zipFile path: " + zipFile.absolutePath
- // println "zipFile exists: " + zipFile.exists()
- if (!zipFile.exists()) {
- downloadBullet
- }
- }
- // Copy Bullet files to jni directory
- task copyBullet(type: Copy) {
- def sourceDir = file(bulletSrcPath)
- def outputDir = new File(jniPath)
- // println "copyBullet sourceDir = " + sourceDir
- // println "copyBullet outputDir = " + outputDir
- from sourceDir
- into outputDir
- }
- copyBullet.dependsOn {
- def bulletUnzipDir = file(localZipFolder)
- // println "bulletUnzipDir: " + bulletUnzipDir.absolutePath
- // println "bulletUnzipDir exists: " + bulletUnzipDir.exists()
- // println "bulletUnzipDir isDirectory: " + bulletUnzipDir.isDirectory()
- if (!bulletUnzipDir.isDirectory()) {
- unzipBullet
- }
- }
- // Copy jME cpp native files to jni directory
- task copyJmeCpp(type: Copy) {
- def sourceDir = new File(jmeCppPath)
- def outputDir = new File(jniPath)
- // println "copyJmeCpp sourceDir = " + sourceDir
- // println "copyJmeCpp outputDir = " + outputDir
- from sourceDir
- into outputDir
- }
- // Copy jME android native files to jni directory
- task copyJmeAndroid(type: Copy) {
- def sourceDir = new File(jmeAndroidPath)
- def outputDir = new File(jniPath)
- // println "copyJmeAndroid sourceDir = " + sourceDir
- // println "copyJmeAndroid outputDir = " + outputDir
- from sourceDir
- into outputDir
- }
- task buildBulletNativeLib(type: Exec, dependsOn: [copyJmeAndroid, copyJmeCpp, copyBullet]) {
- // args 'TARGET_PLATFORM=android-9'
- // println "buildBulletNativeLib ndkWorkingPath: " + ndkWorkingPath
- // println "buildBulletNativeLib rootProject.ndkCommandPath: " + rootProject.ndkCommandPath
- workingDir ndkWorkingPath
- executable rootProject.ndkCommandPath
- args "-j" + Runtime.runtime.availableProcessors()
- }
- //task updatePreCompiledBulletLibs(type: Copy, dependsOn: generateNativeHeaders) {
- task updatePreCompiledBulletLibs(type: Copy, dependsOn: buildBulletNativeLib) {
- def sourceDir = new File(ndkOutputPath)
- def outputDir = new File(bulletPreCompiledLibsDir)
- // println "updatePreCompiledBulletLibs sourceDir: " + sourceDir
- // println "updatePreCompiledBulletLibs outputDir: " + outputDir
- from sourceDir
- into outputDir
- }
- // Copy pre-compiled libs to build directory (when not building new libs)
- task copyPreCompiledBulletLibs(type: Copy) {
- def sourceDir = new File(bulletPreCompiledLibsDir)
- def outputDir = new File(ndkOutputPath)
- // println "copyPreCompiledBulletLibs sourceDir: " + sourceDir
- // println "copyPreCompiledBulletLibs outputDir: " + outputDir
- from sourceDir
- into outputDir
- }
- // ndkExists is a boolean from the build.gradle in the root project
- // buildNativeProjects is a string set to "true"
- if (ndkExists && buildNativeProjects == "true") {
- // build native libs and update stored pre-compiled libs to commit
- compileJava.dependsOn { updatePreCompiledBulletLibs }
- } else {
- // use pre-compiled native libs (not building new ones)
- compileJava.dependsOn { copyPreCompiledBulletLibs }
- }
- jar.into("lib") { from ndkOutputPath }
- // Helper class to wrap ant dowload task
- class MyDownload extends DefaultTask {
- @Input
- String sourceUrl
- @OutputFile
- File target
- @TaskAction
- void download() {
- ant.get(src: sourceUrl, dest: target)
- }
- }
|