Fix task ordering and more in Gradle Android build

This commit is contained in:
sfan5 2023-02-23 11:32:42 +01:00 committed by SmallJoker
parent a93f3542d9
commit fee2e3ee27
3 changed files with 56 additions and 44 deletions

@ -53,51 +53,59 @@ android {
task prepareAssets() { task prepareAssets() {
def assetsFolder = "build/assets" def assetsFolder = "build/assets"
def projRoot = "../.." def projRoot = rootDir.parent
def gameToCopy = "minetest_game" def gameToCopy = "minetest_game"
copy { doFirst {
from "${projRoot}/minetest.conf.example", "${projRoot}/README.md" into assetsFolder logger.lifecycle('Preparing assets at {}', assetsFolder)
} }
copy { doLast {
from "${projRoot}/doc/lgpl-2.1.txt" into "${assetsFolder}" copy {
} from "${projRoot}/minetest.conf.example", "${projRoot}/README.md" into assetsFolder
copy {
from "${projRoot}/builtin" into "${assetsFolder}/builtin"
}
copy {
from "${projRoot}/client/shaders" into "${assetsFolder}/client/shaders"
}
copy {
from "../native/deps/armeabi-v7a/Irrlicht/Shaders" into "${assetsFolder}/client/shaders/Irrlicht"
}
copy {
from "${projRoot}/fonts" include "*.ttf" into "${assetsFolder}/fonts"
}
copy {
from "${projRoot}/games/${gameToCopy}" into "${assetsFolder}/games/${gameToCopy}"
}
fileTree("${projRoot}/po").include("**/*.po").forEach { poFile ->
def moPath = "${assetsFolder}/locale/${poFile.parentFile.name}/LC_MESSAGES/"
file(moPath).mkdirs()
exec {
commandLine 'msgfmt', '-o', "${moPath}/minetest.mo", poFile
} }
} copy {
copy { from "${projRoot}/doc/lgpl-2.1.txt" into assetsFolder
from "${projRoot}/textures" into "${assetsFolder}/textures" }
copy {
from "${projRoot}/builtin" into "${assetsFolder}/builtin"
}
copy {
from "${projRoot}/client/shaders" into "${assetsFolder}/client/shaders"
}
copy {
from "../native/deps/armeabi-v7a/Irrlicht/Shaders" into "${assetsFolder}/client/shaders/Irrlicht"
}
copy {
from "${projRoot}/fonts" include "*.ttf" into "${assetsFolder}/fonts"
}
copy {
from "${projRoot}/games/${gameToCopy}" into "${assetsFolder}/games/${gameToCopy}"
}
copy {
from "${projRoot}/textures" into "${assetsFolder}/textures"
}
// compile translations
fileTree("${projRoot}/po").include("**/*.po").forEach { poFile ->
def moPath = "${assetsFolder}/locale/${poFile.parentFile.name}/LC_MESSAGES/"
file(moPath).mkdirs()
exec {
commandLine 'msgfmt', '-o', "${moPath}/minetest.mo", poFile
}
}
file("${assetsFolder}/.nomedia").text = ""
} }
file("${assetsFolder}/.nomedia").text = "" task zipAssets(dependsOn: prepareAssets, type: Zip) {
task zipAssets(type: Zip) {
archiveFileName = "Minetest.zip" archiveFileName = "Minetest.zip"
from "${assetsFolder}" from assetsFolder
destinationDirectory = file("src/main/assets") destinationDirectory = file("src/main/assets")
} }
} }
preBuild.dependsOn zipAssets preBuild.dependsOn zipAssets
prepareAssets.dependsOn ':native:getDeps'
// Map for the version code that gives each ABI a value. // Map for the version code that gives each ABI a value.
import com.android.build.OutputFile import com.android.build.OutputFile

@ -33,5 +33,4 @@ allprojects {
task clean(type: Delete) { task clean(type: Delete) {
delete rootProject.buildDir delete rootProject.buildDir
delete 'native/deps'
} }

@ -52,18 +52,23 @@ android {
// get precompiled deps // get precompiled deps
task downloadDeps(type: Download) { task downloadDeps(type: Download) {
src 'https://github.com/minetest/minetest_android_deps/releases/download/latest/deps.zip' def depsDir = new File(buildDir.parent, 'deps')
dest new File(buildDir, 'deps.zip') def depsZip = new File(buildDir, 'deps.zip')
overwrite false
}
task getDeps(dependsOn: downloadDeps, type: Copy) { src 'https://github.com/minetest/minetest_android_deps/releases/download/latest/deps.zip'
def deps = new File(buildDir.parent, 'deps') dest depsZip
if (!deps.exists()) { overwrite false
deps.mkdir()
from zipTree(downloadDeps.dest) task getDeps(dependsOn: downloadDeps, type: Copy) {
into deps depsDir.mkdir()
from zipTree(depsZip)
into depsDir
doFirst { logger.lifecycle('Extracting to {}', depsDir) }
} }
} }
preBuild.dependsOn getDeps preBuild.dependsOn getDeps
clean {
delete new File(buildDir.parent, 'deps')
}