[Android] LibVlcUtil: fix library path search
Thomas Guillem
git at videolan.org
Thu Oct 23 10:21:04 CEST 2014
vlc-ports/android | branch: master | Thomas Guillem <tom at gllm.fr> | Wed Oct 22 15:34:13 2014 +0200| [0e6d442b4434746a75a8ec5cec68e2c898fcfe07] | committer: Thomas Guillem
LibVlcUtil: fix library path search
After android-21, libs are not necessarily in applicationInfo.dataDir + "/lib"
folder, so use applicationInfo.nativeLibraryDir (added after Gingerbread).
Also fix system library path search by using
System.getProperty("java.library.path") that return "/vendor/lib:/system/lib"
or "/vendor/lib64:/system/lib64".
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=0e6d442b4434746a75a8ec5cec68e2c898fcfe07
---
.../src/org/videolan/libvlc/LibVlcUtil.java | 49 +++++++++++++++-----
1 file changed, 37 insertions(+), 12 deletions(-)
diff --git a/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java b/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java
index a4bed55..739c06a 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java
@@ -100,13 +100,11 @@ public class LibVlcUtil {
// If already checked return cached result
if(errorMsg != null || isCompatible) return isCompatible;
- ApplicationInfo applicationInfo = context.getApplicationInfo();
- String libBasePath;
- if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)
- libBasePath = "/system";
- else
- libBasePath = applicationInfo.dataDir;
- ElfData elf = readLib(libBasePath + "/lib/libvlcjni.so");
+ final File lib = searchLibrary(context);
+ if (lib == null)
+ return true;
+
+ ElfData elf = readLib(lib);
if(elf == null) {
Log.e(TAG, "WARNING: Unable to read libvlcjni.so; cannot check device ABI!");
Log.e(TAG, "WARNING: Cannot guarantee correct ABI for this build (may crash)!");
@@ -320,17 +318,44 @@ public class LibVlcUtil {
boolean att_fpu;
}
+ private static File searchLibrary(Context context) {
+ // Search for library path
+ String [] libraryPaths = null;
+ final ApplicationInfo applicationInfo = context.getApplicationInfo();
+
+ if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
+ final String property = System.getProperty("java.library.path");
+ libraryPaths = property.split(":");
+ } else {
+ libraryPaths = new String[1];
+ if (isGingerbreadOrLater())
+ libraryPaths[0] = applicationInfo.nativeLibraryDir;
+ else
+ libraryPaths[0] = applicationInfo.dataDir + "/lib";
+ }
+ if (libraryPaths == null) {
+ Log.e(TAG, "can't find library path");
+ return null;
+ }
+
+ // Search for libvlcjni.so
+ File lib = null;
+ for (String libraryPath : libraryPaths) {
+ lib = new File(libraryPath, "libvlcjni.so");
+ if (lib.exists() && lib.canRead())
+ return lib;;
+ }
+ Log.e(TAG, "WARNING: Can't find shared library");
+ return null;
+ }
+
/** '*' prefix means it's unsupported */
private static String[] CPU_archs = {"*Pre-v4", "*v4", "*v4T",
"v5T", "v5TE", "v5TEJ",
"v6", "v6KZ", "v6T2", "v6K", "v7",
"*v6-M", "*v6S-M", "*v7E-M", "*v8"};
- private static ElfData readLib(String path) {
- File file = new File(path);
- if (!file.exists() || !file.canRead())
- return null;
-
+ private static ElfData readLib(File file) {
RandomAccessFile in = null;
try {
in = new RandomAccessFile(file, "r");
More information about the Android
mailing list