import groovy.json.JsonOutput import groovy.json.JsonSlurper import java.text.SimpleDateFormat apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply from: rootProject.file('gradle/bytex/bytex.gradle') Properties properties = new Properties() properties.load(project.rootProject.file("gradle.properties").newDataInputStream()) android { compileSdkVersion rootProject.ext.android.compileSdkVersion defaultConfig { minSdkVersion rootProject.ext.android.minSdkVersion targetSdkVersion rootProject.ext.android.targetSdkVersion versionCode rootProject.versionCode as int versionName rootProject.versionName applicationId rootProject.ext.android.fLauncherApplicationId testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { arguments = [AROUTER_MODULE_NAME: project.getName()] } } multiDexEnabled true } sourceSets { main { if (rootProject.isJunkDetectEnable()) { java.srcDirs = ['src/main/java', 'src/block/java'] } else { java.srcDirs = ['src/main/java'] } } } packagingOptions { exclude 'META-INF/proguard/coroutines.pro' exclude 'META-INF/*' exclude "/lib/armeabi-v7a/*.so" pickFirst 'lib/arm64-v8a/libc++_shared.so' pickFirst "META-INF/com.android.tools/proguard/coroutines.pro" } signingConfigs { release { keyAlias = 'CarLauncher' storeFile file('../keystore/car_launcher.jks') storePassword 'ZDauto123456' keyPassword 'ZDauto123456' } releaseEB5 { keyAlias = 'android_platform' storeFile file('../keystore/EB5/car_launcher.jks') storePassword 'ZDauto123456' keyPassword 'ZDauto123456' } } buildTypes { debug { debuggable true minifyEnabled false zipAlignEnabled false shrinkResources false signingConfig signingConfigs.release manifestPlaceholders = [ MAP_SDK_VERSION : properties.getProperty("MAP_SDK_VERSION"), // 高德地图鉴权信息 AMAP_API_VALUE : rootProject.ext.android.fLauncherAmapApiValue, ] } release { debuggable false minifyEnabled false zipAlignEnabled false shrinkResources false signingConfig signingConfigs.release proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' manifestPlaceholders = [ MAP_SDK_VERSION : properties.getProperty("MAP_SDK_VERSION"), // 高德地图鉴权信息 AMAP_API_VALUE : rootProject.ext.android.fLauncherAmapApiValue, ] } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } lintOptions { checkReleaseBuilds false abortOnError false } kotlinOptions { jvmTarget = '1.8' } sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' } } // 项目 business // 业务线 product // 车型 vehicle flavorDimensions "project","product","role","vehicle" ,"basic", "env" productFlavors { // launcher app launcher { dimension "basic" // 是否作为 launcher 运行 buildConfigField 'boolean', 'IS_LAUNCHER', 'true' buildConfigField 'String', 'SOCKET_APP_ID', '\"com.mogo.launcher\"' buildConfigField 'String', 'WORKING_BRANCH_NAME', getWorkingBranchName() buildConfigField 'String', 'WORKING_BRANCH_HASH', getWorkingBranchHash() buildConfigField 'String', 'APP_BUILD_TIME', getBuildTime() buildConfigField 'String', 'MAP_SDK_VERSION', "\"${MAP_SDK_VERSION}\"" buildConfigField 'String', 'MAP_SDK_OPT_VERSION', "\"${MAP_SDK_OPERATION_VERSION}\"" // ②车机类型,主要用于区分自研车机还是别人家的车机,自研车机类型为0 buildConfigField 'int', 'CAR_MACHINE_TYPE', '2' // ④GPS数据提供源: 0-Android系统,1-工控机,2-OBU buildConfigField 'int', 'GPS_PROVIDER', "1" // ⑤构建的是否是演示(美化)模式 buildConfigField 'boolean', 'IS_DEMO_MODE', 'false' // 是否支持卡顿检测 buildConfigField 'boolean', 'IS_SUPPORT_JUNK_DETECT', "${rootProject.isJunkDetectEnable()}" buildConfigField 'String', 'SWEEPER_DEFAULT_MODE', '\"Cloud\"' buildConfigField 'boolean', 'SWEEPER_CAN_SWITCH_MODE', 'true' } mogo { dimension "project" buildConfigField 'boolean', 'secure', "true" buildConfigField 'String', 'URLs', "\"${readFileToJson("mogo").replace("\"", "\\\"")}\"" buildConfigField 'String', 'mediaUrlConfig', "\"${readMediaUrlConfigFromJsonFile("mogo").replace("\"", "\\\"")}\"" buildConfigField 'String', 'musicUrlConfig', "\"${readMusicUrlConfigFromJsonFile("mogo").replace("\"", "\\\"")}\"" } yantai { dimension "project" buildConfigField 'boolean', 'secure', "false" buildConfigField 'String', 'URLs', "\"${readFileToJson("yantai").replace("\"", "\\\"")}\"" buildConfigField 'String', 'mediaUrlConfig', "\"${readMediaUrlConfigFromJsonFile("yantai").replace("\"", "\\\"")}\"" buildConfigField 'String', 'musicUrlConfig', "\"${readMusicUrlConfigFromJsonFile("yantai").replace("\"", "\\\"")}\"" } dali { dimension "project" buildConfigField 'boolean', 'secure', "true" buildConfigField 'String', 'URLs', "\"${readFileToJson("dali").replace("\"", "\\\"")}\"" buildConfigField 'String', 'mediaUrlConfig', "\"${readMediaUrlConfigFromJsonFile("dali").replace("\"", "\\\"")}\"" buildConfigField 'String', 'musicUrlConfig', "\"${readMusicUrlConfigFromJsonFile("dali").replace("\"", "\\\"")}\"" } saas { dimension "project" buildConfigField 'boolean', 'secure', "true" buildConfigField 'String', 'URLs', "\"${readFileToJson("saas").replace("\"", "\\\"")}\"" buildConfigField 'String', 'mediaUrlConfig', "\"${readMediaUrlConfigFromJsonFile("saas").replace("\"", "\\\"")}\"" buildConfigField 'String', 'musicUrlConfig', "\"${readMusicUrlConfigFromJsonFile("saas").replace("\"", "\\\"")}\"" } // 配置网络环境,QA、线上、演示 qa { dimension "env" buildConfigField 'int', 'NET_ENV', '2' } online { dimension "env" buildConfigField 'int', 'NET_ENV', '3' } demo { dimension "env" buildConfigField 'int', 'NET_ENV', '4' } } apply from: "./script/roleFlavors/driver.gradle" apply from: "./script/roleFlavors/passenger.gradle" apply from: "./script/roleFlavors/driverpassenger.gradle" apply from: "./script/productFlavors/bus.gradle" apply from: "./script/productFlavors/charter.gradle" apply from: "./script/productFlavors/shuttle.gradle" apply from: "./script/productFlavors/sweeperOperate.gradle" apply from: "./script/productFlavors/sweeperCloud.gradle" apply from: "./script/productFlavors/taxi.gradle" apply from: "./script/productFlavors/taxiunmanned.gradle" // 配置不同渠道参数,直接影响功能完整度 apply from: "./script/vehicleFlavors/ochJL.gradle" apply from: "./script/vehicleFlavors/ochM2.gradle" apply from: "./script/vehicleFlavors/ochDFHQ.gradle" apply from: "./script/vehicleFlavors/ochFT.gradle" //包车 apply from: "./script/vehicleFlavors/ochM1.gradle" apply from: "./script/flavorfilter/flavorsFilterConfig.gradle" packagingOptions { exclude 'META-INF/io.netty.versions.properties' } useLibrary 'android.test.runner' useLibrary 'android.test.base' useLibrary 'android.test.mock' } repositories { flatDir { dirs 'libs' } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) implementation rootProject.ext.dependencies.androidxappcompat implementation rootProject.ext.dependencies.arouter implementation rootProject.ext.dependencies.boostmultidex // debugImplementation rootProject.ext.dependencies.debugleakcanary // releaseImplementation rootProject.ext.dependencies.releaseleakcanary implementation rootProject.ext.dependencies.android_start_up implementation rootProject.ext.dependencies.lancetx_runtime if (rootProject.isJunkDetectEnable()) { implementation rootProject.ext.dependencies.lancetx_compiler_lib implementation rootProject.ext.dependencies.handler_proxy_runtime kapt rootProject.ext.dependencies.lancetx_compiler annotationProcessor rootProject.ext.dependencies.lancetx_compiler annotationProcessor rootProject.ext.dependencies.google_auto_service kapt rootProject.ext.dependencies.google_auto_service compileOnly rootProject.ext.dependencies.google_auto_service compileOnly rootProject.ext.dependencies.apm_insight compileOnly rootProject.ext.dependencies.serialport } // implementation rootProject.ext.dependencies.mogocustommap implementation project(':libraries:mapmodule') implementation project(':core:function-impl:mogo-core-function-startup') implementation project(':core:function-impl:mogo-core-function-devatools') implementation project(':core:function-impl:mogo-core-function-datacenter') implementation project(':core:function-impl:mogo-core-function-biz') implementation project(':core:function-impl:mogo-core-function-hmi') implementation project(':core:function-impl:mogo-core-function-map') implementation project(':core:function-impl:mogo-core-function-chat') implementation project(':core:function-impl:mogo-core-function-patch') implementation project(':foudations:mogo-commons') implementation project(':core:mogo-core-function-call') implementation project(':core:mogo-core-utils') implementation project(':core:mogo-core-res') androidTestImplementation project(':core:mogo-core-function-call') androidTestImplementation project(':core:mogo-core-res') apply from: "./script/functions/och.gradle" androidTestImplementation rootProject.ext.dependencies.androidx_test_core androidTestImplementation rootProject.ext.dependencies.androidx_test_core_ktx androidTestImplementation rootProject.ext.dependencies.androidx_unit_ext androidTestImplementation rootProject.ext.dependencies.androidx_unit_ext_ktx androidTestImplementation rootProject.ext.dependencies.androidx_runner androidTestImplementation rootProject.ext.dependencies.androidx_espresso_core androidTestImplementation rootProject.ext.dependencies.localbroadcastmanager androidTestImplementation rootProject.ext.dependencies.downloader } android.applicationVariants.all { variant -> def buildTime = new Date().format("yyyyMMdd", TimeZone.getTimeZone("GMT+08:00")) def flavor = variant.productFlavors.collect { it.name }.join('-') variant.outputs.all { output -> outputFileName = [ rootProject.applicationName, "v${variant.versionName}", buildTime, flavor.length() > 0 ? "[${flavor}]" : "", variant.buildType.name ].findAll { it.length() > 0 }.join('_') << ".apk" } } apply from: "./regroup.gradle" /** * @return 获取当前分支名称 */ def getWorkingBranchName() { def workingBranchName = "" def proc = "git rev-parse --abbrev-ref HEAD".execute() proc.in.eachLine { line -> workingBranchName = line } proc.err.eachLine { line -> println line } proc.waitFor() workingBranchName = "\"${workingBranchName}\"" println "Working branch name: " + workingBranchName return workingBranchName } /** * @return 获取当前分支hash */ def getWorkingBranchHash() { def workingBranchHash = "" def proc = "git log -n1 --format=format:%h".execute() proc.in.eachLine { line -> workingBranchHash = line } proc.err.eachLine { line -> println line } proc.waitFor() println "Working branch hash: " + workingBranchHash return "\"${workingBranchHash}\"" } static def getBuildTime() { def buildTimeFormat = "yyyy-MM-dd HH:mm:ss" //设置时间格式 SimpleDateFormat formatter = new SimpleDateFormat(buildTimeFormat, Locale.getDefault()) //获取当前时间 Date curDate = new Date(System.currentTimeMillis()) def buildTime = formatter.format(curDate) return "\"${buildTime}\"" } Object readFileToJson(env) { try { // 加载config.json 文件 File file = new File("${rootDir}/app/config/urlConfig.json") def jsonSlurper = new JsonSlurper() // 解析json def config = jsonSlurper.parse(file) def flavorNames = variantName() def jsonOutput = new JsonOutput() config.each {key, value -> // 匹配flavor对应的 json if(flavorNames.toLowerCase().contains(key)){ return jsonOutput.toJson(value.get(env)) } } // 保底原则 return jsonOutput.toJson(config.get(env).get(flavorNames)) } catch (IOException e) { e.printStackTrace() } return null } def variantName() { if(gradle.startParameter.taskNames.size()>0) { for (String taskName : gradle.startParameter.taskNames) { if (taskName.contains("Yantai")) { project.dependencies.add('implementation', project.project(':tts:tts-iflytek')) }else if (taskName.contains("Mogo")) { if(taskName.contains("TaxiPassenger")) { project.dependencies.add('implementation', project.project(':tts:tts-zhi')) }else { project.dependencies.add('implementation', project.project(':tts:tts-pad')) } }else if (taskName.contains("Dali")) { project.dependencies.add('implementation', project.project(':tts:tts-pad')) }else if (taskName.contains("Saas")) { if(taskName.contains("TaxiunmannedPassenger")) { project.dependencies.add('implementation', project.project(':tts:tts-zhi')) }else { project.dependencies.add('implementation', project.project(':tts:tts-pad')) } }else { // 不能再else 加任何逻辑 是android dlc的特效 println("-----------$taskName") } taskName = taskName.replace("Debug", "") taskName = taskName.replace("Release", "") if (taskName.endsWith("Qa")) { return "qa" } else if (taskName.endsWith("Online")) { return "online" } else if (taskName.endsWith("Demo")) { return "demo" } } } return "qa" } /** * 读取各车型宣传视频本地配置 * @param env * @return */ Object readMediaUrlConfigFromJsonFile(env){ try { // 加载config.json 文件 File file = new File("${rootDir}/app/config/MediaUrlConfig.json") def jsonSlurper = new JsonSlurper() // 解析json def config = jsonSlurper.parse(file) def flavorNames = variantVehicleName() def jsonOutput = new JsonOutput() def getKey = flavorNames config.get(env).each {key, value -> // 匹配flavor对应的 json if(flavorNames.toLowerCase().contains(key)){ getKey = key return true } } return jsonOutput.toJson(config.get(env).get(getKey)) } catch (IOException e) { e.printStackTrace() } return null } /** * 读取各车型宣传视频本地配置 * @param env * @return */ Object readMusicUrlConfigFromJsonFile(env){ try { // 加载config.json 文件 File file = new File("${rootDir}/app/config/MusicUrlConfig.json") def jsonSlurper = new JsonSlurper() // 解析json def config = jsonSlurper.parse(file) def flavorNames = variantVehicleName() def jsonOutput = new JsonOutput() def getKey = flavorNames config.get(env).each {key, value -> // 匹配flavor对应的 json if(flavorNames.toLowerCase().contains(key)){ getKey = key return true } } return jsonOutput.toJson(config.get(env).get(getKey)) } catch (IOException e) { e.printStackTrace() } return null } def variantVehicleName() { if(gradle.startParameter.taskNames.size()>0) { for (String taskName : gradle.startParameter.taskNames) { if (taskName.contains("Debug") | taskName.contains("Release")) { return taskName } } } return "buspassenger" }