python-for-android icon indicating copy to clipboard operation
python-for-android copied to clipboard

Proposal: Android-Specific Metadata Support in Recipes

Open Novfensec opened this issue 7 months ago • 3 comments

Introduce support in python-for-android to parse Android-specific metadata from pyproject.toml of pip-installed packages. This enables modular bundling of assets into APK builds, allowing packages to contribute platform-native components directly.

Example pyproject.toml Layout

[tool.python-for-android.android]
src = "android/src/"
res = "android/res/"
extra_manifest_xml = "android/extra_manifest.xml"
extra_manifest_application_xml= "android/extra_manifest_application.xml"
activities = [
    {
        "name": "org.package.android.MyActivity",
        "process": ":package_process",
    }
]
proguard = "android/proguard-rules.txt"
jniLibs = "android/jni/"
assets = "android/assets/"
resources = "android/resources"

etc. Etc.

How It Works

  • During dependency resolution (p4a.recipe or pip stage), check for [tool.python-for-android.android] in pyproject.toml.
  • Resolve declared paths from the site-packages directory.
  • Inject collected files into dists/<your_app>/build/ before Gradle build.

Please consider this.

THANKS!!

Novfensec avatar Jul 23 '25 05:07 Novfensec

@kuzeyron I want to take on this, but I don't know if the approach I have in mind is okay. Here's what I'm thinking: directly under this code: https://github.com/kivy/python-for-android/blob/359975b1aad7a03fba24400376eb02a16764d703/pythonforandroid/build.py#L528-L531 p4A can loop through all installed python packages looking for a android.toml or in the root folder of each package or in root/android. When found it loads toml file and extracts the java src file only and copy it to ctx.javaclass_dir.

The reason I said java src file only is because modifying xml or adding resources can conflict with what the user want's to modify themselves.

kengoon avatar Dec 06 '25 20:12 kengoon

Something even better, --requirements args can be modified to accept extra arguments. e.g

android.requirements = python,kivy,mypackage:android,otherpackage-with-version==1.2:java

where android and java are the directory inside the packages containing the java files in a java compliant package directory. then we can extract them and put in environ just like the way the versions are stored in environ also. and then copy them to ctx.javaclass_dir.

@kuzeyron what do you think?

kengoon avatar Dec 06 '25 22:12 kengoon

Sure, why not? Make sure to write a proper documentation of this if you proceed with this task.

kuzeyron avatar Dec 07 '25 08:12 kuzeyron