Conversion to Gradle KTS (#33772)

* Convert settings.gradle to Kotlin Script

Stage 1 of #33742

Signed-off-by: clocks <doomsdayrs@gmail.com>

* servoview-local: Convert build.gradle to Kotlin Script

Stage 1 of #33742

Signed-off-by: clocks <doomsdayrs@gmail.com>

* Convert build.gradle to Kotlin Script

This was a trickier one, as I wanted to maintain compatibility with the rest of the files while facilitating this migration.

Closures are annoying, another annoyance of loosely typed languages in an OOP project.

Migration of child build scripts will require the reverse code and or migration of this scripts functions to kotlin lambdas / functions (which are just jvm functions).

Code based off of the following guide.
https://docs.gradle.org/current/userguide/kotlin_dsl.html#groovy_closures_from_kotlin

Stage 1 of #33742

Signed-off-by: clocks <doomsdayrs@gmail.com>

* servoapp: Convert build.gradle to Kotlin Script

Migrated deprecated API usages.
There are two more, but ignored for now.
("splits.density", "capitalize")

Stage 1 of #33742

Signed-off-by: clocks <doomsdayrs@gmail.com>

* servoview: Convert build.gradle to Kotlin Script

Migrated deprecated API usages.
There are two more, but ignored for now.
("splits.density", "capitalize")

Stage 1 of #33742

Signed-off-by: clocks <doomsdayrs@gmail.com>

* servoview: Replace ResourceGroovyMethods with Kotlin File.walk

Signed-off-by: clocks <doomsdayrs@gmail.com>

* Replace Groovy Closures with Kotlin Lambda types

Stage 1 of #33742

Signed-off-by: clocks <doomsdayrs@gmail.com>

* Move Utility fields to buildSrc

Using extra fields is quite annoying and makes it hard to maintain
 API stability.

"buildSrc" is designed for this task, and thus is being used
 for said task.

This means that when editing build.gradle files in an Android Studio,
 there is a direct reference to the source of a function.
 (Easier time referring to documentation, source of function, etc).

More information here:
https://docs.gradle.org/current/userguide/sharing_build_logic_between_subprojects.html

Stage 1 of #33742

Signed-off-by: clocks <doomsdayrs@gmail.com>

* Sync target SDK to 33

Signed-off-by: clocks <doomsdayrs@gmail.com>

* Make Notification actions immutable.

Otherwise android lint will be upset.

Signed-off-by: clocks <doomsdayrs@gmail.com>

* Move dependencies from servoview to servoapp

ServoView does not use them.

Signed-off-by: clocks <doomsdayrs@gmail.com>

* Add POST_NOTIFICATIONS to manifest

Signed-off-by: clocks <doomsdayrs@gmail.com>

* Add host to intent-filter

Use "*" for any host, lets hope this works.

Signed-off-by: clocks <doomsdayrs@gmail.com>

* Solve ndkBuild tasks not being linked

The problem stems from something something groovy wishy washy unclear
 execution order something Kotlin explicit execution order.

Merge tasks exist after the project is evaluated.
 The problem is that simply running afterEvaluate causes an
 ConcurrentModificationException. This is because of creating a new
 task while looping over existing tasks. To remedy this we simply
 filter the tasks first, than create and link the new task.

Signed-off-by: clocks <doomsdayrs@gmail.com>

* Add documentation to why some functions are extensions to Project

Signed-off-by: clocks <doomsdayrs@gmail.com>

* android: drop the host directives from AndroidManifest.xml

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>

---------

Signed-off-by: clocks <doomsdayrs@gmail.com>
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
Clocks 2024-11-01 04:04:28 -04:00 committed by GitHub
parent 0d7fa75447
commit cc6f7c5bc4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 602 additions and 569 deletions

View file

@ -1,164 +0,0 @@
plugins {
id 'com.android.application'
}
import java.util.regex.Matcher
import java.util.regex.Pattern
android {
compileSdk 33
buildToolsVersion = "34.0.0"
namespace 'org.servo.servoshell'
buildDir = rootDir.absolutePath + "/../../../target/android/gradle/servoapp"
defaultConfig {
applicationId "org.servo.servoshell"
minSdk 30
targetSdk 30
versionCode generatedVersionCode
versionName "0.0.1" // TODO: Parse Servo's TOML and add git SHA.
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// Share all of that with servoview
flavorDimensions = ["default"]
productFlavors {
basic {
}
}
splits {
density {
enable false
}
abi {
enable false
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java']
}
}
def signingKeyInfo = getSigningKeyInfo()
if (signingKeyInfo) {
signingConfigs {
release {
storeFile signingKeyInfo.storeFile
storePassword signingKeyInfo.storePassword
keyAlias signingKeyInfo.keyAlias
keyPassword signingKeyInfo.keyPassword
}
}
}
buildTypes {
debug {
}
release {
signingConfig signingKeyInfo ? signingConfigs.release : signingConfigs.debug
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
// Custom build types
armv7Debug {
initWith(debug)
ndk {
abiFilters getNDKAbi('armv7')
}
}
armv7Release {
initWith(release)
ndk {
abiFilters getNDKAbi('armv7')
}
}
arm64Debug {
initWith(debug)
ndk {
abiFilters getNDKAbi('arm64')
}
}
arm64Release {
initWith(release)
ndk {
abiFilters getNDKAbi('arm64')
}
}
x86Debug {
initWith(debug)
ndk {
abiFilters getNDKAbi('x86')
}
}
x86Release {
initWith(release)
ndk {
abiFilters getNDKAbi('x86')
}
}
x64Debug {
initWith(debug)
ndk {
abiFilters getNDKAbi('x64')
}
}
x64Release {
initWith(release)
ndk {
abiFilters getNDKAbi('x64')
}
}
}
// Ignore default 'debug' and 'release' build types
variantFilter { variant ->
if(variant.buildType.name == 'release' || variant.buildType.name == 'debug') {
variant.setIgnore(true)
}
}
project.afterEvaluate {
android.applicationVariants.all { variant ->
Pattern pattern = Pattern.compile(/^[\w\d]+([A-Z][\w\d]+)(Debug|Release)/)
Matcher matcher = pattern.matcher(variant.name)
if (!matcher.find()) {
throw new GradleException("Invalid variant name for output: " + variant.name)
}
def arch = matcher.group(1)
def debug = variant.name.contains("Debug")
def finalFolder = getTargetDir(debug, arch)
def finalFile = new File(finalFolder, "servoapp.apk")
variant.outputs.all { output ->
Task copyAndRenameAPKTask = project.task("copyAndRename${variant.name.capitalize()}APK", type: Copy) {
from output.outputFile.getParent()
into finalFolder
include output.outputFileName
rename(output.outputFileName, finalFile.getName())
}
variant.assemble.finalizedBy(copyAndRenameAPKTask)
}
}
}
}
dependencies {
if (findProject(':servoview-local')) {
implementation project(':servoview-local')
} else {
implementation project(':servoview')
}
}

View file

@ -0,0 +1,175 @@
import java.util.regex.Pattern
plugins {
id("com.android.application")
}
android {
compileSdk = 33
buildToolsVersion = "34.0.0"
namespace = "org.servo.servoshell"
layout.buildDirectory = File(rootDir.absolutePath, "/../../../target/android/gradle/servoapp")
defaultConfig {
applicationId = "org.servo.servoshell"
minSdk = 30
targetSdk = 33
versionCode = generatedVersionCode
versionName = "0.0.1" // TODO: Parse Servo"s TOML and add git SHA.
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
// Share all of that with servoview
flavorDimensions.add("default")
productFlavors {
register("basic") {
}
}
splits {
density {
isEnable = false
}
abi {
isEnable = false
}
}
sourceSets {
named("main") {
java.srcDirs("src/main/java")
}
}
val signingKeyInfo = getSigningKeyInfo()
if (signingKeyInfo != null) {
signingConfigs {
register("release") {
storeFile = signingKeyInfo["storeFile"] as File
storePassword = signingKeyInfo["storePassword"] as String
keyAlias = signingKeyInfo["keyAlias"] as String
keyPassword = signingKeyInfo["keyPassword"] as String
}
}
}
buildTypes {
debug {
}
release {
signingConfig =
signingConfigs.getByName(if (signingKeyInfo != null) "release" else "debug")
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
// Custom build types
val debug = getByName("debug")
val release = getByName("release")
register("armv7Debug") {
initWith(debug)
ndk {
abiFilters.add(getNDKAbi("armv7"))
}
}
register("armv7Release") {
initWith(release)
ndk {
abiFilters.add(getNDKAbi("armv7"))
}
}
register("arm64Debug") {
initWith(debug)
ndk {
abiFilters.add(getNDKAbi("arm64"))
}
}
register("arm64Release") {
initWith(release)
ndk {
abiFilters.add(getNDKAbi("arm64"))
}
}
register("x86Debug") {
initWith(debug)
ndk {
abiFilters.add(getNDKAbi("x86"))
}
}
register("x86Release") {
initWith(release)
ndk {
abiFilters.add(getNDKAbi("x86"))
}
}
register("x64Debug") {
initWith(debug)
ndk {
abiFilters.add(getNDKAbi("x64"))
}
}
register("x64Release") {
initWith(release)
ndk {
abiFilters.add(getNDKAbi("x64"))
}
}
}
// Ignore default "debug" and "release" build types
androidComponents {
beforeVariants {
if (it.buildType == "release" || it.buildType == "debug") {
it.enable = false
}
}
}
project.afterEvaluate {
android.applicationVariants.forEach { variant ->
val pattern = Pattern.compile("^[\\w\\d]+([A-Z][\\w\\d]+)(Debug|Release)")
val matcher = pattern.matcher(variant.name)
if (!matcher.find()) {
throw GradleException("Invalid variant name for output: " + variant.name)
}
val arch = matcher.group(1)
val debug = variant.name.contains("Debug")
val finalFolder = getTargetDir(debug, arch)
val finalFile = File(finalFolder, "servoapp.apk")
variant.outputs.forEach { output ->
val copyAndRenameAPKTask =
project.task<Copy>("copyAndRename${variant.name.capitalize()}APK") {
from(output.outputFile.parent)
into(finalFolder)
include(output.outputFile.name)
rename(output.outputFile.name, finalFile.name)
}
variant.assembleProvider.get().finalizedBy(copyAndRenameAPKTask)
}
}
}
}
dependencies {
if (findProject(":servoview-local") != null) {
implementation(project(":servoview-local"))
} else {
implementation(project(":servoview"))
}
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.9.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
}

View file

@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

View file

@ -149,7 +149,7 @@ public class MediaSession {
Intent playIntent = new Intent(KEY_MEDIA_PLAY);
Notification.Action playAction =
new Notification.Action(R.drawable.media_session_play, "Play",
PendingIntent.getBroadcast(mContext, 0, playIntent, 0));
PendingIntent.getBroadcast(mContext, 0, playIntent, PendingIntent.FLAG_IMMUTABLE));
builder.addAction(playAction);
}
@ -157,7 +157,7 @@ public class MediaSession {
Intent pauseIntent = new Intent(KEY_MEDIA_PAUSE);
Notification.Action pauseAction =
new Notification.Action(R.drawable.media_session_pause, "Pause",
PendingIntent.getBroadcast(mContext, 0, pauseIntent, 0));
PendingIntent.getBroadcast(mContext, 0, pauseIntent, PendingIntent.FLAG_IMMUTABLE));
builder.addAction(pauseAction);
}