You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mohemm-flutter-app/android/app/build.gradle

162 lines
5.5 KiB
Groovy

plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id "dev.flutter.flutter-gradle-plugin"
id "com.google.gms.google-services"
// id "com.huawei.agconnect" //todo this will be done
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
//apply plugin: 'com.android.application'
//apply plugin: 'kotlin-android'
//apply plugin: 'com.google.gms.google-services'
//apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
//apply plugin: 'com.huawei.agconnect'
android {
namespace 'hmg.cloudSolutions.mohem'
compileSdkVersion 35
defaultConfig {
multiDexEnabled true
}
compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "hmg.cloudSolutions.mohem"
minSdkVersion 28
targetSdkVersion 35
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildFeatures{
buildConfig true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
flutter {
source '../..'
}
dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10"
}
def targetProjects = ["huawei_push", "in_app_update", "qr_code_scanner"]
subprojects {
afterEvaluate { subproject ->
if (targetProjects.contains(subproject.name) && subproject.extensions.findByName("android") != null) {
// Register the fix task only for target projects
def fixTask = subproject.tasks.register("fixManifestsAndNamespace") {
doLast {
def buildGradleFile = file("build.gradle")
def manifestFile = file("src/main/AndroidManifest.xml")
// Step 1: Set namespace from package if not already present
if (manifestFile.exists()) {
def manifestContent = manifestFile.getText("UTF-8")
def matcher = (manifestContent =~ /package\s*=\s*"([^"]+)"/)
def packageName = matcher.find() ? matcher.group(1) : null
if (packageName != null && !buildGradleFile.getText().contains("namespace")) {
println "Setting namespace in ${buildGradleFile.path}"
def updatedBuildGradle = buildGradleFile.getText().replaceFirst(
/android\s*\{/,
"android {\n namespace = \"${packageName}\""
)
buildGradleFile.write(updatedBuildGradle, "UTF-8")
}
}
// Step 2: Remove `package` from all AndroidManifest.xml files in the project
def manifestFiles = fileTree("src/main") {
include "**/AndroidManifest.xml"
}
manifestFiles.each { file ->
def content = file.getText()
if (content.contains("package=")) {
println "Removing package attribute from ${file.path}"
def updated = content.replaceAll(/package\s*=\s*"[^"]*"/, "")
file.write(updated)
}
}
}
}
// Ensure the task runs before preBuild
subproject.tasks.matching { it.name.startsWith("preBuild") }.configureEach {
dependsOn fixTask
}
}
}
}