33import java .io .File ;
44
55import android .util .Log ;
6-
6+ import java .util .ArrayList ;
7+ import java .io .FilenameFilter ;
78
89public class PythonUtil {
9- private static final String TAG = "PythonUtil" ;
10-
11- protected static String [] getLibraries () {
12- return new String [] {
13- "SDL2" ,
14- "SDL2_image" ,
15- "SDL2_mixer" ,
16- "SDL2_ttf" ,
17- "crypto1.0.2h" ,
18- "ssl1.0.2h" ,
19- "python2.7" ,
20- "python3.5m" ,
21- "main"
10+ private static final String TAG = "PythonUtil" ;
11+
12+ protected static ArrayList <String > getLibraries (File filesDir ) {
13+
14+ ArrayList <String > MyList = new ArrayList <String >();
15+ MyList .add ("SDL2" );
16+ MyList .add ("SDL2_image" );
17+ MyList .add ("SDL2_mixer" );
18+ MyList .add ("SDL2_ttf" );
19+
20+ String absPath = filesDir .getParentFile ().getParentFile ().getAbsolutePath () + "/lib/" ;
21+ filesDir = new File (absPath );
22+ File [] files = filesDir .listFiles (new FilenameFilter () {
23+ @ Override
24+ public boolean accept (File dir , String name ) {
25+ return name .matches (".*ssl.*" ) || name .matches (".*crypto.*" );
26+ }
27+ });
28+
29+ for (int i = 0 ; i < files .length ; ++i ) {
30+ File mfl = files [i ];
31+ String name = mfl .getName ();
32+ name = name .substring (3 , name .length () - 3 );
33+ MyList .add (name );
2234 };
35+
36+ MyList .add ("python2.7" );
37+ MyList .add ("python3.5m" );
38+ MyList .add ("main" );
39+ return MyList ;
2340 }
2441
25- public static void loadLibraries (File filesDir ) {
42+ public static void loadLibraries (File filesDir ) {
2643
2744 String filesDirPath = filesDir .getAbsolutePath ();
2845 boolean skippedPython = false ;
2946
30- for (String lib : getLibraries ()) {
31- try {
47+ for (String lib : getLibraries (filesDir )) {
48+ try {
3249 System .loadLibrary (lib );
3350 } catch (UnsatisfiedLinkError e ) {
3451 if (lib .startsWith ("python" ) && !skippedPython ) {
@@ -54,5 +71,6 @@ public static void loadLibraries(File filesDir) {
5471 }
5572
5673 Log .v (TAG , "Loaded everything!" );
57- }
74+ }
5875}
76+
0 commit comments