From ab87f7499831b89ebc8e921f7ed9448fd8e6b49a Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Wed, 19 Apr 2023 00:53:59 -0400 Subject: android: Convert gradle scripts to Kotlin DSL --- src/android/app/build.gradle | 190 -------------------------------- src/android/app/build.gradle.kts | 227 +++++++++++++++++++++++++++++++++++++++ src/android/build.gradle | 10 -- src/android/build.gradle.kts | 10 ++ src/android/settings.gradle | 15 --- src/android/settings.gradle.kts | 18 ++++ 6 files changed, 255 insertions(+), 215 deletions(-) delete mode 100644 src/android/app/build.gradle create mode 100644 src/android/app/build.gradle.kts delete mode 100644 src/android/build.gradle create mode 100644 src/android/build.gradle.kts delete mode 100644 src/android/settings.gradle create mode 100644 src/android/settings.gradle.kts diff --git a/src/android/app/build.gradle b/src/android/app/build.gradle deleted file mode 100644 index 09ca9c26f..000000000 --- a/src/android/app/build.gradle +++ /dev/null @@ -1,190 +0,0 @@ -plugins { - id 'com.android.application' - id 'org.jetbrains.kotlin.android' - id 'kotlin-parcelize' -} - -/** - * Use the number of seconds/10 since Jan 1 2016 as the versionCode. - * This lets us upload a new build at most every 10 seconds for the - * next 680 years. - */ -def autoVersion = (int) (((new Date().getTime() / 1000) - 1451606400) / 10) -def buildType - -android { - namespace 'org.yuzu.yuzu_emu' - - compileSdkVersion 33 - ndkVersion "25.2.9519653" - - viewBinding.enabled = true - - compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } - - kotlinOptions { - jvmTarget = '11' - } - - lint { - // This is important as it will run lint but not abort on error - // Lint has some overly obnoxious "errors" that should really be warnings - abortOnError false - - //Uncomment disable lines for test builds... - //disable 'MissingTranslation'bin - //disable 'ExtraTranslation' - } - - defaultConfig { - // TODO If this is ever modified, change application_id in strings.xml - applicationId "org.yuzu.yuzu_emu" - minSdkVersion 28 - targetSdkVersion 33 - versionCode autoVersion - versionName getVersion() - ndk.abiFilters "arm64-v8a", "x86_64" - - buildConfigField "String", "GIT_HASH", "\"${getGitHash()}\"" - buildConfigField "String", "BRANCH", "\"${getBranch()}\"" - } - - signingConfigs { - //release { - // storeFile file('') - // storePassword System.getenv('ANDROID_KEYPASS') - // keyAlias = 'key0' - // keyPassword System.getenv('ANDROID_KEYPASS') - //} - } - - applicationVariants.all { variant -> - buildType = variant.buildType.name // sets the current build type - } - - // Define build types, which are orthogonal to product flavors. - buildTypes { - - // Signed by release key, allowing for upload to Play Store. - release { - signingConfig signingConfigs.debug - } - - // builds a release build that doesn't need signing - // Attaches 'debug' suffix to version and package name, allowing installation alongside the release build. - relWithDebInfo { - initWith release - versionNameSuffix '-debug' - signingConfig signingConfigs.debug - minifyEnabled false - testCoverageEnabled false - debuggable true - jniDebuggable true - } - - // Signed by debug key disallowing distribution on Play Store. - // Attaches 'debug' suffix to version and package name, allowing installation alongside the release build. - debug { - // TODO If this is ever modified, change application_id in debug/strings.xml - versionNameSuffix '-debug' - debuggable true - jniDebuggable true - } - } - - flavorDimensions "version" - productFlavors { - mainline { - dimension "version" - } - } - - externalNativeBuild { - cmake { - version "3.22.1" - path "../../../CMakeLists.txt" - } - } - - defaultConfig { - externalNativeBuild { - cmake { - arguments "-DENABLE_QT=0", // Don't use QT - "-DENABLE_SDL2=0", // Don't use SDL - "-DENABLE_WEB_SERVICE=0", // Don't use telemetry - "-DBUNDLE_SPEEX=ON", - "-DANDROID_ARM_NEON=true", // cryptopp requires Neon to work - "-DYUZU_USE_BUNDLED_VCPKG=ON", - "-DYUZU_USE_BUNDLED_FFMPEG=ON" - - abiFilters "arm64-v8a", "x86_64" - } - } - } -} - -dependencies { - implementation 'androidx.core:core-ktx:1.9.0' - implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'androidx.exifinterface:exifinterface:1.3.6' - implementation 'androidx.cardview:cardview:1.0.0' - implementation 'androidx.recyclerview:recyclerview:1.2.1' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation 'androidx.lifecycle:lifecycle-viewmodel:2.5.1' - implementation 'androidx.fragment:fragment:1.5.5' - implementation "androidx.slidingpanelayout:slidingpanelayout:1.2.0" - implementation "androidx.documentfile:documentfile:1.0.1" - implementation 'com.google.android.material:material:1.8.0' - implementation 'androidx.preference:preference:1.2.0' - implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1" - implementation "io.coil-kt:coil:2.2.2" - implementation 'androidx.core:core-splashscreen:1.0.0' - implementation 'androidx.window:window:1.0.0' - implementation 'org.ini4j:ini4j:0.5.4' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' -} - -def getVersion() { - def versionName = '0.0' - - try { - versionName = 'git describe --always --long'.execute([], project.rootDir).text - .trim() - .replaceAll(/(-0)?-[^-]+$/, "") - } catch (Exception) { - logger.error('Cannot find git, defaulting to dummy version number') - } - - if (System.getenv("GITHUB_ACTIONS") != null) { - def gitTag = System.getenv("GIT_TAG_NAME") - versionName = gitTag ?: versionName - } - - return versionName -} - -def getGitHash() { - try { - def gitHash = 'git rev-parse HEAD'.execute([], project.rootDir).text.trim() - return gitHash - } catch (Exception e) { - logger.error(e + ': Cannot find git, defaulting to dummy build hash') - } - - return '0' -} - -def getBranch() { - try { - def branch = 'git rev-parse --abbrev-ref HEAD'.execute([], project.rootDir).text.trim() - return branch - } catch (Exception e) { - logger.error(e + ': Cannot find git, defaulting to dummy branch') - } - - return 'main' -} diff --git a/src/android/app/build.gradle.kts b/src/android/app/build.gradle.kts new file mode 100644 index 000000000..e2b53c7bd --- /dev/null +++ b/src/android/app/build.gradle.kts @@ -0,0 +1,227 @@ +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") + id("kotlin-parcelize") +} + +/** + * Use the number of seconds/10 since Jan 1 2016 as the versionCode. + * This lets us upload a new build at most every 10 seconds for the + * next 680 years. + */ +val autoVersion = (((System.currentTimeMillis() / 1000) - 1451606400) / 10).toInt() +var buildType = "" + +@Suppress("UnstableApiUsage") +android { + namespace = "org.yuzu.yuzu_emu" + + compileSdkVersion = "android-33" + ndkVersion = "25.2.9519653" + + buildFeatures { + viewBinding = true + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + + kotlinOptions { + jvmTarget = "11" + } + + lint { + // This is important as it will run lint but not abort on error + // Lint has some overly obnoxious "errors" that should really be warnings + abortOnError = false + + //Uncomment disable lines for test builds... + //disable 'MissingTranslation'bin + //disable 'ExtraTranslation' + } + + defaultConfig { + // TODO If this is ever modified, change application_id in strings.xml + applicationId = "org.yuzu.yuzu_emu" + minSdk = 28 + targetSdk = 33 + versionCode = autoVersion + versionName = getVersion() + + ndk { + abiFilters += listOf("arm64-v8a", "x86_64") + } + + buildConfigField("String", "GIT_HASH", "\"${getGitHash()}\"") + buildConfigField("String", "BRANCH", "\"${getBranch()}\"") + } + + signingConfigs { + //release { + // storeFile file('') + // storePassword System.getenv('ANDROID_KEYPASS') + // keyAlias = 'key0' + // keyPassword System.getenv('ANDROID_KEYPASS') + //} + } + + applicationVariants.all { variant -> + buildType = variant.buildType.name // sets the current build type + true + } + + // Define build types, which are orthogonal to product flavors. + buildTypes { + + // Signed by release key, allowing for upload to Play Store. + release { + signingConfig = signingConfigs.getByName("debug") + } + + // builds a release build that doesn't need signing + // Attaches 'debug' suffix to version and package name, allowing installation alongside the release build. + register("relWithDebInfo") { + initWith(getByName("release")) + versionNameSuffix = "-debug" + signingConfig = signingConfigs.getByName("debug") + isMinifyEnabled = false + enableAndroidTestCoverage = false + isDebuggable = true + isJniDebuggable = true + } + + // Signed by debug key disallowing distribution on Play Store. + // Attaches 'debug' suffix to version and package name, allowing installation alongside the release build. + debug { + // TODO If this is ever modified, change application_id in debug/strings.xml + versionNameSuffix = "-debug" + isDebuggable = true + isJniDebuggable = true + } + } + + flavorDimensions.add("version") + productFlavors { + create("mainline") { + dimension = "version" + } + } + + externalNativeBuild { + cmake { + version = "3.22.1" + path = file("../../../CMakeLists.txt") + } + } + + defaultConfig { + externalNativeBuild { + cmake { + arguments( + "-DENABLE_QT=0", // Don't use QT + "-DENABLE_SDL2=0", // Don't use SDL + "-DENABLE_WEB_SERVICE=0", // Don't use telemetry + "-DBUNDLE_SPEEX=ON", + "-DANDROID_ARM_NEON=true", // cryptopp requires Neon to work + "-DYUZU_USE_BUNDLED_VCPKG=ON", + "-DYUZU_USE_BUNDLED_FFMPEG=ON" + ) + + abiFilters("arm64-v8a", "x86_64") + } + } + } +} + +dependencies { + implementation("androidx.core:core-ktx:1.9.0") + implementation("androidx.appcompat:appcompat:1.6.1") + implementation("androidx.exifinterface:exifinterface:1.3.6") + implementation("androidx.cardview:cardview:1.0.0") + implementation("androidx.recyclerview:recyclerview:1.2.1") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + implementation("androidx.lifecycle:lifecycle-viewmodel:2.5.1") + implementation("androidx.fragment:fragment:1.5.5") + implementation("androidx.slidingpanelayout:slidingpanelayout:1.2.0") + implementation("androidx.documentfile:documentfile:1.0.1") + implementation("com.google.android.material:material:1.8.0") + implementation("androidx.preference:preference:1.2.0") + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1") + implementation("io.coil-kt:coil:2.2.2") + implementation("androidx.core:core-splashscreen:1.0.0") + implementation("androidx.window:window:1.0.0") + implementation("org.ini4j:ini4j:0.5.4") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0") +} + +fun getVersion(): String { + var versionName = "0.0" + + try { + versionName = ProcessBuilder("git", "describe", "--always", "--long") + .directory(project.rootDir) + .redirectOutput(ProcessBuilder.Redirect.PIPE) + .redirectError(ProcessBuilder.Redirect.PIPE) + .start().inputStream.bufferedReader().use { it.readText() } + .trim() + .replace(Regex("(-0)?-[^-]+$"), "") + } catch (e: Exception) { + logger.error("Cannot find git, defaulting to dummy version number") + } + + if (System.getenv("GITHUB_ACTIONS") != null) { + val gitTag = System.getenv("GIT_TAG_NAME") + versionName = gitTag ?: versionName + } + + return versionName +} + +fun getGitHash(): String { + try { + val processBuilder = ProcessBuilder("git", "rev-parse", "HEAD") + processBuilder.directory(project.rootDir) + val process = processBuilder.start() + val inputStream = process.inputStream + val errorStream = process.errorStream + process.waitFor() + + return if (process.exitValue() == 0) { + inputStream.bufferedReader() + .use { it.readText().trim() } // return the value of gitHash + } else { + val errorMessage = errorStream.bufferedReader().use { it.readText().trim() } + logger.error("Error running git command: $errorMessage") + "dummy-hash" // return a dummy hash value in case of an error + } + } catch (e: Exception) { + logger.error("$e: Cannot find git, defaulting to dummy build hash") + return "dummy-hash" // return a dummy hash value in case of an error + } +} + +fun getBranch(): String { + try { + val processBuilder = ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD") + processBuilder.directory(project.rootDir) + val process = processBuilder.start() + val inputStream = process.inputStream + val errorStream = process.errorStream + process.waitFor() + + return if (process.exitValue() == 0) { + inputStream.bufferedReader() + .use { it.readText().trim() } // return the value of gitHash + } else { + val errorMessage = errorStream.bufferedReader().use { it.readText().trim() } + logger.error("Error running git command: $errorMessage") + "dummy-hash" // return a dummy hash value in case of an error + } + } catch (e: Exception) { + logger.error("$e: Cannot find git, defaulting to dummy build hash") + return "dummy-hash" // return a dummy hash value in case of an error + } +} diff --git a/src/android/build.gradle b/src/android/build.gradle deleted file mode 100644 index e2c06c58c..000000000 --- a/src/android/build.gradle +++ /dev/null @@ -1,10 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -plugins { - id 'com.android.application' version '7.4.2' apply false - id 'com.android.library' version '7.4.2' apply false - id 'org.jetbrains.kotlin.android' version '1.8.10' apply false -} - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/src/android/build.gradle.kts b/src/android/build.gradle.kts new file mode 100644 index 000000000..442209666 --- /dev/null +++ b/src/android/build.gradle.kts @@ -0,0 +1,10 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + id("com.android.application") version "7.4.2" apply false + id("com.android.library") version "7.4.2" apply false + id("org.jetbrains.kotlin.android") version "1.8.10" apply false +} + +tasks.register("clean").configure { + delete(rootProject.buildDir) +} diff --git a/src/android/settings.gradle b/src/android/settings.gradle deleted file mode 100644 index 1e7b2cc14..000000000 --- a/src/android/settings.gradle +++ /dev/null @@ -1,15 +0,0 @@ -pluginManagement { - repositories { - gradlePluginPortal() - google() - mavenCentral() - } -} -dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) - repositories { - google() - mavenCentral() - } -} -include ':app' diff --git a/src/android/settings.gradle.kts b/src/android/settings.gradle.kts new file mode 100644 index 000000000..1fb82df41 --- /dev/null +++ b/src/android/settings.gradle.kts @@ -0,0 +1,18 @@ +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} + +@Suppress("UnstableApiUsage") +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +include(":app") -- cgit v1.2.3