kivy / python-for-android

Turn your Python application into an Android APK
https://python-for-android.readthedocs.io
MIT License
8.33k stars 1.84k forks source link

Enhancement Request - Custom Java #1563

Open RobertFlatt opened 5 years ago

RobertFlatt commented 5 years ago

Versions

Description

Add a p4a command line option to specify a folder containing custom java classes.

During build the folder and contents would be copied to the javaclasses folder, for example:

cp -r <option argument> .local/share/python-for-android/build/javaclasses/<project>/ Example usage: --fantastic_new_custom_java_option=~/greatproject/com

Where custom java located here: ~/greatproject/com/company/project/custom.java

Something similar is supposed to exist in buildozer, implementation issues suggest a need for redundancy.

buildozer.spec

Command:

Spec file:

Logs

// REPLACE ME: Paste the build ouput containing the error
ghost commented 5 years ago

There is an --add-jar option internally in the build.py bootstrap script. I think you might be able to just specify it for p4a (which if I recall correctly passes unknown options through to the bootstrap build script) and that would copy your specified .jar files into the libs folder. That may already be enough to get that to work, but you'll have to give it a try and see if that actually does the job especially regarding them actually being loaded at runtime when added like that, I'm just guessing from vague source code memories here

RobertFlatt commented 5 years ago

The option is there in toolchain.py , but gradle fails

[INFO]:    Selecting java build tool:
[INFO]:    Detected highest available build tools version to be 28.0.3
[INFO]:        Building with gradle, as gradle executable is present
[DEBUG]:   -> running gradlew assembleDebug
[DEBUG]:
[DEBUG]:        > Configure project :
[DEBUG]:        WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
[DEBUG]:        It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
[DEBUG]:
[DEBUG]:
[DEBUG]:        FAILURE: Build failed with an exception.
[DEBUG]:
[DEBUG]:        * What went wrong:
[DEBUG]:        Could not resolve all files for configuration ':debugCompileClasspath'.
[DEBUG]:        > Failed to transform file 'jartest.jar' to match attributes {artifactType=android-classes} using transform JarTransform
[DEBUG]:           > Transform output file /home/bobf/.local/share/python-for-android/dists/ex/src/main/libs/jartest.jar does not exist.
[DEBUG]:
[DEBUG]:        * Try:
[DEBUG]:        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[DEBUG]:
[DEBUG]:        * Get more help at https://help.gradle.org
[DEBUG]:
[DEBUG]:        BUILD FAILED in 6s
[DEBUG]:        14 actionable tasks: 3 executed, 11 up-to-date
[DEBUG]:
[DEBUG]:

Jar file build, using the jnius example file, and changing the first line to "package com.fishes;"

jar cvf jartest.jar com
added manifest
adding: com/(in = 0) (out= 0)(stored 0%)
adding: com/fishes/(in = 0) (out= 0)(stored 0%)
adding: com/fishes/Hardware.java(in = 1370) (out= 509)(deflated 62%)
inclement commented 5 years ago

Noted by @OptimusGREEN that /.buildozer/android/platform/build/dists//src/main/libs/ was the correct location for libs to be copied.

AndreMiras commented 5 years ago

Can you tell if this is fixed via https://github.com/kivy/python-for-android/pull/1693 ? Edit: Yes I could reproduce the gradle Failed to transform file issue