Skip to content

Commit

Permalink
Use extracted libraries when they're available (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
konraddysput authored Jun 16, 2024
1 parent 54f2aed commit 08d5d69
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class CrashHandlerConfiguration {
public static final Set<String> UNSUPPORTED_ABIS = new HashSet<String>(Arrays.asList(new String[]{"x86"}));
private static final String CRASHPAD_DIRECTORY_PATH = "/crashpad";

private static final String BACKTRACE_NATIVE_LIBRARY_NAME = "libbacktrace-native.so";


public Boolean isSupportedAbi() {
return isSupportedAbi(AbiHelper.getCurrentAbi());
Expand Down Expand Up @@ -48,6 +50,7 @@ public List<String> getCrashHandlerEnvironmentVariables(String apkPath, String n
// extend system-specific environment variables, with variables needed to properly run app_process via crashpad
File nativeLibraryDirectory = new File(nativeLibraryDirPath);

String backtraceNativeLibraryPath = getBacktraceNativeLibraryPath(nativeLibraryDirPath, apkPath, arch);
File allNativeLibrariesDirectory = nativeLibraryDirectory.getParentFile();
String allPossibleLibrarySearchPaths = TextUtils.join(File.pathSeparator, new String[]{
nativeLibraryDirPath,
Expand All @@ -56,7 +59,7 @@ public List<String> getCrashHandlerEnvironmentVariables(String apkPath, String n
"/data/local"});

environmentVariables.add(String.format("CLASSPATH=%s", apkPath));
environmentVariables.add(String.format("%s=%s!/lib/%s/libbacktrace-native.so", BACKTRACE_CRASH_HANDLER, apkPath, arch));
environmentVariables.add(String.format("%s=%s", BACKTRACE_CRASH_HANDLER, backtraceNativeLibraryPath));
environmentVariables.add(String.format("LD_LIBRARY_PATH=%s", allPossibleLibrarySearchPaths));
environmentVariables.add("ANDROID_DATA=/data");

Expand All @@ -72,4 +75,15 @@ public String useCrashpadDirectory(String databaseDirectory) {
}
return databasePath;
}

private String getBacktraceNativeLibraryPath(String nativeLibraryDirPath, String apkPath, String arch) {
String backtraceNativeLibraryPath = String.format("%s/%s", nativeLibraryDirPath, BACKTRACE_NATIVE_LIBRARY_NAME);
File backtraceNativeLibrary = new File(backtraceNativeLibraryPath);

// If ndk libraries are already extracted, we shouldn't use libraries from the apk.
// Otherwise. We need to find a path in the apk to use compressed libraries from there.
return backtraceNativeLibrary.exists()
? backtraceNativeLibraryPath
: String.format("%s!/lib/%s/%s", apkPath, arch, BACKTRACE_NATIVE_LIBRARY_NAME);
}
}

0 comments on commit 08d5d69

Please sign in to comment.