kivy / buildozer

Generic Python packager for Android and iOS
https://buildozer.readthedocs.io
MIT License
1.74k stars 499 forks source link

Build APK with both x86 and arm libs #1321

Closed pgp closed 2 years ago

pgp commented 3 years ago

Versions

Description

Is there any way to instruct buildozer to build an APK containing both x86 and arm libs?

I can successfully build two APKs in two different build commands, by respectively specifying x86 and armeabi-v7a as values for the android.arch key in the buildozer.spec file, however is there a way to build a fat apk, or at least to build the two apks for different archs, in a single buildozer invocation?

DarkionAvey commented 3 years ago

I don't know exactly how, but I am also interested in this. Technically, the *.so objects that are bundled in the private.mp3 file need to be moved into /lib directory since each arch will have to have its own corresponding libraries. It's also easier to do it using cmake, but I am not sure if p4a is willing to migrate from Mk to cmake

For those who are willing to implement this, this is my cmake file:

# python headers
include_directories("path\\to\\headers\\${ANDROID_ABI}__ndk_target_21\\python3\\Include")
# the start.c file (which is compiled as libmain.so using mk). It is compiled as libstart.so using cmake
add_library(
        start
        SHARED
        jni/application/src/start.c) 
# include and link pre-compiled *.so files (which also include the ones from assets/private.mp3)
include_directories(${PROJECT_SOURCE_DIR}/libs/${ANDROID_ABI})
link_directories(${PROJECT_SOURCE_DIR}/libs/${ANDROID_ABI})
# finally, link the start.c with libpythonXX.so
target_link_libraries(
        start
        ${log-lib}
        ${PROJECT_SOURCE_DIR}/libs/${ANDROID_ABI}/libpython3.8m.so
)

Edit: I forgot to mention that you have to set android:extractNativeLibs="true" in Android manifest, then supply context.applicationInfo.nativeLibraryDir to "PYTHONPATH" variable, like this (Kotlin):

 nativeSetEnv(
                "PYTHONPATH", kotlin.String.format(
                    "%s:%s:%s",
                    context.applicationInfo.nativeLibraryDir,
                    app_root_dir,
                    assets_dir
                  )
            )
evecimar commented 3 years ago

how to use this to solve the armeabi-v7a compilation problem?

DarkionAvey commented 3 years ago

how to use this to solve the armeabi-v7a compilation problem?

What exactly is the problem?

misl6 commented 2 years ago

🥳 Since python-for-android v2022.03.13 and buildozer https://github.com/kivy/buildozer/releases/tag/1.3.0 we now support multi-arch APK and AAB.

QGB commented 1 year ago

🥳 从python-for-android v2022.03.13buildozer https://github.com/kivy/buildozer/releases/tag/1.3.0开始,我们现在支持多架构 APK 和 AAB。

# Cwd /home/user/KivyJniusBluetoothApp/.buildozer/android/platform/python-for-android
[WARNING]: prerequisites.py is experimental and does not support all prerequisites yet.
[WARNING]: Please report any issues to the python-for-android issue tracker.
[WARNING]: prerequisites.py is experimental and does not support all prerequisites yet.
[WARNING]: Please report any issues to the python-for-android issue tracker.
[ERROR]:   Build failed: Asked to compile for no Archs, so failing.
['/home/user/KivyJniusBluetoothApp/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py', 'create', '--dist_name=myapp', '--bootstrap=sdl2', '--requirements=pyth
on3,kivy,dill,flask,requests,cchardet,psutil,wcwidth,xdis,uncompyle6,pandas,ipython', '--arch', 'armeabi-v7a,arm64-v8a', '--copy-libs', '--color=always', '--storage-dir=/home/user/KivyJ
niusBluetoothApp/.buildozer/android/platform/build-armeabi-v7a,arm64-v8a', '--ndk-api=21', '--ignore-setup-py'] ==================================================================
# Command failed: /usr/bin/python3 -m pythonforandroid.toolchain create --dist_name=myapp --bootstrap=sdl2 --requirements=python3,kivy,dill,flask,requests,cchardet,psutil,wcwidth,xdis,u
ncompyle6,pandas,ipython --arch armeabi-v7a,arm64-v8a --copy-libs --color=always --storage-dir="/home/user/KivyJniusBluetoothApp/.buildozer/android/platform/build-armeabi-v7a,arm64-v8a"
 --ndk-api=21 --ignore-setup-py