Skip to content
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

use build aar in kotlin app ,can't load /lib/arm64/libpybundle.so file #2940

Closed
vjeson opened this issue Dec 14, 2023 · 4 comments
Closed

use build aar in kotlin app ,can't load /lib/arm64/libpybundle.so file #2940

vjeson opened this issue Dec 14, 2023 · 4 comments
Labels

Comments

@vjeson
Copy link

vjeson commented Dec 14, 2023

Versions

  • Python: 3.10.12
  • OS:
  • Kivy:
  • Cython:
  • OpenJDK:
  • python-for-android 2023.9.16

Description

generate aar with p4a, use the aar in the Kotlin app, and I can confirm the build apk contains the so file

image

can in kt like this

    override fun onStart() {
        super.onStart()
        val context=super.getContext()
        ServiceP4a_test_service.prepare(context)
        ServiceP4a_test_service.start(context,"aa")

    }

and I found aar extrac the so like this

public static void prepare(Context ctx) {
    String appRoot = PythonUtil.getAppRoot(ctx);
    Log.v("PythonService", "Ready to unpack");
    File app_root_file = new File(appRoot);
    PythonUtil.unpackAsset(ctx, "private", app_root_file, true);
    PythonUtil.unpackPyBundle(ctx, ctx.getApplicationInfo().nativeLibraryDir + "/libpybundle", app_root_file, false);
}

buildozer.spec

Command:

p4a aar --private /pytest/p4a-library  --package=comd.devgg.p4a_aartest --name "p4alibrary" --version 0.1 --android-api 31 --bootstrap service_library --requirements python3 --service=echo:service.py --arch=arm64-v8a 

Logs

V/pythonutil: Unpacking /data/app/~~vqTf2YNP6WZ6OwaMQTcqEA==/com.devgg.call_aar_test2-_AkXT_nq1pzrbvNKk5m0Zw==/lib/arm64/libpybundle app
V/pythonutil: Data version is a9469a597a257b56f0553f0a5d5b88f55a98ef9e
V/pythonutil: Extracting /data/app/~~vqTf2YNP6WZ6OwaMQTcqEA==/com.devgg.call_aar_test2-_AkXT_nq1pzrbvNKk5m0Zw==/lib/arm64/libpybundle assets.
I/.call_aar_test2: This is non sticky GC, maxfree is 33554432 minfree is 8388608
I/.call_aar_test2: WaitForGcToComplete blocked ObjectsAllocated on Background for 15.741ms
E/python: opening up extract tar
    java.io.FileNotFoundException: /data/app/~~vqTf2YNP6WZ6OwaMQTcqEA==/com.devgg.call_aar_test2-_AkXT_nq1pzrbvNKk5m0Zw==/lib/arm64/libpybundle.so: open failed: ENOENT (No such file or directory)
Copy link

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.

If you're having trouble installing or using python-for-android, maybe you could be interested in our quickstart guide.

Let us know if this comment was made in error, and we'll be happy to reopen the issue.

@vjeson
Copy link
Author

vjeson commented Dec 14, 2023

This is obviously a bug, everything is ok ,but can't load so file

@pach318
Copy link

pach318 commented Dec 20, 2023

Check if the "extractNativeLibs" option is enabled in your app's "AndroidManifest.xml":

    <application
        ...
        android:extractNativeLibs="true"
        ...>

I got the same "no such file" error if this is not enabled (the native libs directory would be empty). After enabling it in the app, the python bundle is loaded successfully.

@vjeson
Copy link
Author

vjeson commented Dec 21, 2023

Check if the "extractNativeLibs" option is enabled in your app's "AndroidManifest.xml":

    <application
        ...
        android:extractNativeLibs="true"
        ...>

I got the same "no such file" error if this is not enabled (the native libs directory would be empty). After enabling it in the app, the python bundle is loaded successfully.

Thx, it's resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants