@@ -39,11 +39,16 @@ val coronaSrcDir = project.findProperty("coronaSrcDir") as? String
3939 " $rootDir /../Corona"
4040 }
4141val coronaBuiltFromSource = file(" CMakeLists.txt" ).exists() && file(" ../sdk" ).exists()
42+
4243val windows = System .getProperty(" os.name" ).toLowerCase().contains(" windows" )
43- val shortOsName = if (windows) " win" else " mac"
44+ val linux = System .getProperty(" os.name" ).toLowerCase().contains(" linux" )
45+ val shortOsName = if (windows) " win" else if (linux) " linux" else " mac"
46+
4447val nativeDir = if (windows) {
4548 val resourceDir = coronaResourcesDir?.let { file(" $it /../Native/" ).absolutePath }?.takeIf { file(it).exists() }
4649 (resourceDir ? : " ${System .getenv(" CORONA_PATH" )} /Native" ).replace(" \\ " , " /" )
50+ } else if (linux) {
51+ " $coronaResourcesDir /Native"
4752} else {
4853 val resourceDir = coronaResourcesDir?.let { file(" $it /../../../Native/" ).absolutePath }?.takeIf { file(it).exists() }
4954 resourceDir ? : " ${System .getenv(" HOME" )} /Library/Application Support/Corona/Native/"
@@ -61,7 +66,7 @@ fun checkCoronaNativeInstallation() {
6166 } else {
6267 val setupNativeApp = File (" /Applications" ).listFiles { f ->
6368 f.isDirectory && f.name.startsWith(" Corona" )
64- }?.max ()?.let {
69+ }.maxOrNull ()?.let {
6570 " ${it.absolutePath} /Native/Setup Corona Native.app"
6671 } ? : " Native/Setup Corona Native.app"
6772 throw InvalidUserDataException (" Corona Native was not set-up properly. Launch '$setupNativeApp '." )
@@ -124,16 +129,17 @@ val parsedBuildProperties: JsonObject = run {
124129 return @run JsonObject (mapOf (" buildSettings" to parsedBuildSettingsFile, " packageName" to coronaAppPackage, " targetedAppStore" to coronaTargetStore))
125130}
126131
127- val coronaMinSdkVersion = parsedBuildProperties.lookup<Any ?>(" buildSettings.android.minSdkVersion" ).firstOrNull()?.toString()?.toIntOrNull()
128- ? : 16
132+ extra[ " minSdkVersion " ] = parsedBuildProperties.lookup<Any ?>(" buildSettings.android.minSdkVersion" ).firstOrNull()?.toString()?.toIntOrNull()
133+ ? : 19
129134
130135val coronaBuilder = if (windows) {
131136 " $nativeDir /Corona/win/bin/CoronaBuilder.exe"
137+ } else if (linux) {
138+ " $coronaResourcesDir /../Solar2DBuilder"
132139} else {
133140 " $nativeDir /Corona/$shortOsName /bin/CoronaBuilder.app/Contents/MacOS/CoronaBuilder"
134141}
135142
136-
137143val coronaVersionName =
138144 parsedBuildProperties.lookup<Any ?>(" buildSettings.android.versionName" ).firstOrNull()?.toString()
139145 ? : project.findProperty(" coronaVersionName" ) as ? String ? : " 1.0"
@@ -144,6 +150,8 @@ val coronaVersionCode: Int =
144150
145151val androidDestPluginPlatform = if (coronaTargetStore.equals(" amazon" , ignoreCase = true )) {
146152 " android-kindle"
153+ } else if (coronaTargetStore.equals(" samsung" , ignoreCase = true )) {
154+ " android-nongoogle"
147155} else {
148156 " android"
149157}
@@ -182,21 +190,22 @@ if (configureCoronaPlugins == "YES") {
182190// </editor-fold>
183191
184192android {
185- compileOptions {
186- sourceCompatibility = org.gradle.api.JavaVersion .VERSION_1_8
187- targetCompatibility = org.gradle.api.JavaVersion .VERSION_1_8
193+ lintOptions {
194+ isCheckReleaseBuilds = true
188195 }
189-
190- compileSdkVersion(29 )
196+ compileSdk = 33
191197 defaultConfig {
192198 applicationId = coronaAppPackage
193- targetSdkVersion( 29 )
194- minSdkVersion(coronaMinSdkVersion )
199+ targetSdk = 33
200+ minSdk = (extra[ " minSdkVersion " ] as Int )
195201 versionCode = coronaVersionCode
196202 versionName = coronaVersionName
197203 multiDexEnabled = true
198204 }
199-
205+ compileOptions {
206+ sourceCompatibility = JavaVersion .VERSION_11
207+ targetCompatibility = JavaVersion .VERSION_11
208+ }
200209 coronaKeystore?.let { keystore ->
201210 signingConfigs {
202211 create(" release" ) {
@@ -247,6 +256,16 @@ android {
247256 aaptOptions {
248257 additionalParameters(" --extra-packages" , extraPackages.filter { it.isNotBlank() }.joinToString(" :" ))
249258 }
259+ if (isExpansionFileRequired) {
260+ assetPacks.add(" :preloadedAssets" )
261+ }
262+
263+ parsedBuildProperties.lookup<JsonArray <JsonObject >>(" buildSettings.android.onDemandResources" ).firstOrNull()?.forEach {
264+ it[" tag" ].let { tag ->
265+ assetPacks.add(" :pda-$tag " )
266+ }
267+ }
268+
250269 // This is dirty hack because Android Assets refuse to copy assets which start with . or _
251270 if (! isExpansionFileRequired) {
252271 android.applicationVariants.all {
@@ -266,6 +285,35 @@ android {
266285}
267286
268287// <editor-fold desc="Packaging Corona App" defaultstate="collapsed">
288+ val apkFilesSet = mutableSetOf<String >()
289+ file(" $buildDir /intermediates/corona_manifest_gen/CopyToApk.txt" ).takeIf { it.exists() }?.readLines()?.forEach {
290+ apkFilesSet.add(it.trim())
291+ }
292+ if (! isSimulatorBuild) {
293+ parsedBuildProperties.lookup<JsonArray <String >>(" buildSettings.android.apkFiles" ).firstOrNull()?.forEach {
294+ apkFilesSet.add(it.trim())
295+ }
296+ }
297+ if (apkFilesSet.isNotEmpty()) {
298+ val generatedApkFiles = " $buildDir /generated/apkFiles"
299+ val coronaCopyApkFiles = tasks.create<Copy >(" coronaCopyApkFiles" ) {
300+ description = " Creates new resource directory with raw APK files"
301+ into(generatedApkFiles)
302+ from(coronaSrcDir) {
303+ apkFilesSet.forEach { include(it) }
304+ }
305+ doFirst {
306+ delete(generatedApkFiles)
307+ }
308+ }
309+
310+ android.applicationVariants.all {
311+ preBuildProvider.configure {
312+ dependsOn(coronaCopyApkFiles)
313+ }
314+ android.sourceSets[name].resources.srcDirs(generatedApkFiles)
315+ }
316+ }
269317
270318fun processPluginGradleScripts () {
271319 fileTree(coronaPlugins) {
@@ -319,6 +367,12 @@ fun coronaAssetsCopySpec(spec: CopySpec) {
319367 file(" $coronaTmpDir /excludesfile.properties" ).takeIf { it.exists() }?.readLines()?.forEach {
320368 exclude(it)
321369 }
370+ parsedBuildProperties.lookup<JsonArray <JsonObject >>(" buildSettings.android.onDemandResources" ).firstOrNull()?.forEach {
371+ it[" resource" ].let { res ->
372+ exclude(" $res " )
373+ exclude(" $res /**" )
374+ }
375+ }
322376 if (! isSimulatorBuild) {
323377 // use build.settings properties only if this is not simulator build
324378 parsedBuildProperties.lookup<JsonArray <String >>(" buildSettings.excludeFiles.all" ).firstOrNull()?.forEach {
@@ -463,7 +517,7 @@ android.applicationVariants.all {
463517 }
464518 doFirst {
465519 if (! file(coronaSrcDir).isDirectory) {
466- throw InvalidUserDataException (" Unable to find Corona project to build !" )
520+ throw InvalidUserDataException (" Unable to find Solar2D project (for example platform/test/assets2/main.lua) !" )
467521 }
468522 }
469523 }
@@ -752,6 +806,8 @@ tasks.register<Zip>("exportCoronaAppTemplate") {
752806 exclude(" app/build/**" , " app/CMakeLists.txt" )
753807 exclude(" **/*.iml" , " **/\\ .*" )
754808 include(" setup.sh" , " setup.bat" )
809+ include(" preloadedAssets/build.gradle.kts" )
810+ include(" PAD.kts.template" )
755811 into(" template" )
756812 }
757813 from(android.sdkDirectory) {
@@ -811,7 +867,7 @@ tasks.register<Copy>("exportToNativeAppTemplate") {
811867val coronaNativeOutputDir = project.findProperty(" coronaNativeOutputDir" ) as ? String
812868 ? : " $nativeDir /Corona"
813869
814- tasks.register<Copy >(" installAppTemplateToNative " ) {
870+ tasks.register<Copy >(" installAppTemplateToSim " ) {
815871 if (coronaBuiltFromSource) group = " Corona-dev"
816872 enabled = coronaBuiltFromSource
817873 dependsOn(" exportCoronaAppTemplate" )
@@ -821,10 +877,10 @@ tasks.register<Copy>("installAppTemplateToNative") {
821877 into(" $coronaNativeOutputDir /android/resource" )
822878}
823879
824- tasks.register<Copy >(" installAppTemplateAndAARToNative " ) {
880+ tasks.register<Copy >(" installAppTemplateAndAARToSim " ) {
825881 if (coronaBuiltFromSource) group = " Corona-dev"
826882 enabled = coronaBuiltFromSource
827- dependsOn(" installAppTemplateToNative " )
883+ dependsOn(" installAppTemplateToSim " )
828884 dependsOn(" :Corona:assembleRelease" )
829885 from(" ${findProject(" :Corona" )?.buildDir} /outputs/aar/" ) {
830886 include(" Corona-release.aar" )
@@ -836,15 +892,24 @@ tasks.register<Copy>("installAppTemplateAndAARToNative") {
836892fun copyWithAppFilename (dest : String , appName : String? ) {
837893 delete(" $dest /$coronaAppFileName .apk" )
838894 delete(" $dest /$coronaAppFileName .aab" )
895+ var hasODR = false
896+ parsedBuildProperties.lookup<JsonArray <JsonObject >>(" buildSettings.android.onDemandResources" ).firstOrNull()?.forEach {
897+ it[" resource" ].let { res ->
898+ hasODR = true
899+ }
900+ }
901+
839902 copy {
840903 into(dest)
841904 val copyTask = this
842905 android.applicationVariants.matching {
843906 it.name.equals(" release" , true )
844907 }.all {
845- copyTask.from(packageApplicationProvider!! .get().outputDirectory) {
846- include(" *.apk" )
847- exclude(" *unsigned*" )
908+ if (! isExpansionFileRequired && ! hasODR) {
909+ copyTask.from(packageApplicationProvider!! .get().outputDirectory) {
910+ include(" *.apk" )
911+ exclude(" *unsigned*" )
912+ }
848913 }
849914 copyTask.from(" $buildDir /outputs/bundle/$name " ) {
850915 include(" *.aab" )
@@ -877,10 +942,6 @@ tasks.create("buildCoronaApp") {
877942 }
878943 }
879944 delete(" $it /$coronaExpansionFileName " )
880- copy {
881- from(" $buildDir /outputs/$coronaExpansionFileName " )
882- into(it)
883- }
884945 }
885946 }
886947}
@@ -1060,7 +1121,6 @@ tasks.register<Zip>("createExpansionFile") {
10601121// </editor-fold>
10611122
10621123dependencies {
1063-
10641124 if (coronaBuiltFromSource) {
10651125 implementation(project(" :Corona" ))
10661126 implementation(files(" $rootDir /../../plugins/build/licensing-google/android/bin/classes.jar" ))
0 commit comments