Skip to content

VERY experimental Nintendo Switch 2 emulator

C++

[android] Fix build id (#3066)

Caio Oliveira61f3ce643c59
diff --git a/src/android/app/build.gradle.kts b/src/android/app/build.gradle.kts
index b03ae732d4..01a413261e 100644
--- a/src/android/app/build.gradle.kts
+++ b/src/android/app/build.gradle.kts
@@ -61,7 +61,6 @@ android {
minSdk = 24
targetSdk = 36
versionName = getGitVersion()
-
versionCode = autoVersion
ndk {
@@ -69,9 +68,6 @@ android {
abiFilters += listOf("arm64-v8a")
}
- buildConfigField("String", "GIT_HASH", "\"${getGitHash()}\"")
- buildConfigField("String", "BRANCH", "\"${getBranch()}\"")
-
externalNativeBuild {
cmake {
val extraCMakeArgs =
@@ -92,14 +88,14 @@ android {
"-DYUZU_TESTS=OFF",
"-DDYNARMIC_TESTS=OFF",
*extraCMakeArgs.toTypedArray()
- ))
+ )
+ )
abiFilters("arm64-v8a")
}
}
}
-
val keystoreFile = System.getenv("ANDROID_KEYSTORE_FILE")
signingConfigs {
if (keystoreFile != null) {
@@ -162,7 +158,39 @@ android {
}
}
- // this is really annoying but idk any other ways to fix this behavior
+ flavorDimensions.add("version")
+ productFlavors {
+ create("mainline") {
+ dimension = "version"
+ resValue("string", "app_name_suffixed", "Eden")
+ }
+
+ create("genshinSpoof") {
+ dimension = "version"
+ resValue("string", "app_name_suffixed", "Eden Optimized")
+ applicationId = "com.miHoYo.Yuanshen"
+ }
+
+ create("legacy") {
+ dimension = "version"
+ resValue("string", "app_name_suffixed", "Eden Legacy")
+ applicationId = "dev.legacy.eden_emulator"
+
+ externalNativeBuild {
+ cmake {
+ arguments.add("-DYUZU_LEGACY=ON")
+ }
+ }
+
+ sourceSets {
+ getByName("legacy") {
+ res.srcDirs("src/main/legacy")
+ }
+ }
+ }
+ }
+
+ // this is really annoying but idk any other ways to fix this behavior
applicationVariants.all {
val variant = this
when {
@@ -187,40 +215,6 @@ android {
}
}
- android {
- flavorDimensions.add("version")
- productFlavors {
- create("mainline") {
- dimension = "version"
- resValue("string", "app_name_suffixed", "Eden")
- }
-
- create("genshinSpoof") {
- dimension = "version"
- resValue("string", "app_name_suffixed", "Eden Optimized")
- applicationId = "com.miHoYo.Yuanshen"
- }
-
- create("legacy") {
- dimension = "version"
- resValue("string", "app_name_suffixed", "Eden Legacy")
- applicationId = "dev.legacy.eden_emulator"
-
- externalNativeBuild {
- cmake {
- arguments.add("-DYUZU_LEGACY=ON")
- }
- }
-
- sourceSets {
- getByName("legacy") {
- res.srcDirs("src/main/legacy")
- }
- }
- }
- }
- }
-
externalNativeBuild {
cmake {
version = "3.22.1"
@@ -284,7 +278,6 @@ dependencies {
implementation("androidx.core:core-splashscreen:1.0.1")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.2")
implementation("androidx.window:window:1.3.0")
- implementation("androidx.constraintlayout:constraintlayout:2.2.1")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation("org.commonmark:commonmark:0.22.0")
implementation("androidx.navigation:navigation-fragment-ktx:2.8.9")
@@ -302,7 +295,9 @@ fun runGitCommand(command: List<String>): String {
.directory(project.rootDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
- .start().inputStream.bufferedReader().use { it.readText() }
+ .start()
+ .inputStream.bufferedReader()
+ .use { it.readText() }
.trim()
} catch (e: Exception) {
logger.error("Cannot find git")
@@ -326,9 +321,3 @@ fun getGitVersion(): String {
}
return versionName.ifEmpty { "0.0" }
}
-
-fun getGitHash(): String =
- runGitCommand(listOf("git", "rev-parse", "--short", "HEAD")).ifEmpty { "dummy-hash" }
-
-fun getBranch(): String =
- runGitCommand(listOf("git", "rev-parse", "--abbrev-ref", "HEAD")).ifEmpty { "dummy-hash" }
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt
index 18ace18393..4b93e36254 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt
@@ -227,6 +227,11 @@ object NativeLibrary {
*/
external fun isUpdateCheckerEnabled(): Boolean
+ /**
+ * Returns the build version generated by CMake (BUILD_VERSION).
+ */
+ external fun getBuildVersion(): String
+
enum class CoreError {
ErrorSystemFiles,
ErrorSavestate,
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt
index 88ec13dd4c..edd1b0765d 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AboutFragment.kt
@@ -29,6 +29,7 @@ import org.yuzu.yuzu_emu.R
import org.yuzu.yuzu_emu.databinding.FragmentAboutBinding
import org.yuzu.yuzu_emu.model.HomeViewModel
import org.yuzu.yuzu_emu.utils.ViewUtils.updateMargins
+import org.yuzu.yuzu_emu.NativeLibrary
class AboutFragment : Fragment() {
private var _binding: FragmentAboutBinding? = null
@@ -78,11 +79,15 @@ class AboutFragment : Fragment() {
binding.root.findNavController().navigate(R.id.action_aboutFragment_to_licensesFragment)
}
- binding.textVersionName.text = BuildConfig.VERSION_NAME
+ val buildName = getString(R.string.app_name_suffixed)
+ val buildVersion = NativeLibrary.getBuildVersion()
+ val fullVersionText = "$buildName ($buildVersion)"
+
+ binding.textVersionName.text = fullVersionText
binding.buttonVersionName.setOnClickListener {
val clipBoard =
requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
- val clip = ClipData.newPlainText(getString(R.string.build), BuildConfig.GIT_HASH)
+ val clip = ClipData.newPlainText(getString(R.string.build), fullVersionText)
clipBoard.setPrimaryClip(clip)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
diff --git a/src/android/app/src/main/jni/native.cpp b/src/android/app/src/main/jni/native.cpp
index ffef4f740c..b0a414d1c3 100644
--- a/src/android/app/src/main/jni/native.cpp
+++ b/src/android/app/src/main/jni/native.cpp
@@ -1615,4 +1615,10 @@ JNIEXPORT jstring JNICALL Java_org_yuzu_yuzu_1emu_NativeLibrary_getUpdateUrl(
}
#endif
+JNIEXPORT jstring JNICALL Java_org_yuzu_yuzu_1emu_NativeLibrary_getBuildVersion(
+ JNIEnv* env,
+ [[maybe_unused]] jobject obj) {
+ return env->NewStringUTF(Common::g_build_version);
+}
+
} // extern "C"