apply plugin: 'com.android.application'

// buildhost settings - paths and the like
apply from: 'appSettings.gradle'

layout.buildDirectory.set(rootProject.layout.buildDirectory.dir("app"))

android {
    namespace 'org.libreoffice.androidapp'
    compileSdk 36
    buildToolsVersion "36.0.0"
    ndkVersion "29.0.14206865"
    buildFeatures.buildConfig = true

    defaultConfig {
        // applicationId, versionCode and versionName are defined in appSettings.gradle
        minSdk 26
        targetSdk 35

        resValue "string", "app_name", "${liboAppName}"
        resValue "string", "vendor", "${liboVendor}"
        resValue "string", "info_url", "${liboInfoURL}"
        resValue "string", "online_version_hash", "${liboOVersionHash}"
        resValue "string", "core_version_hash", "${liboCoreVersionHash}"
        resValue "string", "image_draw_header", "@drawable/drawer_header"
        manifestPlaceholders = [ appIcon: "${liboLauncherIcon}" ]
        buildConfigField "boolean", "APP_HAS_BRANDING", "${liboHasBranding}"
    }
    splits {
        abi {
            enable true

            reset ()
            for (abi in liboAbiSplit) {
                //noinspection ChromeOsAbiSupport - we generate liboAbiSplit at configure time, so we won't include ChromeOS support if we're not trying to build for it...
                include(abi)
            }
        }
    }

    lint {
        disable 'MissingTranslation', 'ExtraTranslation'
    }

    buildTypes {
        debug {
            resValue "string", "app_name", "${liboAppName} Debug"
            applicationIdSuffix '.debug'
            versionNameSuffix '-debug'
            debuggable true
        }
        release {
            if (file("src/main/res/drawable/drawer_header_brand.png").exists()) {
                resValue "string", "image_draw_header", "@drawable/drawer_header_brand"
            }

            minifyEnabled false // FIXME disabled before we get a good proguardRules for callFakeWebsocketOnMessage calling from C++
            shrinkResources false // FIXME cannot be enabled when minifyEnabled is turned off
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.7.1'
    implementation 'androidx.core:core:1.17.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.2.1'
    implementation 'androidx.recyclerview:recyclerview:1.4.0'
    implementation 'com.google.android.material:material:1.13.0'

    implementation 'androidx.preference:preference:1.2.1'
    implementation project(path: ':lib')

    // https://stackoverflow.com/questions/75263047/duplicate-class-in-kotlin-android
    constraints {
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") {
            because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
        }
        implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
            because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
        }
    }
}

tasks.register('copyBrandFiles', Copy) {
    from "${liboBrandingDir}/android"
    into "src/main/res"
}

afterEvaluate {
	if (project.ext.liboHasBranding != "true" || !file("${liboBrandingDir}").exists()) {
		copyBrandFiles.enabled = false
	}

	preBuild.dependsOn copyBrandFiles
}
