Add conversion code for Java code

Add support to pro2cmake to convert java code for android.

Add support to override API_LEVEL for the Android sdk jar file. If the
sdk is not found, we'll default to the one located by QT_ANDROID_JAR.

Change-Id: If0b746dc7f9148ac43e6592a4a4dd23d46bbd4cd
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Leander Beernaert 2019-10-18 14:28:08 +02:00
parent 7e7f41e40c
commit 373be4200b
6 changed files with 127 additions and 45 deletions

View File

@ -27,6 +27,18 @@ if (NOT IS_DIRECTORY "${ANDROID_SDK_ROOT}")
message(FATAL_ERROR "Could not find ANDROID_SDK_ROOT or path is not a directory: ${ANDROID_SDK_ROOT}")
endif()
# Get the Android SDK jar for an API version other than the one specified with
# QT_ANDROID_API_VERSION.
function(qt_get_android_sdk_jar_for_api api out_jar_location)
set(jar_location "${ANDROID_SDK_ROOT}/platforms/${api}/android.jar")
if (NOT EXISTS "${jar_location}")
message(WARNING "Could not locate Android SDK jar for api '${api}', defaulting to ${QT_ANDROID_API_VERSION}")
set(${out_jar_location} ${QT_ANDROID_JAR} PARENT_SCOPE)
else()
set(${out_jar_location} ${jar_location} PARENT_SCOPE)
endif()
endfunction()
# Minimum recommend android SDK api version
set(QT_ANDROID_API_VERSION "android-21")

View File

@ -0,0 +1,30 @@
# Generated from jar.pro.
set(java_sources
src/org/qtproject/qt5/android//accessibility/QtAccessibilityDelegate.java
src/org/qtproject/qt5/android//accessibility/QtNativeAccessibility.java
src/org/qtproject/qt5/android//CursorHandle.java
src/org/qtproject/qt5/android//EditContextView.java
src/org/qtproject/qt5/android//EditPopupMenu.java
src/org/qtproject/qt5/android//ExtractStyle.java
src/org/qtproject/qt5/android//QtActivityDelegate.java
src/org/qtproject/qt5/android//QtEditText.java
src/org/qtproject/qt5/android//QtInputConnection.java
src/org/qtproject/qt5/android//QtLayout.java
src/org/qtproject/qt5/android//QtMessageDialogHelper.java
src/org/qtproject/qt5/android//QtNative.java
src/org/qtproject/qt5/android//QtNativeLibrariesDir.java
src/org/qtproject/qt5/android//QtSurface.java
src/org/qtproject/qt5/android//QtThread.java
)
add_jar(QtAndroid
INCLUDE_JARS ${QT_ANDROID_JAR}
SOURCES ${java_sources}
)
install_jar(QtAndroid
DESTINATION jar
COMPONENT Devel
)

View File

@ -1,33 +1,31 @@
# QtAndroid Jar
# special case skip regeneration
# special case begin
set(path_prefix ${CMAKE_CURRENT_SOURCE_DIR}/src/org/qtproject/qt5/android/)
# Generated from jar.pro.
set(java_sources
${path_prefix}/accessibility/QtAccessibilityDelegate.java
${path_prefix}/accessibility/QtNativeAccessibility.java
${path_prefix}/CursorHandle.java
${path_prefix}/EditContextView.java
${path_prefix}/EditPopupMenu.java
${path_prefix}/ExtractStyle.java
${path_prefix}/QtActivityDelegate.java
${path_prefix}/QtEditText.java
${path_prefix}/QtInputConnection.java
${path_prefix}/QtLayout.java
${path_prefix}/QtMessageDialogHelper.java
${path_prefix}/QtNative.java
${path_prefix}/QtNativeLibrariesDir.java
${path_prefix}/QtServiceDelegate.java
${path_prefix}/QtSurface.java
${path_prefix}/QtThread.java)
src/org/qtproject/qt5/android/accessibility/QtAccessibilityDelegate.java
src/org/qtproject/qt5/android/accessibility/QtNativeAccessibility.java
src/org/qtproject/qt5/android/CursorHandle.java
src/org/qtproject/qt5/android/EditContextView.java
src/org/qtproject/qt5/android/EditPopupMenu.java
src/org/qtproject/qt5/android/ExtractStyle.java
src/org/qtproject/qt5/android/QtActivityDelegate.java
src/org/qtproject/qt5/android/QtEditText.java
src/org/qtproject/qt5/android/QtInputConnection.java
src/org/qtproject/qt5/android/QtLayout.java
src/org/qtproject/qt5/android/QtMessageDialogHelper.java
src/org/qtproject/qt5/android/QtNative.java
src/org/qtproject/qt5/android/QtNativeLibrariesDir.java
src/org/qtproject/qt5/android/QtSurface.java
src/org/qtproject/qt5/android/QtThread.java
src/org/qtproject/qt5/android/QtServiceDelegate.java # special case
)
add_jar(QtAndroid
INCLUDE_JARS ${QT_ANDROID_JAR}
SOURCES ${java_sources}
)
)
install_jar(QtAndroid
DESTINATION jar
COMPONENT Devel)
# special case end
COMPONENT Devel
)

