Skip to content

Commit f40c447

Browse files
committed
Improve android setup tools
- Rename ANDROID_SDK to ANDROID_SDK_ROOT, refer to: https://developer.android.google.cn/studio/command-line/variables - CMake: Use ndk in sdk_root/ndk/xxx/
1 parent f152c8e commit f40c447

File tree

7 files changed

+24
-41
lines changed

7 files changed

+24
-41
lines changed

core/platform/android/libcocos2dx/axistools.gradle

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,8 @@ class axistools {
103103
ndkVer = ndkVer.substring(0, ndkVer.length() - 1)
104104
}
105105

106-
/* Collect ndk dirs */
107-
def ndkRoot = Paths.get("${System.env.ANDROID_NDK}")
108106
def ndkDirs = []
109-
if (Files.exists(ndkRoot)) {
110-
ndkRoot = ndkRoot.toAbsolutePath().toString()
111-
ndkDirs.add(ndkRoot)
112-
}
113-
114-
def sdkRoot = Paths.get("${System.env.ANDROID_SDK}")
107+
def sdkRoot = Paths.get("${System.env.ANDROID_SDK_ROOT}")
115108
if (Files.exists(sdkRoot)) {
116109
File dir = new File(sdkRoot.toAbsolutePath().toString() + '/ndk')
117110
if (dir.isDirectory()) {
@@ -159,7 +152,7 @@ class axistools {
159152
}
160153
}
161154

162-
def sdkRoot = Paths.get("${System.env.ANDROID_SDK}")
155+
def sdkRoot = Paths.get("${System.env.ANDROID_SDK_ROOT}")
163156

164157
if(Files.exists(sdkRoot)) {
165158
def verList = []

setup.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
This script will install environment variables needed to by axis. It will set these envrironment variables:
3030
* AXIS_CONSOLE_ROOT: used to run axis console tools
3131
* ANDROID_NDK: used to build android native codes
32-
* ANDROID_SDK: used to generate applicatoin on Android through commands
32+
* ANDROID_SDK_ROOT: used to generate applicatoin on Android through commands
3333
* AXIS_ROOT: path where axis is installed
3434
3535
On Max OS X, when start a shell, it will read these files and execute commands in sequence:
@@ -67,7 +67,7 @@
6767
AXIS_CONSOLE_ROOT = 'AXIS_CONSOLE_ROOT'
6868

6969
ANDROID_NDK = 'ANDROID_NDK'
70-
ANDROID_SDK = 'ANDROID_SDK'
70+
ANDROID_SDK_ROOT = 'ANDROID_SDK_ROOT'
7171

7272
def _check_python_version():
7373
major_ver = sys.version_info[0]
@@ -194,7 +194,7 @@ def _set_environment_variable_unix(self, key, value):
194194
file.write('\n# Add environment variable %s for axis\n' % key)
195195
file.write('export %s="%s"\n' % (key, value))
196196
file.write('export PATH=$%s:$PATH\n' % key)
197-
if key == ANDROID_SDK:
197+
if key == ANDROID_SDK_ROOT:
198198
file.write(
199199
'export PATH=$%s/tools:$%s/platform-tools:$PATH\n' % (key, key))
200200
file.close()
@@ -296,7 +296,7 @@ def _get_input_value(self, var_name):
296296
# if sys_var == ANDROID_NDK:
297297
# root.wm_title('Set ANDROID_NDK')
298298
# else:
299-
# root.wm_title('Set ANDROID_SDK')
299+
# root.wm_title('Set ANDROID_SDK_ROOT')
300300

301301
# def callback():
302302
# self.tmp_input_value = tkFileDialog.askdirectory()
@@ -312,14 +312,14 @@ def _get_input_value(self, var_name):
312312
# You can safely skip this step now. You can set the ANDROID_NDK later.
313313
# """
314314

315-
# if sys_var == ANDROID_SDK:
315+
# if sys_var == ANDROID_SDK_ROOT:
316316
# label_content = 'Select path for Android SDK'
317317
# label_help = """
318318
# The Android SDK is needed to develop games for Android.
319319
# For further information, go to:
320320
# https://developer.android.com/tools/sdk/ndk/index.html.
321321

322-
# You can safely skip this step now. You can set the ANDROID_SDK later.
322+
# You can safely skip this step now. You can set the ANDROID_SDK_ROOT later.
323323
# """
324324

325325
# Tkinter.Label(root, text=label_help).pack()
@@ -346,7 +346,7 @@ def _check_valid(self, var_name, value):
346346
ret = False
347347
if var_name == ANDROID_NDK:
348348
ret = self._is_ndk_root_valid(value)
349-
elif var_name == ANDROID_SDK:
349+
elif var_name == ANDROID_SDK_ROOT:
350350
ret = self._is_android_sdk_root_valid(value)
351351
else:
352352
ret = False
@@ -583,7 +583,7 @@ def _get_sdkpath_for_cmd(self, cmd, has_bin_folder=True):
583583
def _find_value_from_sys(self, var_name):
584584
if var_name == ANDROID_NDK:
585585
return self._get_ndkbuild_path()
586-
elif var_name == ANDROID_SDK:
586+
elif var_name == ANDROID_SDK_ROOT:
587587
return self._get_androidsdk_path()
588588
else:
589589
return None
@@ -656,7 +656,7 @@ def set_environment_variables(self, ndk_root, android_sdk_root, quiet):
656656
self.file_used_for_setup)
657657
if(quiet) :
658658
ndk_ret = self.set_variable(ANDROID_NDK, ndk_root)
659-
sdk_ret = self.set_variable(ANDROID_SDK, android_sdk_root)
659+
sdk_ret = self.set_variable(ANDROID_SDK_ROOT, android_sdk_root)
660660

661661
# tip the backup file
662662
if (self.backup_file is not None) and (os.path.exists(self.backup_file)):

thirdparty/android-specific/cpufeatures/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@ set(target_name ${lib_name})
44

55
project(${lib_name})
66

7-
# CMake from android SDK set ANDROID_NDK instead of CMAKE_ANDROID_NDK
8-
if(ANDROID_NDK)
9-
add_library(${target_name} ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
10-
set(cpufeatures_include_dir ${ANDROID_NDK}/sources/android/cpufeatures CACHE INTERNAL "cpufeatures include directory")
11-
else()
12-
add_library(${target_name} ${CMAKE_ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
13-
set(cpufeatures_include_dir ${CMAKE_ANDROID_NDK}/sources/android/cpufeatures CACHE INTERNAL "cpufeatures include directory")
14-
endif()
7+
add_library(${target_name} ${CMAKE_ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
8+
set(cpufeatures_include_dir ${CMAKE_ANDROID_NDK}/sources/android/cpufeatures CACHE INTERNAL "cpufeatures include directory")
159

1610
set_target_properties(${target_name} PROPERTIES
1711
INTERFACE_INCLUDE_DIRECTORIES ${cpufeatures_include_dir})

tools/console/plugins/plugin_compile/build_android.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(self, verbose, app_android_root, no_res, proj_obj, mode, build_type
5353
self.build_type = build_type
5454

5555
# check environment variable
56-
self.sdk_root = axis.check_environment_variable('ANDROID_SDK')
56+
self.sdk_root = axis.check_environment_variable('ANDROID_SDK_ROOT')
5757
self.ant_root = None
5858
if os.path.exists(os.path.join(self.app_android_root, "gradle.properties")):
5959
self.sign_prop_file = os.path.join(self.app_android_root, "gradle.properties")

tools/console/plugins/plugin_deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def deploy_android(self, dependencies):
160160
self.package = compile_dep.android_package
161161
self.activity = compile_dep.android_activity
162162
apk_path = compile_dep.apk_path
163-
sdk_root = axis.check_environment_variable('ANDROID_SDK')
163+
sdk_root = axis.check_environment_variable('ANDROID_SDK_ROOT')
164164
adb_path = axis.CMDRunner.convert_path_to_cmd(os.path.join(sdk_root, 'platform-tools', 'adb'))
165165

166166
if not self._no_uninstall:

tools/console/plugins/plugin_run/project_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def run_android_device(self, dependencies):
238238
if not self._platforms.is_android_active():
239239
return
240240

241-
sdk_root = axis.check_environment_variable('ANDROID_SDK')
241+
sdk_root = axis.check_environment_variable('ANDROID_SDK_ROOT')
242242
adb_path = axis.CMDRunner.convert_path_to_cmd(os.path.join(sdk_root, 'platform-tools', 'adb'))
243243
deploy_dep = dependencies['deploy']
244244
startapp = "%s shell am start -n \"%s/%s\"" % (adb_path, deploy_dep.package, deploy_dep.activity)

tools/unix-ci/setup_android.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
NDK_VER = "23.2.8568313" # "r23c LTS"
3434

3535
# ANDROID_NDK = os.path.join(ROOT_DIR, "android-ndk-" + NDK_VER)
36-
ANDROID_SDK = os.path.join(ROOT_DIR, "android-sdk")
37-
ANDROID_NDK = os.path.join(ANDROID_SDK, "ndk/" + NDK_VER)
36+
ANDROID_SDK_ROOT = os.path.join(ROOT_DIR, "android-sdk")
37+
ANDROID_NDK = os.path.join(ANDROID_SDK_ROOT, "ndk/" + NDK_VER)
3838
SDK_MANAGER = os.path.join(ROOT_DIR, "cmdline-tools/bin/sdkmanager")
3939
SYSTEM = platform.system().lower()
4040
if SYSTEM == "windows":
@@ -95,9 +95,9 @@ def install_android_cmdline_tools():
9595
@retry(Exception, tries=5, delay=1, backoff=1)
9696
def install_android_sdk():
9797
# list packages
98-
run_with_yes(SDK_MANAGER + " --list --sdk_root=" + ANDROID_SDK)
98+
run_with_yes(SDK_MANAGER + " --list --sdk_root=" + ANDROID_SDK_ROOT)
9999

100-
switches = " --verbose --sdk_root=" + ANDROID_SDK + " "
100+
switches = " --verbose --sdk_root=" + ANDROID_SDK_ROOT + " "
101101
cmd_base = SDK_MANAGER + switches
102102
packages = [
103103
'platform-tools',
@@ -115,17 +115,13 @@ def install_android_sdk():
115115
def export_environment(ndk_only):
116116
with open(os.path.join(ROOT_DIR, "environment.sh"), "a") as myfile:
117117
if not ndk_only:
118-
myfile.write("export ANDROID_SDK=" + ANDROID_SDK + "\n")
119-
myfile.write("export ANDROID_HOME=" + ANDROID_SDK + "\n")
120-
myfile.write("export ANDROID_SDK_ROOT=" + ANDROID_SDK + "\n")
121-
myfile.write("export ANDROID_NDK=" + ANDROID_NDK + "\n")
118+
myfile.write("export ANDROID_SDK_ROOT=" + ANDROID_SDK_ROOT + "\n") # refer to: https://developer.android.google.cn/studio/command-line/variables
119+
myfile.write("export ANDROID_NDK=" + ANDROID_NDK + "\n") # for lua binding generator
122120

123121
with open(os.path.join(ROOT_DIR, "environment.ps1"), "a") as myfile:
124122
if not ndk_only:
125-
myfile.write("$env:ANDROID_SDK=\"" + ANDROID_SDK + "\"\n")
126-
myfile.write("$env:ANDROID_HOME=\"" + ANDROID_SDK + "\"\n")
127-
myfile.write("$env:ANDROID_SDK_ROOT=\"" + ANDROID_SDK + "\"\n")
128-
myfile.write("$env:ANDROID_NDK=\"" + ANDROID_NDK + "\"\n")
123+
myfile.write("$env:ANDROID_SDK_ROOT=\"" + ANDROID_SDK_ROOT + "\"\n")
124+
myfile.write("$env:ANDROID_NDK=\"" + ANDROID_NDK + "\"\n") # for lua binding generator
129125

130126
def main(ndk_only):
131127
install_android_cmdline_tools()

0 commit comments

Comments
 (0)