Skip to content

Commit

Permalink
Minor Win32 improvements (#1648)
Browse files Browse the repository at this point in the history
* Minor Win32 improvements

There is no win32 support for the Android target. This doesn't change that. It does, however, enable experimental support, via an (unpublished) environment variable, to allow exploration of what is required.

Also, there are some signs of vestigial attempts at supporting Windows. As they haven't been run before, they need a little care:

- Updated references from _winreg to winreg (Built-in module was renamed in Python 3.)
- Corrected download URL to Android NDK for the Windows platform
- Supported sdkmanager installer having a different name (.bat extension) on Windows.

- Also corrected trivial formatting error in Exception text, which applies to all platforms.

* Calculate SDK manager path in two steps for clarity
  • Loading branch information
Julian-O authored Aug 6, 2023
1 parent 2e547c9 commit 8828e09
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions buildozer/targets/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Android target, based on python-for-android project
'''

import os
import sys
if sys.platform == 'win32':
if sys.platform == 'win32' and not os.getenv("KIVY_WIN32_ANDROID_EXPERIMENTAL"):
raise NotImplementedError('Windows platform not yet working for Android')

from platform import uname
Expand All @@ -20,7 +21,6 @@
DEFAULT_ANDROID_NDK_VERSION = '17c'

import traceback
import os
import io
import re
import ast
Expand Down Expand Up @@ -244,12 +244,17 @@ def apache_ant_dir(self):

@property
def sdkmanager_path(self):
sdk_manager_name = (
'sdkmanager.bat'
if platform in ('win32', 'cygwin')
else 'sdkmanager'
)
sdkmanager_path = join(
self.android_sdk_dir, 'tools', 'bin', 'sdkmanager')
self.android_sdk_dir, 'tools', 'bin', sdk_manager_name)
if not os.path.isfile(sdkmanager_path):
raise BuildozerException(
('sdkmanager path "{}" does not exist, sdkmanager is not'
'installed'.format(sdkmanager_path)))
' installed'.format(sdkmanager_path)))
return sdkmanager_path

@property
Expand Down Expand Up @@ -314,14 +319,14 @@ def _p4a_have_aab_support(self):
def _set_win32_java_home(self):
if 'JAVA_HOME' in self.buildozer.environ:
return
import _winreg
with _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
import winreg
with winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\JavaSoft\Java Development Kit") as jdk: # @UndefinedVariable
current_version, _type = _winreg.QueryValueEx(
current_version, _type = winreg.QueryValueEx(
jdk, "CurrentVersion") # @UndefinedVariable
with _winreg.OpenKey(jdk, current_version) as cv: # @UndefinedVariable
java_home, _type = _winreg.QueryValueEx(
with winreg.OpenKey(jdk, current_version) as cv: # @UndefinedVariable
java_home, _type = winreg.QueryValueEx(
cv, "JavaHome") # @UndefinedVariable
self.buildozer.environ['JAVA_HOME'] = java_home

Expand Down Expand Up @@ -410,7 +415,7 @@ def _install_android_ndk(self):
if platform in ('win32', 'cygwin'):
# Checking of 32/64 bits at Windows from: https://stackoverflow.com/a/1405971/798575
import struct
archive = 'android-ndk-r{0}-windows-{1}.zip'
archive = 'android-ndk-r{0}-windows.zip'
is_64 = (8 * struct.calcsize("P") == 64)
elif is_darwin or is_linux or is_freebsd:
_platform = 'linux' if (is_linux or is_freebsd) else 'darwin'
Expand Down

0 comments on commit 8828e09

Please sign in to comment.