Jelajahi Sumber

Add logic to record the version of the Godot engine for the Android platform.

(cherry picked from commit bc5120eb979f98e136a3e980001139d4f862e7e9)
Fredia Huya-Kouadio 4 tahun lalu
induk
melakukan
9fb5215db5

+ 1 - 0
platform/android/export/export.cpp

@@ -2916,6 +2916,7 @@ public:
 			cmdline.push_back("-Pplugins_maven_repos=" + custom_maven_repos); // argument to specify the list of custom maven repos for the plugins dependencies.
 			cmdline.push_back("-Pperform_zipalign=" + zipalign_flag); // argument to specify whether the build should be zipaligned.
 			cmdline.push_back("-Pperform_signing=" + sign_flag); // argument to specify whether the build should be signed.
+			cmdline.push_back("-Pgodot_editor_version=" + String(VERSION_FULL_CONFIG));
 
 			// NOTE: The release keystore is not included in the verbose logging
 			// to avoid accidentally leaking sensitive information when sharing verbose logs for troubleshooting.

+ 5 - 0
platform/android/java/app/AndroidManifest.xml

@@ -29,6 +29,11 @@
     <!-- WARNING: This should stay on a single line until the parsing code is improved. See GH-32414. -->
     <application android:label="@string/godot_project_name_string" android:allowBackup="false" tools:ignore="GoogleAppIndexingWarning" android:icon="@mipmap/icon" >
 
+        <!-- Records the version of the Godot editor used for building -->
+        <meta-data
+            android:name="org.godotengine.editor.version"
+            android:value="${godotEditorVersion}" />
+
         <!-- The following metadata values are replaced when Godot exports, modifying them here has no effect. -->
         <!-- Do these changes in the export preset. Adding new ones is fine. -->
 

+ 2 - 0
platform/android/java/app/build.gradle

@@ -97,6 +97,8 @@ android {
             abiFilters export_abi_list
         }
 
+        manifestPlaceholders = [godotEditorVersion: getGodotEditorVersion()]
+
         // Feel free to modify the application id to your own.
         applicationId getExportPackageName()
         versionCode getExportVersionCode()

+ 49 - 0
platform/android/java/app/config.gradle

@@ -50,6 +50,55 @@ ext.getExportVersionName = { ->
     return versionName
 }
 
+ext.getGodotEditorVersion = { ->
+    String editorVersion = project.hasProperty("godot_editor_version") ? project.property("godot_editor_version") : ""
+    if (editorVersion == null || editorVersion.isEmpty()) {
+        // Try the library version first
+        editorVersion = getGodotLibraryVersion()
+
+        if (editorVersion.isEmpty()) {
+            // Fallback value.
+            editorVersion = "custom_build"
+        }
+    }
+    return editorVersion
+}
+
+ext.getGodotLibraryVersion = { ->
+    // Attempt to read the version from the `version.py` file.
+    String libraryVersion = ""
+
+    File versionFile = new File("../../../version.py")
+    if (versionFile.isFile()) {
+        List<String> requiredKeys = ["major", "minor", "patch", "status", "module_config"]
+        def map = [:]
+
+        List<String> lines = versionFile.readLines()
+        for (String line in lines) {
+            String[] keyValue = line.split("=")
+            String key = keyValue[0].trim()
+            String value = keyValue[1].trim().replaceAll("\"", "")
+
+            if (requiredKeys.contains(key)) {
+                if (!value.isEmpty()) {
+                    map[key] = value
+                }
+                requiredKeys.remove(key)
+            }
+        }
+
+        if (requiredKeys.empty) {
+            libraryVersion = map.values().join(".")
+        }
+    }
+
+    if (libraryVersion.isEmpty()) {
+        // Fallback value in case we're unable to read the file.
+        libraryVersion = "custom_build"
+    }
+    return libraryVersion
+}
+
 final String PLUGIN_VALUE_SEPARATOR_REGEX = "\\|"
 
 // get the list of ABIs the project should be exported to

+ 0 - 6
platform/android/java/build.gradle

@@ -165,12 +165,6 @@ task cleanGodotTemplates(type: Delete) {
     // Delete the library generated AAR files
     delete("lib/build/outputs/aar")
 
-    // Delete the godotpayment libs directory contents
-    delete("plugins/godotpayment/libs")
-
-    // Delete the generated godotpayment aar
-    delete("plugins/godotpayment/build/outputs/aar")
-
     // Delete the app libs directory contents
     delete("app/libs")
 

+ 5 - 0
platform/android/java/lib/AndroidManifest.xml

@@ -7,6 +7,11 @@
     <!-- TODO: Remove the 'requestLegacyExternalStorage' attribute when https://github.com/godotengine/godot/issues/38913 is resolved -->
     <application android:requestLegacyExternalStorage="true">
 
+        <!-- Records the version of the Godot library -->
+        <meta-data
+            android:name="org.godotengine.library.version"
+            android:value="${godotLibraryVersion}" />
+
         <service android:name=".GodotDownloaderService" />
 
     </application>

+ 2 - 0
platform/android/java/lib/build.gradle

@@ -18,6 +18,8 @@ android {
     defaultConfig {
         minSdkVersion versions.minSdk
         targetSdkVersion versions.targetSdk
+
+        manifestPlaceholders = [godotLibraryVersion: getGodotLibraryVersion()]
     }
 
     compileOptions {