Skip to content

Commit

Permalink
Initial Android 33 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
scottrules44 committed Aug 27, 2023
1 parent 451664d commit 220382f
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 55 deletions.
5 changes: 5 additions & 0 deletions plugins/2023.3693/android/corona.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
android.defaultConfig {
minSdkVersion Math.max(minSdkVersion?.apiLevel ?: 15, 16)
}
ext["minSdkVersion"] = Math.max(ext.find("minSdkVersion")?:15, 16)
implementation 'com.google.firebase:firebase-messaging:23.2.1'
Binary file not shown.
Binary file not shown.
13 changes: 13 additions & 0 deletions plugins/2023.3693/iphone-sim/metadata.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local metadata =
{
plugin =
{
format = "staticLibrary",
staticLibs = { 'NotificationsV2Plugin', },
frameworks = { },
frameworksOptional = { "UserNotifications", "UserNotificationsUI" },
delegates = { "CoronaNotificationsDelegate" }
}
}

return metadata
Binary file not shown.
13 changes: 13 additions & 0 deletions plugins/2023.3693/iphone/metadata.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
local metadata =
{
plugin =
{
format = "staticLibrary",
staticLibs = { 'NotificationsV2Plugin', },
frameworks = { },
frameworksOptional = { "UserNotifications", "UserNotificationsUI" },
delegates = { "CoronaNotificationsDelegate" }
}
}

return metadata
50 changes: 50 additions & 0 deletions plugins/2023.3693/mac-sim/plugin_notifications_v2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- Notifications V2 plugin

local Library = require "CoronaLibrary"

-- Create library
local lib = Library:new{ name="plugin.notifications.v2", publisherId="com.coronalabs", version=1 }

-------------------------------------------------------------------------------
-- BEGIN
-------------------------------------------------------------------------------

-- This sample implements the following Lua:
--
-- local notifications = require "plugin.notifications.v2"
--

local function showWarning(functionName)
print( functionName .. " WARNING: The Notifications V2 plugin is only supported on iOS and Android devices")
end

function lib.registerForPushNotifications()
showWarning("notifications.registerForPushNotifications()")
end

function lib.subscribe()
showWarning("notifications.subscribe()")
end

function lib.unsubscribe()
showWarning("notifications.unsubscribe()")
end

function lib.getDeviceToken()
showWarning("notifications.getDeviceToken()")
end

function lib.scheduleNotification()
showWarning("notifications.scheduleNotification()")
end

function lib.cancelNotification()
showWarning("notifications.cancelNotification()")
end

-------------------------------------------------------------------------------
-- END
-------------------------------------------------------------------------------

-- Return an instance
return lib
50 changes: 50 additions & 0 deletions plugins/2023.3693/win32-sim/plugin_notifications_v2.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- Notifications V2 plugin

local Library = require "CoronaLibrary"

-- Create library
local lib = Library:new{ name="plugin.notifications.v2", publisherId="com.coronalabs", version=1 }

-------------------------------------------------------------------------------
-- BEGIN
-------------------------------------------------------------------------------

-- This sample implements the following Lua:
--
-- local notifications = require "plugin.notifications.v2"
--

local function showWarning(functionName)
print( functionName .. " WARNING: The Notifications V2 plugin is only supported on iOS and Android devices")
end

function lib.registerForPushNotifications()
showWarning("notifications.registerForPushNotifications()")
end

function lib.subscribe()
showWarning("notifications.subscribe()")
end

function lib.unsubscribe()
showWarning("notifications.unsubscribe()")
end

function lib.getDeviceToken()
showWarning("notifications.getDeviceToken()")
end

function lib.scheduleNotification()
showWarning("notifications.scheduleNotification()")
end

function lib.cancelNotification()
showWarning("notifications.cancelNotification()")
end

-------------------------------------------------------------------------------
-- END
-------------------------------------------------------------------------------

-- Return an instance
return lib
110 changes: 85 additions & 25 deletions src/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ val coronaSrcDir = project.findProperty("coronaSrcDir") as? String
"$rootDir/../Corona"
}
val coronaBuiltFromSource = file("CMakeLists.txt").exists() && file("../sdk").exists()

val windows = System.getProperty("os.name").toLowerCase().contains("windows")
val shortOsName = if (windows) "win" else "mac"
val linux = System.getProperty("os.name").toLowerCase().contains("linux")
val shortOsName = if (windows) "win" else if (linux) "linux" else "mac"

val nativeDir = if (windows) {
val resourceDir = coronaResourcesDir?.let { file("$it/../Native/").absolutePath }?.takeIf { file(it).exists() }
(resourceDir ?: "${System.getenv("CORONA_PATH")}/Native").replace("\\", "/")
} else if (linux) {
"$coronaResourcesDir/Native"
} else {
val resourceDir = coronaResourcesDir?.let { file("$it/../../../Native/").absolutePath }?.takeIf { file(it).exists() }
resourceDir ?: "${System.getenv("HOME")}/Library/Application Support/Corona/Native/"
Expand All @@ -61,7 +66,7 @@ fun checkCoronaNativeInstallation() {
} else {
val setupNativeApp = File("/Applications").listFiles { f ->
f.isDirectory && f.name.startsWith("Corona")
}?.max()?.let {
}.maxOrNull()?.let {
"${it.absolutePath}/Native/Setup Corona Native.app"
} ?: "Native/Setup Corona Native.app"
throw InvalidUserDataException("Corona Native was not set-up properly. Launch '$setupNativeApp'.")
Expand Down Expand Up @@ -124,16 +129,17 @@ val parsedBuildProperties: JsonObject = run {
return@run JsonObject(mapOf("buildSettings" to parsedBuildSettingsFile, "packageName" to coronaAppPackage, "targetedAppStore" to coronaTargetStore))
}

val coronaMinSdkVersion = parsedBuildProperties.lookup<Any?>("buildSettings.android.minSdkVersion").firstOrNull()?.toString()?.toIntOrNull()
?: 16
extra["minSdkVersion"] = parsedBuildProperties.lookup<Any?>("buildSettings.android.minSdkVersion").firstOrNull()?.toString()?.toIntOrNull()
?: 19

val coronaBuilder = if (windows) {
"$nativeDir/Corona/win/bin/CoronaBuilder.exe"
} else if (linux) {
"$coronaResourcesDir/../Solar2DBuilder"
} else {
"$nativeDir/Corona/$shortOsName/bin/CoronaBuilder.app/Contents/MacOS/CoronaBuilder"
}


val coronaVersionName =
parsedBuildProperties.lookup<Any?>("buildSettings.android.versionName").firstOrNull()?.toString()
?: project.findProperty("coronaVersionName") as? String ?: "1.0"
Expand All @@ -144,6 +150,8 @@ val coronaVersionCode: Int =

val androidDestPluginPlatform = if (coronaTargetStore.equals("amazon", ignoreCase = true)) {
"android-kindle"
} else if (coronaTargetStore.equals("samsung", ignoreCase = true)) {
"android-nongoogle"
} else {
"android"
}
Expand Down Expand Up @@ -182,21 +190,22 @@ if (configureCoronaPlugins == "YES") {
//</editor-fold>

android {
compileOptions {
sourceCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
targetCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
lintOptions {
isCheckReleaseBuilds = true
}

compileSdkVersion(29)
compileSdk = 33
defaultConfig {
applicationId = coronaAppPackage
targetSdkVersion(29)
minSdkVersion(coronaMinSdkVersion)
targetSdk = 33
minSdk = (extra["minSdkVersion"] as Int)
versionCode = coronaVersionCode
versionName = coronaVersionName
multiDexEnabled = true
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
coronaKeystore?.let { keystore ->
signingConfigs {
create("release") {
Expand Down Expand Up @@ -247,6 +256,16 @@ android {
aaptOptions {
additionalParameters("--extra-packages", extraPackages.filter { it.isNotBlank() }.joinToString(":"))
}
if (isExpansionFileRequired) {
assetPacks.add(":preloadedAssets")
}

parsedBuildProperties.lookup<JsonArray<JsonObject>>("buildSettings.android.onDemandResources").firstOrNull()?.forEach {
it["tag"].let { tag ->
assetPacks.add(":pda-$tag")
}
}

// This is dirty hack because Android Assets refuse to copy assets which start with . or _
if (!isExpansionFileRequired) {
android.applicationVariants.all {
Expand All @@ -266,6 +285,35 @@ 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 {
apkFilesSet.add(it.trim())
}
if (!isSimulatorBuild) {
parsedBuildProperties.lookup<JsonArray<String>>("buildSettings.android.apkFiles").firstOrNull()?.forEach {
apkFilesSet.add(it.trim())
}
}
if (apkFilesSet.isNotEmpty()) {
val generatedApkFiles = "$buildDir/generated/apkFiles"
val coronaCopyApkFiles = tasks.create<Copy>("coronaCopyApkFiles") {
description = "Creates new resource directory with raw APK files"
into(generatedApkFiles)
from(coronaSrcDir) {
apkFilesSet.forEach { include(it) }
}
doFirst {
delete(generatedApkFiles)
}
}

android.applicationVariants.all {
preBuildProvider.configure {
dependsOn(coronaCopyApkFiles)
}
android.sourceSets[name].resources.srcDirs(generatedApkFiles)
}
}

fun processPluginGradleScripts() {
fileTree(coronaPlugins) {
Expand Down Expand Up @@ -319,6 +367,12 @@ fun coronaAssetsCopySpec(spec: CopySpec) {
file("$coronaTmpDir/excludesfile.properties").takeIf { it.exists() }?.readLines()?.forEach {
exclude(it)
}
parsedBuildProperties.lookup<JsonArray<JsonObject>>("buildSettings.android.onDemandResources").firstOrNull()?.forEach {
it["resource"].let { res ->
exclude("$res")
exclude("$res/**")
}
}
if (!isSimulatorBuild) {
// use build.settings properties only if this is not simulator build
parsedBuildProperties.lookup<JsonArray<String>>("buildSettings.excludeFiles.all").firstOrNull()?.forEach {
Expand Down Expand Up @@ -463,7 +517,7 @@ android.applicationVariants.all {
}
doFirst {
if (!file(coronaSrcDir).isDirectory) {
throw InvalidUserDataException("Unable to find Corona project to build!")
throw InvalidUserDataException("Unable to find Solar2D project (for example platform/test/assets2/main.lua)!")
}
}
}
Expand Down Expand Up @@ -752,6 +806,8 @@ tasks.register<Zip>("exportCoronaAppTemplate") {
exclude("app/build/**", "app/CMakeLists.txt")
exclude("**/*.iml", "**/\\.*")
include("setup.sh", "setup.bat")
include("preloadedAssets/build.gradle.kts")
include("PAD.kts.template")
into("template")
}
from(android.sdkDirectory) {
Expand Down Expand Up @@ -811,7 +867,7 @@ tasks.register<Copy>("exportToNativeAppTemplate") {
val coronaNativeOutputDir = project.findProperty("coronaNativeOutputDir") as? String
?: "$nativeDir/Corona"

tasks.register<Copy>("installAppTemplateToNative") {
tasks.register<Copy>("installAppTemplateToSim") {
if (coronaBuiltFromSource) group = "Corona-dev"
enabled = coronaBuiltFromSource
dependsOn("exportCoronaAppTemplate")
Expand All @@ -821,10 +877,10 @@ tasks.register<Copy>("installAppTemplateToNative") {
into("$coronaNativeOutputDir/android/resource")
}

tasks.register<Copy>("installAppTemplateAndAARToNative") {
tasks.register<Copy>("installAppTemplateAndAARToSim") {
if (coronaBuiltFromSource) group = "Corona-dev"
enabled = coronaBuiltFromSource
dependsOn("installAppTemplateToNative")
dependsOn("installAppTemplateToSim")
dependsOn(":Corona:assembleRelease")
from("${findProject(":Corona")?.buildDir}/outputs/aar/") {
include("Corona-release.aar")
Expand All @@ -836,15 +892,24 @@ tasks.register<Copy>("installAppTemplateAndAARToNative") {
fun copyWithAppFilename(dest: String, appName: String?) {
delete("$dest/$coronaAppFileName.apk")
delete("$dest/$coronaAppFileName.aab")
var hasODR = false
parsedBuildProperties.lookup<JsonArray<JsonObject>>("buildSettings.android.onDemandResources").firstOrNull()?.forEach {
it["resource"].let { res ->
hasODR = true
}
}

copy {
into(dest)
val copyTask = this
android.applicationVariants.matching {
it.name.equals("release", true)
}.all {
copyTask.from(packageApplicationProvider!!.get().outputDirectory) {
include("*.apk")
exclude("*unsigned*")
if(!isExpansionFileRequired && !hasODR) {
copyTask.from(packageApplicationProvider!!.get().outputDirectory) {
include("*.apk")
exclude("*unsigned*")
}
}
copyTask.from("$buildDir/outputs/bundle/$name") {
include("*.aab")
Expand Down Expand Up @@ -877,10 +942,6 @@ tasks.create("buildCoronaApp") {
}
}
delete("$it/$coronaExpansionFileName")
copy {
from("$buildDir/outputs/$coronaExpansionFileName")
into(it)
}
}
}
}
Expand Down Expand Up @@ -1060,7 +1121,6 @@ tasks.register<Zip>("createExpansionFile") {
//</editor-fold>

dependencies {

if (coronaBuiltFromSource) {
implementation(project(":Corona"))
implementation(files("$rootDir/../../plugins/build/licensing-google/android/bin/classes.jar"))
Expand Down
6 changes: 3 additions & 3 deletions src/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ buildscript {
jcenter()
}
dependencies {
classpath(kotlin("gradle-plugin", version = "1.3.70"))
classpath("com.android.tools.build:gradle:3.5.4")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
classpath("com.android.tools.build:gradle:7.4.2")
classpath("com.beust:klaxon:5.0.1")
classpath("com.google.gms:google-services:4.3.10")
classpath("com.google.gms:google-services:4.3.14")
}
}

Expand Down
Loading

0 comments on commit 220382f

Please sign in to comment.