Skip to content

Commit 220382f

Browse files
committed
Initial Android 33 Support
1 parent 451664d commit 220382f

17 files changed

Lines changed: 289 additions & 55 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
android.defaultConfig {
2+
minSdkVersion Math.max(minSdkVersion?.apiLevel ?: 15, 16)
3+
}
4+
ext["minSdkVersion"] = Math.max(ext.find("minSdkVersion")?:15, 16)
5+
implementation 'com.google.firebase:firebase-messaging:23.2.1'
21 KB
Binary file not shown.
200 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
local metadata =
2+
{
3+
plugin =
4+
{
5+
format = "staticLibrary",
6+
staticLibs = { 'NotificationsV2Plugin', },
7+
frameworks = { },
8+
frameworksOptional = { "UserNotifications", "UserNotificationsUI" },
9+
delegates = { "CoronaNotificationsDelegate" }
10+
}
11+
}
12+
13+
return metadata
211 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
local metadata =
2+
{
3+
plugin =
4+
{
5+
format = "staticLibrary",
6+
staticLibs = { 'NotificationsV2Plugin', },
7+
frameworks = { },
8+
frameworksOptional = { "UserNotifications", "UserNotificationsUI" },
9+
delegates = { "CoronaNotificationsDelegate" }
10+
}
11+
}
12+
13+
return metadata
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- Notifications V2 plugin
2+
3+
local Library = require "CoronaLibrary"
4+
5+
-- Create library
6+
local lib = Library:new{ name="plugin.notifications.v2", publisherId="com.coronalabs", version=1 }
7+
8+
-------------------------------------------------------------------------------
9+
-- BEGIN
10+
-------------------------------------------------------------------------------
11+
12+
-- This sample implements the following Lua:
13+
--
14+
-- local notifications = require "plugin.notifications.v2"
15+
--
16+
17+
local function showWarning(functionName)
18+
print( functionName .. " WARNING: The Notifications V2 plugin is only supported on iOS and Android devices")
19+
end
20+
21+
function lib.registerForPushNotifications()
22+
showWarning("notifications.registerForPushNotifications()")
23+
end
24+
25+
function lib.subscribe()
26+
showWarning("notifications.subscribe()")
27+
end
28+
29+
function lib.unsubscribe()
30+
showWarning("notifications.unsubscribe()")
31+
end
32+
33+
function lib.getDeviceToken()
34+
showWarning("notifications.getDeviceToken()")
35+
end
36+
37+
function lib.scheduleNotification()
38+
showWarning("notifications.scheduleNotification()")
39+
end
40+
41+
function lib.cancelNotification()
42+
showWarning("notifications.cancelNotification()")
43+
end
44+
45+
-------------------------------------------------------------------------------
46+
-- END
47+
-------------------------------------------------------------------------------
48+
49+
-- Return an instance
50+
return lib
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- Notifications V2 plugin
2+
3+
local Library = require "CoronaLibrary"
4+
5+
-- Create library
6+
local lib = Library:new{ name="plugin.notifications.v2", publisherId="com.coronalabs", version=1 }
7+
8+
-------------------------------------------------------------------------------
9+
-- BEGIN
10+
-------------------------------------------------------------------------------
11+
12+
-- This sample implements the following Lua:
13+
--
14+
-- local notifications = require "plugin.notifications.v2"
15+
--
16+
17+
local function showWarning(functionName)
18+
print( functionName .. " WARNING: The Notifications V2 plugin is only supported on iOS and Android devices")
19+
end
20+
21+
function lib.registerForPushNotifications()
22+
showWarning("notifications.registerForPushNotifications()")
23+
end
24+
25+
function lib.subscribe()
26+
showWarning("notifications.subscribe()")
27+
end
28+
29+
function lib.unsubscribe()
30+
showWarning("notifications.unsubscribe()")
31+
end
32+
33+
function lib.getDeviceToken()
34+
showWarning("notifications.getDeviceToken()")
35+
end
36+
37+
function lib.scheduleNotification()
38+
showWarning("notifications.scheduleNotification()")
39+
end
40+
41+
function lib.cancelNotification()
42+
showWarning("notifications.cancelNotification()")
43+
end
44+
45+
-------------------------------------------------------------------------------
46+
-- END
47+
-------------------------------------------------------------------------------
48+
49+
-- Return an instance
50+
return lib

src/android/app/build.gradle.kts

Lines changed: 85 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,16 @@ val coronaSrcDir = project.findProperty("coronaSrcDir") as? String
3939
"$rootDir/../Corona"
4040
}
4141
val coronaBuiltFromSource = file("CMakeLists.txt").exists() && file("../sdk").exists()
42+
4243
val 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+
4447
val 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

130135
val 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-
137143
val 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

145151
val 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

184192
android {
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

270318
fun 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") {
811867
val 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") {
836892
fun 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

10621123
dependencies {
1063-
10641124
if (coronaBuiltFromSource) {
10651125
implementation(project(":Corona"))
10661126
implementation(files("$rootDir/../../plugins/build/licensing-google/android/bin/classes.jar"))

src/android/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ buildscript {
44
jcenter()
55
}
66
dependencies {
7-
classpath(kotlin("gradle-plugin", version = "1.3.70"))
8-
classpath("com.android.tools.build:gradle:3.5.4")
7+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
8+
classpath("com.android.tools.build:gradle:7.4.2")
99
classpath("com.beust:klaxon:5.0.1")
10-
classpath("com.google.gms:google-services:4.3.10")
10+
classpath("com.google.gms:google-services:4.3.14")
1111
}
1212
}
1313

0 commit comments

Comments
 (0)