ninia / jep

Embed Python in Java
Other
1.31k stars 149 forks source link

jep in android #479

Open huazai023 opened 1 year ago

huazai023 commented 1 year ago

When I use android ndk to compile jep, it prompts that libjvm.so cannot be found, what library to use in Android to replace libjvm.so

huazai023 commented 1 year ago

I have enabled Jep to run on Android. Can I propose a pull request

bsteffensmeier commented 1 year ago

Can I propose a pull request

That would be fantastic.

huazai023 commented 1 year ago

Here's how to get jep running on Android:

  1. Modify the jep setup.py file. The content of the modified patch file is as follows:
    
    --- a/setup.py  2023-06-28 03:18:14.651024222 +0000
    +++ b/setup.py  2023-06-28 03:18:04.786364976 +0000
    @@ -73,7 +73,7 @@
         defines.append(('WIN32', 1))
         #Disable warnings about Secure CRT Functions in util.c and pyembed.c.
         defines.append(('_CRT_SECURE_NO_WARNINGS', 1))
    -
    +    platform = os.environ.get('PLATFORM')
     setup(name='jep',
           version=VERSION,
           description='Jep embeds CPython in Java',
    @@ -107,10 +107,10 @@
                   name='jep',
                   sources=get_files('.c'),
                   define_macros=defines,
    -                  libraries=get_java_libraries() + get_python_libs(),
    -                  library_dirs=get_java_lib_folders(),
    -                  extra_link_args=get_java_linker_args() + get_python_linker_args(),
    -                  include_dirs=get_java_include() + ['src/main/c/Include', 'build/include',] + numpy_include,
    +                  libraries=(['nativehelper'] if platform.startswith("android") else get_java_libraries()) + get_python_libs(),
    +                  library_dirs=[] if platform.startswith("android") else get_java_lib_folders(),
    +                  extra_link_args= ([] if platform.startswith("android") else get_java_linker_args()) + get_python_linker_args(),
    +                  include_dirs= ([] if platform.startswith("android") else get_java_include()) + ['src/main/c/Include', 'build/include'] + numpy_include,
               )
           ],

@@ -141,4 +141,3 @@ }, zip_safe=False )


2. When using android-ndk to install jep, you need to use python's crossenv to install it
huazai023 commented 1 year ago

This method needs to set a running target environment parameter: PLATFORM