How to build python for using it with chaquopy in android app (jetbrains-studio)


I want to use python in an android app, but first I want to learn how to install Chaquopy. I already get stopped at the first steps.

I am using:
Chaquopy 17.0.0
Gradle 9.7.1 
android-37.1 (API 37.1 ("CinnamonBun"; Android 17.0))

The app builds and gives me a working screen on my phone when I write in build.gradle.kts:Project:

plugins {
    alias(libs.plugins.android.application) apply false
    id("com.chaquo.python") version "17.0.0" apply false
}

And when I add in build.gradle.kts:App:

plugins {
    alias(libs.plugins.android.application)
    id("com.chaquo.python")
}

I get (after syncing) the successful build as seen below:

> Task :prepareKotlinBuildScriptModel UP-TO-DATE
[Incubating] Problems report is available at: file:///home/$USER/AndroidStudioProjects/$APPNAME/build/reports/problems/problems-report.html
Deprecated Gradle features were used in this build, making it incompatible with Gradle 10.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/9.7.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 2s

In the problems-report.html there is 15 times the same warning:

Declaring dependencies using multi-string notation has been deprecated. (15)
- [warn] Declaring dependencies using multi-string notation has been deprecated.
Declaring dependencies using multi-string notation has been deprecated.
This will fail with an error in Gradle 10.

- Locations
[enum] Plugin`com.chaquo.python`

- Solutions
[enum] Please use single-string notation ("com.chaquo.python.runtime:chaquopy_java:17.0.0@jar") or DependencyFactory instead.

I use gradle 9.7.1 so it compiles. But then when I run the app I get the following errors:

2 problems were found storing the configuration cache.
- Plugin 'com.chaquo.python': external process started '/usr/bin/python3 /home/$USER/AndroidStudioProjects/$APPNAME/app/build/python/check_build_python.py 3.10'
  See https://docs.gradle.org/9.7.1/userguide/configuration_cache_requirements.html#config_cache:requirements:external_processes
- Task `:app:extractDebugPythonBuildPackages` of type `com.chaquo.python.TaskBuilder$BuildPackagesTask`: error writing value of type 'kotlin.SynchronizedLazyImpl'

See the complete report at file:///home/$USER/AndroidStudioProjects/$APPNAME/build/reports/configuration-cache/57bcmkq2bk7157k83cp8pp70/7h06o4gk5xqz0mohgqg3wks1j/configuration-cache-report.html
> Starting an external process '/usr/bin/python3 /home/$USER/AndroidStudioProjects/$APPNAME/app/build/python/check_build_python.py 3.10' during configuration time is unsupported.

There the report says:

1st:

- [error] error writing value of type `kotlin.SynchronizedLazyImpl`
-- field `pythonExecutable$delegate` of `com.chaquo.python.TaskBuilder$BuildPackagesTask`
--- task `:app:extractDebugPythonBuildPackages` of type `com.chaquo.python.TaskBuilder$BuildPackagesTask`
---- Exception at `com.chaquo.python.TaskBuilder.findBuildPython(PythonTasks.kt:638)`

and 2nd:

- [error] external process started `/usr/bin/python3 /home/$USER/AndroidStudioProjects/$APPNAME/app/build/python/check_build_python.py 3.10`
-- plugin 'com.chaquo.python'
--- Exception at `com.chaquo.python.TaskBuilder.exec(PythonTasks.kt:652)`

I think I have to change the way python is being built, but I don't know how... I tried to work with tasks in gradle in order to build python the last but I didn't succeed. I tried to tinker with the buildPath of chaquopy in build.gradle.kts:App, but that didn't work either.

Does anybody have an idea what to do?

1
Sep 17 at 2:35 PM
User Avatarlesenv
#android#kotlin#gradle#build#chaquopy

Accepted Answer

The current version of Chaquopy doesn't support the Gradle configuration cache. This will be fixed in the next release in early October.

Meanwhile, you can work around it by finding the org.gradle.configuration-cache=true line in your gradle.properties file, and changing it to false.

User Avatarmhsmith
Sep 17 at 3:34 PM
2