I need to use the.so library developed for android (jni) but i need to use it in python
Code for android:
package x2;
import android.os.Build;
import java.util.Base64;
public class X {
static {
System.loadLibrary("adlemx");
}
public static String m0do(String str) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return Base64.getEncoder().encodeToString(x01(str).getBytes());
}
return "";
}
public static native String x01(String str);
}
I tried use ctypes
from ctypes import cdll
print(cdll.LoadLibrary("./adlemx.so"))
but I get error:
Traceback (most recent call last):
File "D:\_Projects\DiaryBackend\main.py", line 24, in <module>
print(cdll.LoadLibrary("./adlemx.so"))
File "C:\Program Files\Python39\lib\ctypes\__init__.py", line 452, in LoadLibrary
return self._dlltype(name)
File "C:\Program Files\Python39\lib\ctypes\__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not an application Win32
try create file with name of library "adlemx.py" and paste this code
def __bootstrap__():
global __bootstrap__, __loader__, __file__
import sys, pkg_resources, imp
__file__ = pkg_resources.resource_filename(__name__,'adlemx.so')
__loader__ = None; del __bootstrap__, __loader__
imp.load_dynamic(__name__,__file__)
__bootstrap__()
then import this file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.