Download
184 lines 6.2 KiBGroovyModified 2026-07-25 raw
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
import java.nio.charset.StandardCharsets

plugins {
    id 'com.android.application'
}

android {
    namespace "org.love2d.android"
    ndkVersion '27.3.13750724'

    defaultConfig {
        applicationId project.properties["app.application_id"]
        versionCode project.properties["app.version_code"].toInteger()
        versionName project.properties["app.version_name"]
        minSdk 23
        compileSdk = 35
        targetSdk 35

        externalNativeBuild {
            cmake {
                arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=1", "-DCMAKE_POLICY_VERSION_MINIMUM=3.5", "-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON", "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
                // https://issuetracker.google.com/issues/274493986
                // Transitive shared library that's added through `add_dependencies` is not taken into
                // account. This result in liboboe.so and libluajit.so not get included into the final
                // APK. "love" target depends on LuaJIT, and "OpenAL" target depends on oboe::oboe
                // (which provides liboboe.so). So, add "OpenAL" and "love" target.
                targets "love_android", "OpenAL", "love"
            }
        }

        ndk {
            //noinspection ChromeOsAbiSupport
            abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
            debugSymbolLevel 'full'
        }

        def getAppName = {
            def nameArray = project.properties["app.name_byte_array"]
            def name = project.properties["app.name"]
            if (name != null && nameArray != null) {
                throw new Exception("Only define either `app.name` or `app.name_byte_array` in gradle.properties, but not both!")
            }

            if (name == null) {
                def nameArraySplit = nameArray.split(",")
                def nameBytes = new byte[nameArraySplit.length]
                def count = 0
                for (String s: nameArraySplit) {
                    nameBytes[count++] = (byte) Integer.parseInt(s)
                }
                return new String(nameBytes, StandardCharsets.UTF_8)
            }
            return name
        }

        manifestPlaceholders = [
            NAME:getAppName(),
            ORIENTATION:project.properties["app.orientation"],
        ]
    }

    def retrieveAll3pModules = { ->
        def modules = []

        fileTree("src/main/cpp/lua-modules/").visit { FileVisitDetails details ->
            if (details.isDirectory()) {
                if (file(details.file.path + "/Android.mk").exists() ||
                        file(details.file.path + "/CMakeLists.mk").exists()) {
                    def logger = project.getLogger()
                    logger.lifecycle("3rd-party module: " + details.file.path)

                    def javainfo = file(details.file.path + "/java.txt")
                    if (javainfo.exists()) {
                        def fstream = new FileInputStream(javainfo)
                        def infile = new BufferedReader(new InputStreamReader(fstream))
                        def javapath = infile.readLine().replace("\\", "/")
                        def mpath = null

                        if (javapath[0] != '/') {
                            mpath = details.file.path + "/" + javapath
                        } else {
                            mpath = details.file.path + javapath
                        }

                        modules << mpath

                        logger.lifecycle("Registered path " + mpath)
                        infile.close()
                    }
                }
            }
        }

        return modules
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    buildFeatures {
        prefab true
    }

    flavorDimensions = ['mode', 'recording']
    productFlavors {
        normal {
            dimension 'mode'
        }
        embed {
            dimension 'mode'
        }
        record {
            dimension 'recording'
        }
        noRecord {
            dimension 'recording'
        }
    }

    sourceSets {
        main {
            java {
                srcDir 'src/main/cpp/megasource/libs/SDL3/android-project/app/src/main/java'
                srcDir 'src/main/java'
                srcDir 'src/main/cpp/love/src/libraries/luahttps/src/android/java'
                srcDirs += retrieveAll3pModules()
            }
        }
        normal {
            java {
                srcDir 'src/normal/java'
            }
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildFeatures {
        viewBinding true
    }
    externalNativeBuild {
        cmake {
            path file('src/main/cpp/CMakeLists.txt')
            // '+' notation apparently has been supported long time ago
            // https://issuetracker.google.com/issues/110693527#comment22
            // We require CMake 3.21 because r23 has important fixes
            // that's only fixed if CMake 3.21 is used.
            // https://github.com/android/ndk/issues/463
            version '3.21.0+'
        }
    }
    packagingOptions {
        jniLibs {
            excludes += [
                'lib/armeabi-v7a/libOpenSLES.so',
                'lib/arm64-v8a/libOpenSLES.so',
                'lib/x86/libOpenSLES.so',
                'lib/x86_64/libOpenSLES.so'
            ]
        }
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.7.0'
    implementation 'com.google.android.material:material:1.12.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
    implementation 'androidx.navigation:navigation-fragment:2.8.5'
    implementation 'androidx.navigation:navigation-ui:2.8.5'
    implementation 'androidx.recyclerview:recyclerview:1.3.2'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
    implementation 'com.google.oboe:oboe:1.9.3'
}

// We don't even use Kotlin. Why we have to care about it?
configurations.implementation {
    exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
}