diff --git a/app/src/main/java/com/geode/launcher/GeometryDashActivity.kt b/app/src/main/java/com/geode/launcher/GeometryDashActivity.kt index 83d11a52..311b8688 100644 --- a/app/src/main/java/com/geode/launcher/GeometryDashActivity.kt +++ b/app/src/main/java/com/geode/launcher/GeometryDashActivity.kt @@ -61,17 +61,11 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL // generates helpful information for use in debugging library load failures val gdPackageInfo = packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0) - - val abi = LaunchUtils.applicationArchitecture - val isExtracted = gdPackageInfo.applicationInfo.flags and ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS == ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS - val isSplit = (gdPackageInfo.applicationInfo.splitSourceDirs?.size ?: 0) > 1 - - val metadata = "Geometry Dash metadata:\nSplit sources: $isSplit\nExtracted libraries: $isExtracted\nLauncher architecture: $abi" - Log.i("GeodeLauncher", metadata) + val failureReason = LaunchUtils.diagnoseLoadErrors(this, gdPackageInfo) returnToMain( getString(R.string.load_failed_link_error), - getString(R.string.load_failed_link_error_description) + getString(R.string.load_failed_link_error_description, failureReason.name) ) return diff --git a/app/src/main/java/com/geode/launcher/utils/LaunchUtils.kt b/app/src/main/java/com/geode/launcher/utils/LaunchUtils.kt index 6b9afde0..f4d68ee8 100644 --- a/app/src/main/java/com/geode/launcher/utils/LaunchUtils.kt +++ b/app/src/main/java/com/geode/launcher/utils/LaunchUtils.kt @@ -5,10 +5,16 @@ import android.content.pm.PackageInfo import android.content.pm.PackageManager import android.content.res.AssetManager import android.content.Context +import android.content.pm.ApplicationInfo import android.os.Build +import android.util.Log import java.io.File object LaunchUtils { + enum class FailureReason { + NOT_FOUND, ABI_MISMATCH, UNKNOWN + } + fun isGeometryDashInstalled(packageManager: PackageManager): Boolean { return try { packageManager.getPackageInfo(Constants.PACKAGE_NAME, 0) @@ -34,6 +40,45 @@ object LaunchUtils { return game.versionName } + fun diagnoseLoadErrors(context: Context, packageInfo: PackageInfo): FailureReason { + val abi = applicationArchitecture + val isExtracted = + packageInfo.applicationInfo.flags and ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS == ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS + val isSplit = (packageInfo.applicationInfo.splitSourceDirs?.size ?: 0) > 1 + + val metadata = + "Geometry Dash metadata:\nSplit sources: $isSplit\nExtracted libraries: $isExtracted\nLauncher architecture: $abi" + Log.i("GeodeLauncher", metadata) + + // determine if it can find gd libraries for the opposite architecture + val gdBinaryName = "lib${Constants.COCOS_LIB_NAME}.so" + val oppositeArchitecture = if (abi == "arm64-v8a") "armeabi-v7a" else "arm64-v8a" + + if (packageInfo.applicationInfo.nativeLibraryDir.contains(oppositeArchitecture)) { + return FailureReason.ABI_MISMATCH + } + + if (!isExtracted) { + try { + context.assets.openNonAssetFd("lib/$oppositeArchitecture/$gdBinaryName") + return FailureReason.ABI_MISMATCH + } catch (_: Exception) { + // this is good, actually! + } + } + + // try fetching for its own libraries (only for uncompressed libraries) + if (!isExtracted) { + try { + context.assets.openNonAssetFd("lib/$abi/$gdBinaryName") + } catch (_: Exception) { + return FailureReason.NOT_FOUND + } + } + + return FailureReason.UNKNOWN + } + // supposedly CPU_ABI returns the current arch for the running application // despite being deprecated, this is also one of the few ways to get this information @Suppress("DEPRECATION") diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9dcec6c8..9b2044eb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -40,7 +40,7 @@ Failed to link libraries - Game libraries could not be found. This may occur if the architecture of the launcher and Geometry Dash do not match, or from a system bug.\nCheck application logs for more details. Please report this issue! + Game libraries could not be found. This may occur if the architecture of the launcher and Geometry Dash do not match, or from a system bug.\nReported issue: %1$s.\nCheck application logs for more details. Load failed Uncaught error during game load: `%1$s`.\nCheck application logs for more details. Please report this issue! Cancel