Skip to content

Commit

Permalink
patch from kivy#866
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Patruno committed Feb 20, 2017
1 parent 942ad52 commit 85bade2
Showing 1 changed file with 36 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,49 @@
import java.io.File;

import android.util.Log;

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

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",
"main"
private static final String TAG = "PythonUtil";

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

ArrayList<String> MyList = new ArrayList<String>();
MyList.add("SDL2");
MyList.add("SDL2_image");
MyList.add("SDL2_mixer");
MyList.add("SDL2_ttf");

String absPath = filesDir.getParentFile().getParentFile().getAbsolutePath() + "/lib/";
filesDir = new File(absPath);
File [] files = filesDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.matches(".*ssl.*") || name.matches(".*crypto.*");
}
});

for (int i = 0; i < files.length; ++i) {
File mfl = files[i];
String name = mfl.getName();
name = name.substring(3, name.length() - 3);
MyList.add(name);
};

MyList.add("python2.7");
MyList.add("python3.5m");
MyList.add("main");
return MyList;
}

public static void loadLibraries(File filesDir) {
public static void loadLibraries(File filesDir) {

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

for (String lib : getLibraries()) {
try {
for (String lib : getLibraries(filesDir)) {
try {
System.loadLibrary(lib);
} catch(UnsatisfiedLinkError e) {
if (lib.startsWith("python") && !skippedPython) {
Expand All @@ -52,5 +71,6 @@ public static void loadLibraries(File filesDir) {
}

Log.v(TAG, "Loaded everything!");
}
}
}

0 comments on commit 85bade2

Please sign in to comment.