Skip to content

Commit

Permalink
!!! Updating to Gradle 8.7 and Android plugin 8.5.1
Browse files Browse the repository at this point in the history
fixes #716
  • Loading branch information
Shchvova committed Aug 11, 2024
1 parent b5e847e commit 733926f
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 219 deletions.
85 changes: 40 additions & 45 deletions platform/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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

Expand All @@ -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 ->
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -189,6 +191,7 @@ if (configureCoronaPlugins == "YES") {
//</editor-fold>

android {
namespace = coronaAppPackage
lintOptions {
isCheckReleaseBuilds = true
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -285,7 +276,7 @@ android {

//<editor-fold desc="Packaging Corona App" defaultstate="collapsed">
val apkFilesSet = mutableSetOf<String>()
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) {
Expand All @@ -294,7 +285,7 @@ if (!isSimulatorBuild) {
}
}
if (apkFilesSet.isNotEmpty()) {
val generatedApkFiles = "$buildDir/generated/apkFiles"
val generatedApkFiles = "$buildDirectory/generated/apkFiles"
val coronaCopyApkFiles = tasks.create<Copy>("coronaCopyApkFiles") {
description = "Creates new resource directory with raw APK files"
into(generatedApkFiles)
Expand Down Expand Up @@ -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"

Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -498,7 +491,7 @@ android.applicationVariants.all {
}
}

val taskCopyResources = tasks.create<Copy>("packageCoronaApp${baseName.capitalize()}") {
val taskCopyResources = tasks.create<Copy>("packageCoronaApp$baseNameCapitalized") {
description = "Copies all resources and compiled Lua to the project"

dependsOn(compileLuaTask)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
)
}
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -800,7 +795,7 @@ tasks.register("processPluginsNoDownload") {
tasks.register<Zip>("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")
Expand Down Expand Up @@ -874,7 +869,7 @@ tasks.register<Copy>("installAppTemplateToSim") {
if (coronaBuiltFromSource) group = "Corona-dev"
enabled = coronaBuiltFromSource
dependsOn("exportCoronaAppTemplate")
from("$buildDir/outputs") {
from("$buildDirectory/outputs") {
include("android-template.zip")
}
into("$coronaNativeOutputDir/android/resource")
Expand All @@ -885,7 +880,7 @@ tasks.register<Copy>("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")
}
Expand All @@ -897,7 +892,7 @@ fun copyWithAppFilename(dest: String, appName: String?) {
delete("$dest/$coronaAppFileName.aab")
var hasODR = false
parsedBuildProperties.lookup<JsonArray<JsonObject>>("buildSettings.android.onDemandResources").firstOrNull()?.forEach {
it["resource"].let { res ->
it["resource"].let {
hasODR = true
}
}
Expand All @@ -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")
}
}
Expand Down Expand Up @@ -1108,7 +1103,7 @@ tasks.create<Copy>("copySplashScreen") {

tasks.register<Zip>("createExpansionFile") {
enabled = isExpansionFileRequired
destinationDirectory.set(file("$buildDir/outputs"))
destinationDirectory.set(file("$buildDirectory/outputs"))
archiveFileName.set(coronaExpansionFileName)

from(coronaSrcDir) {
Expand Down
6 changes: 5 additions & 1 deletion platform/android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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.** { *; }
1 change: 0 additions & 1 deletion platform/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="com.corona.app"
android:installLocation="auto">
<!--
This manifest is usually generated by setUpCoronaAppAndPlugins task.
Expand Down
2 changes: 1 addition & 1 deletion platform/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
classpath("com.android.tools.build:gradle:7.4.2")
classpath("com.android.tools.build:gradle:8.5.1")
classpath("com.beust:klaxon:5.0.1")
}
}
Expand Down
3 changes: 0 additions & 3 deletions platform/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
org.gradle.jvmargs=-Xmx1280m

# android.bundle.enableUncompressedNativeLibs=true

# Migrate To Android X
android.useAndroidX=true
android.enableJetifier=true
android.enableResourceOptimizations=false
Binary file modified platform/android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions platform/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Mon Jul 24 23:10:14 CDT 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 733926f

Please sign in to comment.