0

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
Master
  • 13
  • 3
  • 1st of all, check: [\[SO\]: Python Ctypes - loading dll throws OSError: \[WinError 193\] %1 is not a valid Win32 application (@CristiFati's answer)](https://stackoverflow.com/a/57297745/4788546) for that error. 2nd: **an *Android* library can't be loaded in *Win***. So this is a duplicate of [\[SO\]: Install win32com on MacOs and Linux (@CristiFati's answer)](https://stackoverflow.com/a/65030870/4788546). – CristiFati Jan 24 '23 at 20:02

1 Answers1

-1

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

  • same error, also i tried different architectures none works – Master Jan 24 '23 at 16:01
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 25 '23 at 21:57
  • This is completely incorrect, as it points out to loading an **extension module**, while the question is loading a "regular" *.so*. – CristiFati Jan 27 '23 at 11:28