You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to build an Android Library (AAR) with Python-For-Android?
There is a python package which I want to use as a library in existing Android application. I tried to integrate it in Kivy demo app and it is working. However I can't find a way to produce AAR instead of APK.
I managed to build an AAR containing a python service by using a custom bootstrap (based on service_only bootstrap). Maybe I'll publish my code later if it will work.
@gklasen You can use my fork of p4a, and there's also an open PR #1963. I didn't finished my work on it due to a shift of priorities in my project, but I think it is almost complete and ready to use.
I don't have a repo for my build environment, but here's the command that I used to build my library:
@xuhcc Thank you very much for your work on this! I managed to compile an .AAR-File, the only thing left is how can i refer functionality from it within Javacode. Is there an example, or a small hint?
importosfromjniusimportautoclassdefsend_broadcast(data):
Intent=autoclass('android.content.Intent')
intent=Intent('test')
intent.putExtra('result', data)
PythonService=autoclass('org.kivy.android.PythonService')
pyService=PythonService.mServicepyService.sendBroadcast(intent)
# Parse the input data at startarg=os.environ['PYTHON_SERVICE_ARGUMENT']
# Do something with it...# And then return result using broadcastsend_broadcast(result)
And on the app side (my app was written in JavaScript):
// Start service and provide input datafunctionstartExampleService(arg){constcontext=getApplicationContext();ExampleService.prepare(context);ExampleService.start(context,arg);}// Receive the result asynchronouslyfunctionregisterReceiver(){application.registerBroadcastReceiver('test',(context,intent)=>{constextras=intent.getExtras();constresult=newjava.lang.String(extras.getCharArray('result'));});}
@gklasen You can use my fork of p4a, and there's also an open PR #1963. I didn't finished my work on it due to a shift of priorities in my project, but I think it is almost complete and ready to use.
I don't have a repo for my build environment, but here's the command that I used to build my library:
Activity
xuhcc commentedon Aug 17, 2019
I managed to build an AAR containing a python service by using a custom bootstrap (based on
service_onlybootstrap). Maybe I'll publish my code later if it will work.Similar issue: #1055
inclement commentedon Aug 18, 2019
No, this isn't currently supported. As you've found, it should be fairly straightforward though, and it's something I've been meaning to look into.
gklasen commentedon Feb 17, 2020
@xuhcc I am having the same issue. How can i build this? Do you have a repo?
xuhcc commentedon Feb 17, 2020
@gklasen You can use my fork of p4a, and there's also an open PR #1963. I didn't finished my work on it due to a shift of priorities in my project, but I think it is almost complete and ready to use.
I don't have a repo for my build environment, but here's the command that I used to build my library:
python3 -m pythonforandroid.toolchain apk \ --debug \ --bootstrap=library \ --local-recipes=recipes \ --requirements=python3,pyjnius,mypackage \ --dist_name mypackage \ --name "mypackage" \ --version 0.1 \ --package mypackage \ --android_api 28 \ --minsdk 21 \ --ndk-api 21 \ --private .buildozer/android/app \ --service mypackage:service.py \ --copy-libs \ --arch x86 \ --color=always \ --storage-dir="/vagrant/.buildozer/android/platform/build" \ --ndk-api=21 \ --ndk-dir="/home/vagrant/.buildozer/android/platform/android-ndk-r17c/" \ --sdk-dir="/home/vagrant/.buildozer/android/platform/android-sdk/" \ --blacklist-requirements=sqlite3,libffi,android,opensslgklasen commentedon Feb 21, 2020
@xuhcc Thank you very much for your work on this! I managed to compile an .AAR-File, the only thing left is how can i refer functionality from it within Javacode. Is there an example, or a small hint?
Thank again, you already helped a lot.
xuhcc commentedon Feb 21, 2020
In my case it worked like this:
service.py
And on the app side (my app was written in JavaScript):
gklasen commentedon Feb 26, 2020
@xuhcc , thanks, very close to finish. Last quick question, do i need a "main.py" as well or is "service.py" enough?
xuhcc commentedon Feb 26, 2020
Yes, you only need the
service.pyfileabhay6694 commentedon May 18, 2021
I tried to build .aar file using this but I am getting following error
[ERROR]: unsupported bootstrap for android recipe: library
Please help me solve this issue. I install p4a from your forked repo itself.