From 733926fb14b942a04fbbf5edccd3119748de8613 Mon Sep 17 00:00:00 2001 From: Vlad Shcherban Date: Sat, 10 Aug 2024 18:34:09 -0700 Subject: [PATCH] !!! Updating to Gradle 8.7 and Android plugin 8.5.1 fixes #716 --- platform/android/app/build.gradle.kts | 85 +++--- platform/android/app/proguard-rules.pro | 6 +- .../android/app/src/main/AndroidManifest.xml | 1 - platform/android/build.gradle.kts | 2 +- platform/android/gradle.properties | 3 - .../android/gradle/wrapper/gradle-wrapper.jar | Bin 58910 -> 43453 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 +- platform/android/gradlew | 282 +++++++++++------- platform/android/gradlew.bat | 54 ++-- platform/android/sdk/build.gradle.kts | 35 +-- subrepos/enterprise | 2 +- 11 files changed, 256 insertions(+), 219 deletions(-) diff --git a/platform/android/app/build.gradle.kts b/platform/android/app/build.gradle.kts index e1a114ee1..58b83b4d3 100644 --- a/platform/android/app/build.gradle.kts +++ b/platform/android/app/build.gradle.kts @@ -39,8 +39,10 @@ val coronaSrcDir = project.findProperty("coronaSrcDir") as? String } val coronaBuiltFromSource = file("CMakeLists.txt").exists() && file("../sdk").exists() -val windows = System.getProperty("os.name").toLowerCase().contains("windows") -val linux = System.getProperty("os.name").toLowerCase().contains("linux") +val buildDirectory = layout.buildDirectory.asFile.get() + +val windows = System.getProperty("os.name").lowercase().contains("windows") +val linux = System.getProperty("os.name").lowercase().contains("linux") val shortOsName = if (windows) "win" else if (linux) "linux" else "mac" val nativeDir = if (windows) { @@ -53,7 +55,7 @@ val nativeDir = if (windows) { resourceDir ?: "${System.getenv("HOME")}/Library/Application Support/Corona/Native/" } -val coronaPlugins = file("$buildDir/corona-plugins") +val coronaPlugins = file("$buildDirectory/corona-plugins") val luaCmd = "$nativeDir/Corona/$shortOsName/bin/lua" val isSimulatorBuild = coronaTmpDir != null @@ -77,17 +79,17 @@ val buildToolsDir = "$projectDir/buildTools".takeIf { file(it).exists() } checkCoronaNativeInstallation() copy { from(zipTree("$nativeDir/Corona/android/resource/android-template.zip")) - into("$buildDir/intermediates/corona-build-tools") + into("$buildDirectory/intermediates/corona-build-tools") } - "$buildDir/intermediates/corona-build-tools/template/app/buildTools" + "$buildDirectory/intermediates/corona-build-tools/template/app/buildTools" }() -val generatedPluginsOutput = "$buildDir/generated/corona_plugins" +val generatedPluginsOutput = "$buildDirectory/generated/corona_plugins" val generatedPluginAssetsDir = "$generatedPluginsOutput/assets" val generatedPluginNativeLibsDir = "$generatedPluginsOutput/native" val generatedBuildIdPath = "$generatedPluginsOutput/build" val generatedPluginMegaJar = "$generatedPluginsOutput/plugins.jar" -val generatedMainIconsAndBannersDir = "$buildDir/generated/corona_icons" +val generatedMainIconsAndBannersDir = "$buildDirectory/generated/corona_icons" val parsedBuildProperties: JsonObject = run { coronaTmpDir?.let { srcDir -> @@ -122,9 +124,9 @@ val parsedBuildProperties: JsonObject = run { isIgnoreExitValue = true } if (execResult.exitValue != 0) { - throw InvalidUserDataException("Build.settings file could not be parsed: ${output.toString().replace(luaCmd, "")}") + throw InvalidUserDataException("Build.settings file could not be parsed: ${output.toString(charset("UTF-8")).replace(luaCmd, "")}") } - val parsedBuildSettingsFile = Parser.default().parse(StringBuilder(output.toString())) as? JsonObject + val parsedBuildSettingsFile = Parser.default().parse(StringBuilder(output.toString(charset("UTF-8")))) as? JsonObject return@run JsonObject(mapOf("buildSettings" to parsedBuildSettingsFile, "packageName" to coronaAppPackage, "targetedAppStore" to coronaTargetStore)) } @@ -189,6 +191,7 @@ if (configureCoronaPlugins == "YES") { // android { + namespace = coronaAppPackage lintOptions { isCheckReleaseBuilds = true } @@ -224,18 +227,6 @@ android { } } - applicationVariants.all { - generateBuildConfigProvider!!.configure { - enabled = false - } - } - testOptions { - testVariants.all { - generateBuildConfigProvider!!.configure { - enabled = false - } - } - } val mainSourceSet = sourceSets["main"] val pluginJniLibs = file(coronaPlugins).walk().maxDepth(2).filter { it.name == "jniLibs" }.toSet() mainSourceSet.jniLibs.srcDirs(pluginJniLibs) @@ -285,7 +276,7 @@ android { // val apkFilesSet = mutableSetOf() -file("$buildDir/intermediates/corona_manifest_gen/CopyToApk.txt").takeIf { it.exists() }?.readLines()?.forEach { +file("$buildDirectory/intermediates/corona_manifest_gen/CopyToApk.txt").takeIf { it.exists() }?.readLines()?.forEach { apkFilesSet.add(it.trim()) } if (!isSimulatorBuild) { @@ -294,7 +285,7 @@ if (!isSimulatorBuild) { } } if (apkFilesSet.isNotEmpty()) { - val generatedApkFiles = "$buildDir/generated/apkFiles" + val generatedApkFiles = "$buildDirectory/generated/apkFiles" val coronaCopyApkFiles = tasks.create("coronaCopyApkFiles") { description = "Creates new resource directory with raw APK files" into(generatedApkFiles) @@ -392,14 +383,16 @@ fun coronaAssetsCopySpec(spec: CopySpec) { } android.applicationVariants.all { - val baseName = this.baseName.toLowerCase() + val baseName = this.baseName.lowercase() + val baseNameCapitalized = baseName.replaceFirstChar(Char::titlecase) + val isRelease = (baseName == "release") - val generatedAssetsDir = "$buildDir/generated/corona_assets/$baseName" - val compiledLuaArchive = "$buildDir/intermediates/compiled_lua_archive/$baseName/resource.car" + val generatedAssetsDir = "$buildDirectory/generated/corona_assets/$baseName" + val compiledLuaArchive = "$buildDirectory/intermediates/compiled_lua_archive/$baseName/resource.car" // fix assets not been merge when lua file changed - val luaArchiveInMergedAssets = "$buildDir/intermediates/assets/$baseName/resource.car" + val luaArchiveInMergedAssets = "$buildDirectory/intermediates/assets/$baseName/resource.car" - val compileLuaTask = tasks.create("compileLua${baseName.capitalize()}") { + val compileLuaTask = tasks.create("compileLua$baseNameCapitalized") { description = "If required, compiles Lua and archives it into resource.car" val luac = "$nativeDir/Corona/$shortOsName/bin/luac" @@ -415,7 +408,7 @@ android.applicationVariants.all { outputs.file(compiledLuaArchive) doLast { val rootFile = file(coronaSrcDir) - val compiledDir = "$buildDir/intermediates/compiled_lua/$baseName" + val compiledDir = "$buildDirectory/intermediates/compiled_lua/$baseName" delete(compiledDir) mkdir(compiledDir) val luaFiles = if (isSimulatorBuild) { @@ -471,8 +464,8 @@ android.applicationVariants.all { coronaBuild = "$coronaBuild", } """.trimIndent() - val metadataConfig = file("$buildDir/tmp/config.$baseName.lua") - val metadataCompiled = file("$buildDir/tmp/config.$baseName.lu") + val metadataConfig = file("$buildDirectory/tmp/config.$baseName.lua") + val metadataCompiled = file("$buildDirectory/tmp/config.$baseName.lu") mkdir(metadataConfig.parent) metadataConfig.writeText(metadataLuaStr) val configEntries = outputsList.filter { file(it).name == "config.lu" } + metadataConfig @@ -498,7 +491,7 @@ android.applicationVariants.all { } } - val taskCopyResources = tasks.create("packageCoronaApp${baseName.capitalize()}") { + val taskCopyResources = tasks.create("packageCoronaApp$baseNameCapitalized") { description = "Copies all resources and compiled Lua to the project" dependsOn(compileLuaTask) @@ -529,6 +522,8 @@ android.applicationVariants.all { dependsOn(taskCopyResources) } android.sourceSets[name].assets.srcDirs(generatedAssetsDir) + tasks.findByName("lintVitalAnalyze${baseNameCapitalized}")?.dependsOn(taskCopyResources) + tasks.findByName("generate${baseNameCapitalized}LintVitalReportModel")?.dependsOn(taskCopyResources) } fun downloadAndProcessCoronaPlugins(reDownloadPlugins: Boolean = true) { @@ -564,7 +559,7 @@ fun downloadAndProcessCoronaPlugins(reDownloadPlugins: Boolean = true) { "pluginPlatform" to androidDestPluginPlatform, "destinationDirectory" to coronaPlugins.absolutePath )).toJsonString() - val builderInput = file("$buildDir/tmp/builderInput.json") + val builderInput = file("$buildDirectory/tmp/builderInput.json") builderInput.parentFile.mkdirs() builderInput.writeText(buildParams) val builderOutput = ByteArrayOutputStream() @@ -661,7 +656,7 @@ fun downloadAndProcessCoronaPlugins(reDownloadPlugins: Boolean = true) { // Run `convert_metadata.lua` which collects plugin metadata into single file logger.lifecycle("Collecting plugin metadata") run { - file("$buildDir/intermediates").mkdirs() + file("$buildDirectory/intermediates").mkdirs() val metadataFiles = fileTree(coronaPlugins) { include("*/metadata.lua") pluginDisabledMetadata.forEach { @@ -674,7 +669,7 @@ fun downloadAndProcessCoronaPlugins(reDownloadPlugins: Boolean = true) { , "package.path='$nativeDir/Corona/shared/resource/?.lua;'..package.path" , *luaVerbosityPlug , "$buildToolsDir/convert_metadata.lua" - , "$buildDir/intermediates/plugins_metadata.json" + , "$buildDirectory/intermediates/plugins_metadata.json" , *metadataFiles.toTypedArray() ) } @@ -687,12 +682,12 @@ fun downloadAndProcessCoronaPlugins(reDownloadPlugins: Boolean = true) { val inputSettingsFile = if (buildPropsFile.exists()) { buildPropsFile } else { - val buildPropsOut = file("$buildDir/intermediates/corona.build.props") + val buildPropsOut = file("$buildDirectory/intermediates/corona.build.props") buildPropsOut.writeText(parsedBuildProperties.toJsonString()) buildPropsOut } - val manifestGenDir = "$buildDir/intermediates/corona_manifest_gen" + val manifestGenDir = "$buildDirectory/intermediates/corona_manifest_gen" file(manifestGenDir).mkdirs() exec { commandLine(luaCmd @@ -704,7 +699,7 @@ fun downloadAndProcessCoronaPlugins(reDownloadPlugins: Boolean = true) { , /*2*/ inputSettingsFile , /*3*/ coronaAppFileName ?: "Corona App" , /*4*/ "$manifestGenDir/AndroidManifest.xml" - , /*5*/ "$buildDir/intermediates/plugins_metadata.json" + , /*5*/ "$buildDirectory/intermediates/plugins_metadata.json" , /*6*/ "$buildToolsDir/strings.xml" , /*7*/ "$manifestGenDir/strings.xml" , /*8*/ "$manifestGenDir/CopyToApk.txt" @@ -754,7 +749,7 @@ fun downloadAndProcessCoronaPlugins(reDownloadPlugins: Boolean = true) { logger.lifecycle("Collecting legacy jar libraries") run { - val megaJarExtracted = "$buildDir/intermediates/corona-mega-jar" + val megaJarExtracted = "$buildDirectory/intermediates/corona-mega-jar" delete(megaJarExtracted) delete(generatedPluginMegaJar) fileTree(coronaPlugins) { @@ -800,7 +795,7 @@ tasks.register("processPluginsNoDownload") { tasks.register("exportCoronaAppTemplate") { if (coronaBuiltFromSource) group = "Corona-dev" enabled = coronaBuiltFromSource - destinationDirectory.set(file("$buildDir/outputs")) + destinationDirectory.set(file("$buildDirectory/outputs")) archiveFileName.set("android-template.zip") from(rootDir) { include("build.gradle.kts", "settings.gradle.kts", "gradle.properties") @@ -874,7 +869,7 @@ tasks.register("installAppTemplateToSim") { if (coronaBuiltFromSource) group = "Corona-dev" enabled = coronaBuiltFromSource dependsOn("exportCoronaAppTemplate") - from("$buildDir/outputs") { + from("$buildDirectory/outputs") { include("android-template.zip") } into("$coronaNativeOutputDir/android/resource") @@ -885,7 +880,7 @@ tasks.register("installAppTemplateAndAARToSim") { enabled = coronaBuiltFromSource dependsOn("installAppTemplateToSim") dependsOn(":Corona:assembleRelease") - from("${findProject(":Corona")?.buildDir}/outputs/aar/") { + from("${findProject(":Corona")?.layout?.buildDirectory?.asFile?.get()}/outputs/aar/") { include("Corona-release.aar") rename("Corona-release.aar", "Corona.aar") } @@ -897,7 +892,7 @@ fun copyWithAppFilename(dest: String, appName: String?) { delete("$dest/$coronaAppFileName.aab") var hasODR = false parsedBuildProperties.lookup>("buildSettings.android.onDemandResources").firstOrNull()?.forEach { - it["resource"].let { res -> + it["resource"].let { hasODR = true } } @@ -914,7 +909,7 @@ fun copyWithAppFilename(dest: String, appName: String?) { exclude("*unsigned*") } } - copyTask.from("$buildDir/outputs/bundle/$name") { + copyTask.from("$buildDirectory/outputs/bundle/$name") { include("*.aab") } } @@ -1108,7 +1103,7 @@ tasks.create("copySplashScreen") { tasks.register("createExpansionFile") { enabled = isExpansionFileRequired - destinationDirectory.set(file("$buildDir/outputs")) + destinationDirectory.set(file("$buildDirectory/outputs")) archiveFileName.set(coronaExpansionFileName) from(coronaSrcDir) { diff --git a/platform/android/app/proguard-rules.pro b/platform/android/app/proguard-rules.pro index f1b424510..bded0dce1 100644 --- a/platform/android/app/proguard-rules.pro +++ b/platform/android/app/proguard-rules.pro @@ -18,4 +18,8 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile + +-keep class com.ansca.** { *; } +-keep class com.coronalabs.** { *; } +-keep class com.naef.** { *; } +-keep class **.LuaLoader.** { *; } diff --git a/platform/android/app/src/main/AndroidManifest.xml b/platform/android/app/src/main/AndroidManifest.xml index 242bb7376..688dfa9ba 100644 --- a/platform/android/app/src/main/AndroidManifest.xml +++ b/platform/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@