-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Building an Android Library #1957
Comments
I managed to build an AAR containing a python service by using a custom bootstrap (based on Similar issue: #1055 |
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. |
@xuhcc I am having the same issue. How can i build this? Do you have a repo? |
@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,openssl |
@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. |
In my case it worked like this: service.py import os
from jnius import autoclass
def send_broadcast(data):
Intent = autoclass('android.content.Intent')
intent = Intent('test')
intent.putExtra('result', data)
PythonService = autoclass('org.kivy.android.PythonService')
pyService = PythonService.mService
pyService.sendBroadcast(intent)
# Parse the input data at start
arg = os.environ['PYTHON_SERVICE_ARGUMENT']
# Do something with it...
# And then return result using broadcast
send_broadcast(result) And on the app side (my app was written in JavaScript): // Start service and provide input data
function startExampleService(arg) {
const context = getApplicationContext();
ExampleService.prepare(context);
ExampleService.start(context, arg);
}
// Receive the result asynchronously
function registerReceiver() {
application.registerBroadcastReceiver('test', (context, intent) => {
const extras = intent.getExtras();
const result = new java.lang.String(extras.getCharArray('result'));
});
} |
@xuhcc , thanks, very close to finish. Last quick question, do i need a "main.py" as well or is "service.py" enough? |
Yes, you only need the |
I tried to build .aar file using this but I am getting following error Please help me solve this issue. I install p4a from your forked repo itself. |
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.
The text was updated successfully, but these errors were encountered: