kivy / kivy/python-for-android

p4a Doesn't Pick Up Latest Installed Java Command Line Tools, Resulting in avdmanager exception

Open
#2,540 15 comments 1 reaction 0 assignees View on GitHub
Priority: Medium
Dominant language
Python
Stars
8.9k
Forks
2k
Avg merge
12h 20m
Merged PRs (30d)
9

Description

### Versions

- Python: 3.9.7
- OS: Ubuntu 20.04
- Kivy: 2.0
- Cython: 0.29.25
- OpenJDK: 11.0.13

### Description
I'm trying to build an apk with p4a for the first time. Using IntellijIdea, I installed the latest sdk command line tools. But p4a used the avdmanager in ../Sdk/tools/bin, instead of the new one which was installed in the default location .../Sdk/cmdline-tools/latest/bin. The avdmanager then threw a ClassNotFoundException for javax.xml.bind.annotation.XmlSchema.

### Logs

```
$ p4a apk --private $HOME/Test/Python/kivydemo-for-android/showcase --package=com.rhrapps.showcase --name "Kivy Showcase" --version 0.1 --bootstrap=sdl2 --requirements=Python,kivy
[WARNING]: $ANDROIDNDKVER is deprecated and no longer necessary, the value you set is ignored
[INFO]: Will compile for the following archs: armeabi-v7a
[INFO]: Found Android API target in $ANDROIDAPI: 32
Traceback (most recent call last):
File "/home/rhr/Tools/miniconda3/envs/kivy_env/bin/p4a", line 8, in
sys.exit(main())
File "/home/rhr/Tools/miniconda3/envs/kivy_env/lib/python3.9/site-packages/pythonforandroid/entrypoints.py", line 18, in main
ToolchainCL()
File "/home/rhr/Tools/miniconda3/envs/kivy_env/lib/python3.9/site-packages/pythonforandroid/toolchain.py", line 725, in __init__
getattr(self, command)(args)
File "/home/rhr/Tools/miniconda3/envs/kivy_env/lib/python3.9/site-packages/pythonforandroid/toolchain.py", line 143, in wrapper_func
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
File "/home/rhr/Tools/miniconda3/envs/kivy_env/lib/python3.9/site-packages/pythonforandroid/build.py", line 300, in prepare_build_environment
apis = get_available_apis(self.sdk_dir)
File "/home/rhr/Tools/miniconda3/envs/kivy_env/lib/python3.9/site-packages/pythonforandroid/build.py", line 74, in get_available_apis
targets = get_targets(sdk_dir)
File "/home/rhr/Tools/miniconda3/envs/kivy_env/lib/python3.9/site-packages/pythonforandroid/build.py", line 62, in get_targets
targets = avdmanager('list', 'target').stdout.decode('utf-8').split('\n')
File "/home/rhr/Tools/miniconda3/envs/kivy_env/lib/python3.9/site-packages/sh.py", line 1566, in __call__
return RunningCommand(cmd, call_args, stdin, stdout, stderr)
File "/home/rhr/Tools/miniconda3/envs/kivy_env/lib/python3.9/site-packages/sh.py", line 822, in __init__
self.wait()
File "/home/rhr/Tools/miniconda3/envs/kivy_env/lib/python3.9/site-packages/sh.py", line 879, in wait
self.handle_command_exit_code(exit_code)
File "/home/rhr/Tools/miniconda3/envs/kivy_env/lib/python3.9/site-packages/sh.py", line 905, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:

RAN: /home/rhr/Android/Sdk/tools/bin/avdmanager list target

STDOUT:

STDERR:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:213)
at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:200)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 5 more

```

Contributor guide

Open the contributing guide

Research direction

Start in pythonforandroid/build.py at get_targets(), which calls avdmanager, and trace SDK tool selection from the toolchain.py entry point shown in the traceback. Reproduce the supplied p4a command and verify that the current command-line tools are selected and the avdmanager exception no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, python
Domain
build-system, mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.