Repository navigation
Closed
Labels
Priority: MediumThis issue may be useful, and needs some attention.This issue may be useful, and needs some attention.
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 <module>
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.<init>(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(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
Reacted by Albert
Metadata
Metadata
Assignees
Labels
Priority: MediumThis issue may be useful, and needs some attention.This issue may be useful, and needs some attention.
Activity
android build: bump targetSdkVersion to 30
misl6 commentedon Apr 6, 2022
Yeah, recently
toolsbecamecmdline-tools.In
buildozerwe're still relying on an old version of the cmdline tools, which are located attools, but I agree that should be updated to support the newest ones (or at least we should support both locations)mavavilj commentedon Apr 10, 2022
I have this same problem, I've followed instructions at:
https://stackoverflow.com/a/67413427
and
https://python-for-android.readthedocs.io/en/latest/quickstart/#installing-android-sdk
Then when building I get:
I don't know about you, but to me this sounds very acute, because I don't understand any way around.
mavavilj commentedon Apr 10, 2022
I can proceed by editing /usr/lib/python3.10/site-packages/pythonforandroid/build.py lines 116 and 117 to:
But now the error becomes:
misl6 commentedon Apr 10, 2022
As a workaround, until we update
python-for-androidto support the latest Android command-line-tools version, please rely on the following links:macOS: https://dl.google.com/android/repository/commandlinetools-mac-6514223_latest.zip
Linux: https://dl.google.com/android/repository/commandlinetools-linux-6514223_latest.zip
mavavilj commentedon Apr 10, 2022
I can also proceed from the previous edit of /usr/lib/python3.10/site-packages/pythonforandroid/build.py lines 116 and 117 to:
Then the error becomes:
misl6 commentedon Apr 10, 2022
Did you installed the requested API?
See: https://python-for-android.readthedocs.io/en/latest/quickstart/#platform-and-build-tools
mavavilj commentedon Apr 10, 2022
Yes, but by using /opt/android-sdk/cmdline-tools/latest/bin/sdkmanager as given in:
https://stackoverflow.com/questions/65262340/cmdline-tools-could-not-determine-sdk-root/67413427#67413427
my ~/.bashrc:
The installation created a new /tools/ for example, but:
At line 358 of /usr/lib/python3.10/site-packages/pythonforandroid/build.py we find:
apis = get_available_apis(self.sdk_dir)The self.sdk_dir prints to /opt/android-sdk, which indeed should be the sdk_root.
mavavilj commentedon Apr 10, 2022
The reason it doesn't return any available APIs is caused by:
apis = [s for s in targets if re.match(r'^ *API level: ', s)]at line 131
resulting to apis = [].
Even when the line before it
targets = get_targets(sdk_dir)has the full output of /opt/android-sdk/cmdline-tools/latest/bin/sdkmanager --list. This list actually does contain:
system-images;android-27;default;arm64-v8a | 1 | ARM 64 v8a System Imagemavavilj commentedon Apr 10, 2022
I can proceed by commenting out the lines that check for the API (358-367):
Now the error becomes:
mavavilj commentedon Apr 10, 2022
I can proceed by modifying line 430 to use the python3 that I really use:
"python3.10", "-m", "cython", "--help",Now error becomes:
mavavilj commentedon Apr 10, 2022
Finally,
changing to android-ndk-r19c, rather than android-ndk-r23b, the build starts and goes on for quite a long time until I hit something which looks like a python3 name mismatch again:
mavavilj commentedon Apr 10, 2022
Modifying line 1118 of recipe.py to:
python_command = sh.Command("python3.10")ends up to:
Which may suggest that altering "python3" is not robust.
Also:
kivy/buildozer#1422
dbnicholson commentedon May 31, 2022
In #2593 I changed p4a to prefer the newer
avdmanagerincmdline-tools/latest/bin. I don't know if that fixes buildozer, though.4 remaining items
android sdk tools: adapt path to file hierarchy changes
android sdk tools: adapt path to file hierarchy changes
android sdk tools: adapt path to file hierarchy changes
android sdk tools: adapt path to file hierarchy changes
android sdk tools: adapt path to file hierarchy changes
android sdk tools: adapt path to file hierarchy changes
android sdk tools: adapt path to file hierarchy changes
lufebe16 commentedon Mar 4, 2023
Just coming back of a fdroidata merge. And agiain trapped into the
avdmanager ClassNonFoundException. f-droid too seems to
have its own problems with the new command line tools. But why does p4a use
that call? Time to dig into the code.
The only call to avdmanager is in build.py/get_targets() as
'avdmanager list targts'. It delivers a list of parameters for
each targent.
get_targets() is called only from get_available_apis(). The only
relevant information extracted in there are the api numbers. Isn't it not
an overkill?
Targets api information in android-sdk resides in the subdir 'platforms'
So why not simply do:
def get_available_apis(sdk_dir): apis = [] path = join(sdk_dir, 'platforms') if exists(path): targets = os.listdir(path) apis = [s for s in targets if re.match(r'^ *android-', s)] apis = [re.findall(r'[0-9]+', s) for s in apis] apis = [int(s[0]) for s in apis if s] else: raise BuildInterruptingException( 'Could not find platfrom information in Android SDK', instructions='Make sure the path to the Android SDK is correct') return apisThis would deliver the same information and eliminate a critical dependency.
lufebe16 commentedon Mar 4, 2023
Addendum (correctly formatted now):
android sdk tools: adapt path to file hierarchy changes
android sdk tools: adapt path to file hierarchy changes
android sdk tools: adapt path to file hierarchy changes
android build: bump targetSdkVersion to 30
AndreMiras commentedon Oct 9, 2026
Thanks for the report, this was addressed in #2593