openalsoft.gradle 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // OpenAL Soft r1.16
  2. String openALSoftUrl = 'http://repo.or.cz/w/openal-soft.git/snapshot/e5016f814a265ed592a88acea95cf912c4bfdf12.zip'
  3. String openALSoftZipFile = 'OpenALSoft.zip'
  4. // OpenAL Soft directory the download is extracted into
  5. // Typically, the downloaded OpenAL Soft zip file will extract to a directory
  6. // called "openal-soft"
  7. String openALSoftFolder = 'openal-soft-e5016f8'
  8. //Working directories for the ndk build.
  9. String openalsoftBuildDir = "${buildDir}" + File.separator + 'openalsoft'
  10. String openalsoftBuildJniDir = openalsoftBuildDir + File.separator + 'jni'
  11. String openalsoftBuildLibsDir = openalsoftBuildDir + File.separator + 'libs'
  12. //Pre-compiled libs directory
  13. String openalsoftPreCompiledLibsDir = 'libs' + File.separator + 'openalsoft'
  14. // jME Android Native source files path
  15. String openalsoftJmeAndroidPath = 'src/native/jme_openalsoft'
  16. // Download external source files if not available
  17. task downloadOpenALSoft(type: MyDownload) {
  18. sourceUrl = openALSoftUrl
  19. target = file(openalsoftBuildDir + File.separator + openALSoftZipFile)
  20. }
  21. // Unzip external source files
  22. task unzipOpenALSoft(type: Copy) {
  23. def zipFile = file(openalsoftBuildDir + File.separator + openALSoftZipFile)
  24. def outputDir = file(openalsoftBuildDir)
  25. from zipTree(zipFile)
  26. into outputDir
  27. }
  28. unzipOpenALSoft.dependsOn {
  29. def zipFilePath = openalsoftBuildDir + File.separator + openALSoftZipFile
  30. def zipFile = new File(zipFilePath)
  31. // println "zipFile path: " + zipFile.absolutePath
  32. // println "zipFile exists: " + zipFile.exists()
  33. if (!zipFile.exists()) {
  34. downloadOpenALSoft
  35. }
  36. }
  37. // Copy external source files to jni directory
  38. task copyOpenALSoft(type: Copy) {
  39. def sourceDir = file(openalsoftBuildDir + File.separator + openALSoftFolder)
  40. def outputDir = file(openalsoftBuildJniDir)
  41. // println "copyOpenALSoft sourceDir: " + sourceDir
  42. // println "copyOpenALSoft outputDir: " + outputDir
  43. from sourceDir
  44. into outputDir
  45. }
  46. copyOpenALSoft.dependsOn {
  47. def openALSoftUnzipDir = new File(project.projectDir.absolutePath + File.separator + openALSoftFolder)
  48. // println "openALSoftUnzipDir path: " + openALSoftUnzipDir.absolutePath
  49. // println "openALSoftUnzipDir exists: " + openALSoftUnzipDir.isDirectory()
  50. if (!openALSoftUnzipDir.isDirectory()) {
  51. unzipOpenALSoft
  52. }
  53. }
  54. // Copy jME Android native files to jni directory
  55. task copyJmeOpenALSoft(type: Copy, dependsOn:copyOpenALSoft) {
  56. def sourceDir = file(openalsoftJmeAndroidPath)
  57. def outputDir = file(openalsoftBuildJniDir)
  58. // println "copyJmeOpenALSoft sourceDir: " + sourceDir
  59. // println "copyJmeOpenALSoft outputDir: " + outputDir
  60. from sourceDir
  61. into outputDir
  62. }
  63. task generateOpenAlSoftHeaders(type:Exec, dependsOn: copyJmeOpenALSoft) {
  64. executable org.gradle.internal.jvm.Jvm.current().getExecutable('javah')
  65. args '-d', openalsoftJmeAndroidPath
  66. args '-classpath', project.projectClassPath
  67. args "com.jme3.audio.android.AndroidAL"
  68. args "com.jme3.audio.android.AndroidALC"
  69. args "com.jme3.audio.android.AndroidEFX"
  70. }
  71. task buildOpenAlSoftNativeLib(type: Exec, dependsOn: generateOpenAlSoftHeaders) {
  72. // println "openalsoft build dir: " + openalsoftBuildDir
  73. // println "ndkCommandPath: " + project.ndkCommandPath
  74. workingDir openalsoftBuildDir
  75. executable rootProject.ndkCommandPath
  76. args "-j" + Runtime.runtime.availableProcessors()
  77. }
  78. task updatePreCompiledOpenAlSoftLibs(type: Copy, dependsOn: buildOpenAlSoftNativeLib) {
  79. def sourceDir = new File(openalsoftBuildLibsDir)
  80. def outputDir = new File(openalsoftPreCompiledLibsDir)
  81. // println "updatePreCompiledOpenAlSoftLibs sourceDir: " + sourceDir
  82. // println "updatePreCompiledOpenAlSoftLibs outputDir: " + outputDir
  83. from sourceDir
  84. into outputDir
  85. }
  86. // Copy pre-compiled libs to build directory (when not building new libs)
  87. task copyPreCompiledOpenAlSoftLibs(type: Copy) {
  88. def sourceDir = file(openalsoftPreCompiledLibsDir)
  89. def outputDir = file(openalsoftBuildLibsDir)
  90. // println "copyStbiJmeFiles sourceDir: " + sourceDir
  91. // println "copyStbiJmeFiles outputDir: " + outputDir
  92. from sourceDir
  93. into outputDir
  94. }
  95. // ndkExists is a boolean from the build.gradle in the root project
  96. // buildNativeProjects is a string set to "true"
  97. if (ndkExists && buildNativeProjects == "true") {
  98. // build native libs and update stored pre-compiled libs to commit
  99. compileJava.dependsOn { updatePreCompiledOpenAlSoftLibs }
  100. } else {
  101. // use pre-compiled native libs (not building new ones)
  102. compileJava.dependsOn { copyPreCompiledOpenAlSoftLibs }
  103. }
  104. jar.into("lib") { from openalsoftBuildLibsDir }
  105. // Helper class to wrap ant dowload task
  106. class MyDownload extends DefaultTask {
  107. @Input
  108. String sourceUrl
  109. @OutputFile
  110. File target
  111. @TaskAction
  112. void download() {
  113. ant.get(src: sourceUrl, dest: target)
  114. }
  115. }