openalsoft.gradle 4.5 KB

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