View File

@ -1,18 +1,16 @@
# Generated from jar.pro.
#####################################################################
## QtAndroidBearer Binary:
#####################################################################
add_qt_executable(QtAndroidBearer
GUI
INSTALL_DIRECTORY "${INSTALL_DIRECTORY}/jar"
OUTPUT_DIRECTORY "$$MODULE_BASE_OUTDIR/jar"
PUBLIC_LIBRARIES
Qt::Gui
set(java_sources
src/org/qtproject/qt5/android/bearer/QtNetworkReceiver.java
)
add_jar(QtAndroidBearer
INCLUDE_JARS ${QT_ANDROID_JAR}
SOURCES ${java_sources}
)
install_jar(QtAndroidBearer
DESTINATION jar
COMPONENT Devel
)
#### Keys ignored in scope 1:.:.:jar.pro:<TRUE>:
# JAVACLASSPATH = "$$PWD/src"
# JAVASOURCES = "$$PWD/src/org/qtproject/qt5/android/bearer/QtNetworkReceiver.java"
# _LOADED = "qt_build_paths"

View File

@ -1,10 +1,9 @@
# special case begin
# This is a manually edited file
set(path_prefix ${CMAKE_CURRENT_SOURCE_DIR}/src/org/qtproject/qt5/android/bearer)
#####################################################################
## QtAndroidBearer Binary:
#####################################################################
set(java_sources
${path_prefix}/QtNetworkReceiver.java
src/org/qtproject/qt5/android/bearer/QtNetworkReceiver.java
)
add_jar(QtAndroidBearer
@ -16,4 +15,8 @@ install_jar(QtAndroidBearer
DESTINATION jar
COMPONENT Devel)
# special case end
#### Keys ignored in scope 1:.:.:jar.pro:<TRUE>:
# JAVACLASSPATH = "$$PWD/src"
# JAVASOURCES = "$$PWD/src/org/qtproject/qt5/android/bearer/QtNetworkReceiver.java"
# _LOADED = "qt_build_paths"

View File

@ -2692,6 +2692,44 @@ def write_find_package_section(
cm_fh.write("\n")
def write_jar(cm_fh: IO[str], scope: Scope, *, indent: int = 0) -> str:
target = scope.TARGET
install_dir = scope.expandString("target.path")
if not install_dir:
raise RuntimeError("Could not locate jar install path")
install_dir = install_dir.replace("$$[QT_INSTALL_PREFIX]/", "")
android_sdk_jar = "${QT_ANDROID_JAR}"
android_api_level = scope.get_string("API_VERSION")
if android_api_level:
cm_fh.write(f'{spaces(indent)}qt_get_android_sdk_jar_for_api("{android_api_level}" android_sdk)\n\n')
android_sdk_jar ="${android_sdk}"
write_source_file_list(
cm_fh,
scope,
"",
["JAVASOURCES"],
indent=indent,
header=f"set(java_sources\n",
footer=")\n",
)
cm_fh.write(f"{spaces(indent)}add_jar({target}\n")
cm_fh.write(f"{spaces(indent+1)}INCLUDE_JARS {android_sdk_jar}\n")
cm_fh.write(f"{spaces(indent+1)}SOURCES ${{java_sources}}\n")
cm_fh.write(f"{spaces(indent)})\n\n")
cm_fh.write(f"{spaces(indent)}install_jar({target}\n")
cm_fh.write(f"{spaces(indent+1)}DESTINATION {install_dir}\n")
cm_fh.write(f"{spaces(indent+1)}COMPONENT Devel\n")
cm_fh.write(f"{spaces(indent)})\n\n")
return target
def write_example(
cm_fh: IO[str], scope: Scope, gui: bool = False, *, indent: int = 0, is_plugin: bool = False
) -> str:
@ -3030,6 +3068,7 @@ def handle_app_or_lib(
assert scope.TEMPLATE in ("app", "lib")
config = scope.get("CONFIG")
is_jar = "java" in config
is_lib = scope.TEMPLATE == "lib"
is_qml_plugin = any("qml_plugin" == s for s in scope.get("_LOADED"))
is_plugin = (
@ -3040,7 +3079,9 @@ def handle_app_or_lib(
val not in config for val in ["console", "cmdline"]
) and "testlib" not in scope.expand("QT")
if is_example:
if is_jar:
tar = write_jar(cm_fh, scope, indent=indent)
elif is_example:
target = write_example(cm_fh, scope, gui, indent=indent, is_plugin=is_plugin)
elif is_plugin:
assert not is_example