Skip to content

Commit

Permalink
try to diagnose link failed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 19, 2024
1 parent a62c3e1 commit 7554a48
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
10 changes: 2 additions & 8 deletions app/src/main/java/com/geode/launcher/GeometryDashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 45 additions & 0 deletions app/src/main/java/com/geode/launcher/utils/LaunchUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<!-- GeometryDashActivity strings -->
<string name="load_failed_link_error">Failed to link libraries</string>
<string name="load_failed_link_error_description">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!</string>
<string name="load_failed_link_error_description">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.</string>
<string name="load_failed_generic_error">Load failed</string>
<string name="load_failed_generic_error_description">Uncaught error during game load: `%1$s`.\nCheck application logs for more details. Please report this issue!</string>
<string name="message_box_cancel">Cancel</string>
Expand Down

0 comments on commit 7554a48

Please sign in to comment.