2022-07-05 13:26:52 +02:00
# Copyright (C) 2022 The Qt Company Ltd.
2022-08-19 15:21:34 +02:00
# SPDX-License-Identifier: BSD-3-Clause
2022-07-05 13:26:52 +02:00
2019-06-05 12:07:42 +02:00
#
2019-06-06 14:29:31 +02:00
# Self contained Platform Settings for Android
#
2020-09-28 20:19:05 +03:00
# Note: This file is used by the internal builds.
2019-06-06 14:29:31 +02:00
#
#
2020-09-28 20:19:05 +03:00
# Variables:
2019-06-06 14:29:31 +02:00
# QT_ANDROID_JAR
# Location of the adroid sdk jar for java code
2024-08-05 13:27:09 +02:00
# QT_ANDROID_API_USED_FOR_JAVA
# Android API version for building java code
2019-06-05 12:07:42 +02:00
#
if ( NOT DEFINED ANDROID_SDK_ROOT )
2020-10-05 13:32:23 +02:00
message ( FATAL_ERROR "Please provide the location of the Android SDK directory via -DANDROID_SDK_ROOT=<path to Android SDK>" )
2019-06-05 12:07:42 +02:00
endif ( )
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 ( )
2025-03-28 09:00:01 +01:00
_qt_internal_locate_android_jar ( )
2019-06-05 12:07:42 +02:00
# Locate Java
include ( UseJava )
# Find JDK 8.0
find_package ( Java 1.8 COMPONENTS Development REQUIRED )
2019-06-06 14:29:31 +02:00
# Ensure we are using the shared version of libc++
if ( NOT ANDROID_STL STREQUAL c++_shared )
message ( FATAL_ERROR "The Qt libraries on Android only supports the shared library configuration of stl. Please use -DANDROID_STL=\" c++_shared\ " as configuration argument." )
endif ( )
# Target properties required for android deploy tool
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ D E P L O Y M E N T _ D E P E N D E N C I E S
B R I E F _ D O C S
" S p e c i f y a d d i t i o n a l p l u g i n s t h a t n e e d t o b e d e p l o y e d w i t h t h e c u r r e n t a n d r o i d a p p l i c a t i o n "
F U L L _ D O C S
" B y d e f a u l t , a n d r o i d d e p l o y q t w i l l d e t e c t t h e d e p e n d e n c i e s o f y o u r a p p l i c a t i o n . B u t s i n c e r u n - t i m e u s a g e o f p l u g i n s c a n n o t b e d e t e c t e d , t h e r e c o u l d b e f a l s e p o s i t i v e s , a s y o u r a p p l i c a t i o n w i l l d e p e n d o n a n y p l u g i n s t h a t a r e p o t e n t i a l d e p e n d e n c i e s . I f y o u w a n t t o m i n i m i z e t h e s i z e o f y o u r A P K , i t ' s p o s s i b l e t o o v e r r i d e t h e a u t o m a t i c d e t e c t i o n u s i n g t h e A N D R O I D _ D E P L O Y M E N T _ D E P E N D E N C I E S v a r i a b l e . T h i s s h o u l d c o n t a i n a l i s t o f a l l Q t f i l e s w h i c h n e e d t o b e i n c l u d e d , w i t h p a t h s r e l a t i v e t o t h e Q t i n s t a l l r o o t . N o t e t h a t o n l y t h e Q t f i l e s s p e c i f i e d h e r e w i l l b e i n c l u d e d . F a i l i n g t o i n c l u d e t h e c o r r e c t f i l e s c a n r e s u l t i n c r a s h e s . I t ' s a l s o i m p o r t a n t t o m a k e s u r e t h e f i l e s a r e l i s t e d i n t h e c o r r e c t l o a d i n g o r d e r . T h i s v a r i a b l e p r o v i d e s a w a y t o o v e r r i d e t h e a u t o m a t i c d e t e c t i o n e n t i r e l y , s o i f a l i b r a r y i s l i s t e d b e f o r e i t s d e p e n d e n c i e s , i t w i l l f a i l t o l o a d o n s o m e d e v i c e s . "
)
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ E X T R A _ L I B S
B R I E F _ D O C S
" A l i s t o f e x t e r n a l l i b r a r i e s t h a t w i l l b e c o p i e d i n t o y o u r a p p l i c a t i o n ' s l i b r a r y f o l d e r a n d l o a d e d o n s t a r t - u p . "
F U L L _ D O C S
" A l i s t o f e x t e r n a l l i b r a r i e s t h a t w i l l b e c o p i e d i n t o y o u r a p p l i c a t i o n ' s l i b r a r y f o l d e r a n d l o a d e d o n s t a r t - u p . T h i s c a n b e u s e d , f o r i n s t a n c e , t o e n a b l e O p e n S S L i n y o u r a p p l i c a t i o n . S i m p l y s e t t h e p a t h s t o t h e r e q u i r e d l i b s s l . s o a n d l i b c r y p t o . s o l i b r a r i e s h e r e a n d O p e n S S L s h o u l d b e e n a b l e d a u t o m a t i c a l l y . "
)
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ E X T R A _ P L U G I N S
B R I E F _ D O C S
" T h i s v a r i a b l e c a n b e u s e d t o s p e c i f y d i f f e r e n t r e s o u r c e s t h a t y o u r p r o j e c t h a s t o b u n d l e b u t c a n n o t b e d e l i v e r e d t h r o u g h t h e a s s e t s s y s t e m , s u c h a s q m l p l u g i n s . "
F U L L _ D O C S
" T h i s v a r i a b l e c a n b e u s e d t o s p e c i f y d i f f e r e n t r e s o u r c e s t h a t y o u r p r o j e c t h a s t o b u n d l e b u t c a n n o t b e d e l i v e r e d t h r o u g h t h e a s s e t s s y s t e m , s u c h a s q m l p l u g i n s . W h e n u s i n g t h i s v a r i a b l e , a n d r o i d d e p l o y q t w i l l m a k e s u r e e v e r y t h i n g i s p a c k a g e d a n d d e p l o y e d p r o p e r l y . "
)
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ P A C K A G E _ S O U R C E _ D I R
B R I E F _ D O C S
" T h i s v a r i a b l e c a n b e u s e d t o s p e c i f y a d i r e c t o r y w h e r e a d d i t i o n s a n d m o d i f i c a t i o n s c a n b e m a d e t o t h e d e f a u l t A n d r o i d p a c k a g e t e m p l a t e . "
F U L L _ D O C S
" T h i s v a r i a b l e c a n b e u s e d t o s p e c i f y a d i r e c t o r y w h e r e a d d i t i o n s a n d m o d i f i c a t i o n s c a n b e m a d e t o t h e d e f a u l t A n d r o i d p a c k a g e t e m p l a t e . T h e a n d r o i d d e p l o y q t t o o l w i l l c o p y t h e a p p l i c a t i o n t e m p l a t e f r o m Q t i n t o t h e b u i l d d i r e c t o r y , a n d t h e n i t w i l l c o p y t h e c o n t e n t s o f t h e A N D R O I D _ P A C K A G E _ S O U R C E _ D I R o n t o p o f t h i s , o v e r w r i t i n g a n y e x i s t i n g f i l e s . T h e u p d a t e s t e p w h e r e p a r t s o f t h e s o u r c e f i l e s a r e m o d i f i e d a u t o m a t i c a l l y t o r e f l e c t y o u r o t h e r s e t t i n g s i s t h e n r u n o n t h e r e s u l t i n g m e r g e d p a c k a g e . I f y o u , f o r i n s t a n c e , w a n t t o m a k e a c u s t o m A n d r o i d M a n i f e s t . x m l f o r y o u r a p p l i c a t i o n , t h e n p l a c e t h i s d i r e c t l y i n t o t h e f o l d e r s p e c i f i e d i n t h i s v a r i a b l e . Y o u c a n a l s o a d d c u s t o m J a v a f i l e s i n A N D R O I D _ P A C K A G E _ S O U R C E _ D I R / s r c . "
)
2020-08-13 17:39:22 +03:00
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ A P P L I C A T I O N _ A R G U M E N T S
B R I E F _ D O C S
" T h i s v a r i a b l e c a n b e u s e d t o s p e c i f y c o m m a n d - l i n e a r g u m e n t s t o t h e A n d r o i d a p p . "
F U L L _ D O C S
" S p e c i f i e s e x t r a c o m m a n d - l i n e a r g u m e n t s t o t h e A n d r o i d a p p u s i n g t h e A n d r o i d M a n i f e s t . x m l w i t h t h e t a g a n d r o i d . a p p . a r g u m e n t s . "
)
2019-06-06 14:29:31 +02:00
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ D E P L O Y M E N T _ S E T T I N G S _ F I L E
B R I E F _ D O C S
2020-09-28 16:00:32 +03:00
" T h i s v a r i a b l e i s u s e d t o s p e c i f y t h e d e p l o y m e n t s e t t i n g s J S O N f i l e f o r a n d r o i d d e p l o y q t . "
2019-06-06 14:29:31 +02:00
F U L L _ D O C S
2020-09-28 16:00:32 +03:00
" T h i s v a r i a b l e p o i n t s t o t h e p a t h o f t h e d e p l o y m e n t s e t t i n g s J S O N f i l e , w h i c h h o l d s p r o p e r t i e s r e q u i r e d b y a n d r o i d d e p l o y q t t o p a c k a g e t h e A n d r o i d a p p . "
2019-06-06 14:29:31 +02:00
)
2022-01-19 13:35:50 +02:00
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ S Y S T E M _ L I B S _ P R E F I X
B R I E F _ D O C S
" T h i s v a r i a b l e i s u s e d t o s p e c i f y a p a t h t o Q t l i b r a r i e s o n t h e t a r g e t d e v i c e i n A n d r o i d . "
F U L L _ D O C S
" T h i s v a r i a b l e c a n b e u s e d t o p r o v i d e a c u s t o m s y s t e m l i b r a r y p a t h t o u s e f o r l i b r a r y l o a d i n g l o o k u p o n A n d r o i d . T h i s i s n e c e s s a r y w h e n u s i n g Q t l i b r a r i e s i n s t a l l e d o u t s i d e a n a p p ' s d e f a u l t native ( JNI ) l i b r a r y d i r e c t o r y . "
)
define_property ( TARGET
P R O P E R T Y
Q T _ A N D R O I D _ N O _ D E P L O Y _ Q T _ L I B S
B R I E F _ D O C S
" T h i s v a r i a b l e i s u s e d t o c o n t r o l w h e t h e r Q t l i b r a r i e s s h o u l d b e d e p l o y e d i n s i d e t h e A P K o n A n d r o i d . "
F U L L _ D O C S
" T h i s v a r i a b l e c a n b e u s e d t o e x c l u d e Q t s h a r e d l i b r a r i e s f r o m b e i n g p a c k a g e d i n s i d e t h e A P K w h e n d e p l o y i n g o n A n d r o i d . N o t s u p p o r t e d w h e n d e p l o y i n g a s A n d r o i d A p p l i c a t i o n B u n d l e . "
)
2020-12-08 15:40:43 +01:00
# Returns test execution arguments for Android targets
CMake:Android: add wrapper scripts to easily run apps
Create a script that allows running an app or a test easily similar
to running on host. This improves development workflow and time by
allowing quick runs without having to manually call the various adb
commands to launch, get a pid of the app and then print the logcat,
let alone passing parameters or environment variables.
For normal apps, the app package name is retrieved by the script, run
and live logcat is printed as long as the app is still running.
For tests, the script calls androidtestrunner, allowing test parameters
to be passed to the test.
For CI debugging, this would save quite a lot of hussle and frustration
trying to run or debug a test app.
One other benefit for this is enabling running Android tests from Qt
Creator's testlib plugin without big changes to Qt Creator to support
androidtestrunner explicitly.
Because file(GENERATE) would fail if called twice for the same file,
I use file(WRITE). This is used because at the time of calling the
target executable finalizer, we don't know if the target is a test
or not, so we rely on writing the script first as a normal target,
then call it if the target is a test where it overrides the script.
For this also, parameters passed to the runner or androidtestrunner
can't handle generator expressions.
[ChangeLog][CMake][Android] Add wrapper scripts to run Android apps and
tests with ease from the host.
Task-number: QTBUG-129889
Change-Id: I84e85ce2bbf6944c8aa20bdc2c2b6d7b956bc748
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-10-07 17:43:31 +03:00
function ( qt_internal_android_test_runner_arguments target out_test_runner out_test_arguments )
2025-03-17 18:55:27 +01:00
qt_internal_get_host_info_var_prefix ( host_info_var_prefix )
set ( host_bin_dir "${QT_HOST_PATH}/${${host_info_var_prefix}_BINDIR}" )
set ( ${ out_test_runner } "${host_bin_dir}/androidtestrunner" PARENT_SCOPE )
set ( deployment_tool "${host_bin_dir}/androiddeployqt" )
2019-10-24 10:50:06 +02:00
2025-03-03 13:05:09 +01:00
_qt_internal_android_get_target_android_build_dir ( android_build_dir ${ target } )
2020-12-08 15:40:43 +01:00
set ( ${ out_test_arguments }
CMake:Android: add wrapper scripts to easily run apps
Create a script that allows running an app or a test easily similar
to running on host. This improves development workflow and time by
allowing quick runs without having to manually call the various adb
commands to launch, get a pid of the app and then print the logcat,
let alone passing parameters or environment variables.
For normal apps, the app package name is retrieved by the script, run
and live logcat is printed as long as the app is still running.
For tests, the script calls androidtestrunner, allowing test parameters
to be passed to the test.
For CI debugging, this would save quite a lot of hussle and frustration
trying to run or debug a test app.
One other benefit for this is enabling running Android tests from Qt
Creator's testlib plugin without big changes to Qt Creator to support
androidtestrunner explicitly.
Because file(GENERATE) would fail if called twice for the same file,
I use file(WRITE). This is used because at the time of calling the
target executable finalizer, we don't know if the target is a test
or not, so we rely on writing the script first as a normal target,
then call it if the target is a test where it overrides the script.
For this also, parameters passed to the runner or androidtestrunner
can't handle generator expressions.
[ChangeLog][CMake][Android] Add wrapper scripts to run Android apps and
tests with ease from the host.
Task-number: QTBUG-129889
Change-Id: I84e85ce2bbf6944c8aa20bdc2c2b6d7b956bc748
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-10-07 17:43:31 +03:00
" - - p a t h " " $ { a n d r o i d _ b u i l d _ d i r } "
2020-12-08 15:40:43 +01:00
" - - a d b " " $ { A N D R O I D _ S D K _ R O O T } / p l a t f o r m - t o o l s / a d b "
" - - s k i p - i n s t a l l - r o o t "
2023-12-18 15:01:56 +02:00
" - - m a k e " " \ " $ { C M A K E _ C O M M A N D } \ " - - b u i l d $ { C M A K E _ B I N A R Y _ D I R } - - t a r g e t $ { t a r g e t } _ m a k e _ a p k "
CMake:Android: add wrapper scripts to easily run apps
Create a script that allows running an app or a test easily similar
to running on host. This improves development workflow and time by
allowing quick runs without having to manually call the various adb
commands to launch, get a pid of the app and then print the logcat,
let alone passing parameters or environment variables.
For normal apps, the app package name is retrieved by the script, run
and live logcat is printed as long as the app is still running.
For tests, the script calls androidtestrunner, allowing test parameters
to be passed to the test.
For CI debugging, this would save quite a lot of hussle and frustration
trying to run or debug a test app.
One other benefit for this is enabling running Android tests from Qt
Creator's testlib plugin without big changes to Qt Creator to support
androidtestrunner explicitly.
Because file(GENERATE) would fail if called twice for the same file,
I use file(WRITE). This is used because at the time of calling the
target executable finalizer, we don't know if the target is a test
or not, so we rely on writing the script first as a normal target,
then call it if the target is a test where it overrides the script.
For this also, parameters passed to the runner or androidtestrunner
can't handle generator expressions.
[ChangeLog][CMake][Android] Add wrapper scripts to run Android apps and
tests with ease from the host.
Task-number: QTBUG-129889
Change-Id: I84e85ce2bbf6944c8aa20bdc2c2b6d7b956bc748
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-10-07 17:43:31 +03:00
" - - a p k " " $ { a n d r o i d _ b u i l d _ d i r } / $ { t a r g e t } . a p k "
2023-12-08 12:11:48 +02:00
" - - n d k - s t a c k " " $ { A N D R O I D _ N D K _ R O O T } / n d k - s t a c k "
2020-12-08 15:40:43 +01:00
P A R E N T _ S C O P E
2019-10-24 10:50:06 +02:00
)
endfunction ( )