8000 Fixed ssl, sqlite and crystax library loads on Android versions before ~4.4 by inclement · Pull Request #1106 · kivy/python-for-android · GitHub
[go: up one dir, main page]

Skip to content

Fixed ssl, sqlite and crystax library loads on Android versions before ~4.4 #1106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,58 @@
import java.io.File;

import android.util.Log;

import java.util.ArrayList;
import java.io.FilenameFilter;
import java.util.regex.Pattern;

public class PythonUtil {
private static final String TAG = "pythonutil";

protected static String[] getLibraries() {
return new String[] {
"SDL2",
"SDL2_image",
"SDL2_mixer",
"SDL2_ttf",
"python2.7",
"python3.5m",
"python3.6m",
"main"
};
protected static void addLibraryIfExists(ArrayList<String> libsList, String pattern, File libsDir) {
// pattern should be the name of the lib file, without the
// preceding "lib" or suffix ".so", for instance "ssl.*" will
// match files of the form "libssl.*.so".
File [] files = libsDir.listFiles();

pattern = "lib" + pattern + "\\.so";
Pattern p = Pattern.compile(pattern);
for (int i = 0; i < files.length; ++i) {
File file = files[i];
String name = file.getName();
Log.v(TAG, "Checking pattern " + pattern + " against " + name);
if (p.matcher(name).matches()) {
Log.v(TAG, "Pattern " + pattern + " matched file " + name);
libsList.add(name.substring(3, name.length() - 3));
}
}
}

public static void loadLibraries(File filesDir) {
protected static ArrayList<String> getLibraries(File filesDir) {

String libsDirPath = filesDir.getParentFile().getParentFile().getAbsolutePath() + "/lib/";
File libsDir = new File(libsDirPath);

ArrayList<String> libsList = new ArrayList<String>();
addLibraryIfExists(libsList, "crystax", libsDir);
addLibraryIfExists(libsList, "sqlite3", libsDir);
libsList.add("SDL2");
libsList.add("SDL2_image");
libsList.add("SDL2_mixer");
libsList.add("SDL2_ttf");
addLibraryIfExists(libsList, "ssl.*", libsDir);
addLibraryIfExists(libsList, "crypto.*", libsDir);
libsList.add("python2.7");
libsList.add("python3.5m");
libsList.add("main");
return libsList;
}

public static void loadLibraries(File filesDir) {

String filesDirPath = filesDir.getAbsolutePath();
boolean foundPython = false;

for (String lib : getLibraries()) {
for (String lib : getLibraries(filesDir)) {
Log.v(TAG, "Loading library: " + lib);
try {
System.loadLibrary(lib);
Expand Down Expand Up @@ -66,3 +94,4 @@ public static void loadLibraries(File filesDir) {
Log.v(TAG, "Loaded everything!");
}
}

0