3
3
import java .io .File ;
4
4
5
5
import android .util .Log ;
6
-
6
+ import java .util .ArrayList ;
7
+ import java .io .FilenameFilter ;
7
8
8
9
public 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 );
22
34
};
35
+
36
+ MyList .add ("python2.7" );
37
+ MyList .add ("python3.5m" );
38
+ MyList .add ("main" );
39
+ return MyList ;
23
40
}
24
41
25
- public static void loadLibraries (File filesDir ) {
42
+ public static void loadLibraries (File filesDir ) {
26
43
27
44
String filesDirPath = filesDir .getAbsolutePath ();
28
45
boolean skippedPython = false ;
29
46
30
- for (String lib : getLibraries ()) {
31
- try {
47
+ for (String lib : getLibraries (filesDir )) {
48
+ try {
32
49
System .loadLibrary (lib );
33
50
} catch (UnsatisfiedLinkError e ) {
34
51
if (lib .startsWith ("python" ) && !skippedPython ) {
@@ -54,5 +71,6 @@ public static void loadLibraries(File filesDir) {
54
71
}
55
72
56
73
Log .v (TAG , "Loaded everything!" );
57
- }
74
+ }
58
75
}
76
+
0 commit comments