add simple example '.android-ssl-test'

This commit is contained in:
pls.153 2024-11-20 20:59:23 +01:00
parent c55b08ab6c
commit c6cd718ef2
18 changed files with 470 additions and 0 deletions

2
examples/.android-ssl-test/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*
!.gitignore

View file

@ -0,0 +1,7 @@
(defsystem :app
:serial t
:depends-on (#-depends-loaded :drakma)
:components ((:file "lisp/package")
(:file "lisp/ui-vars")
(:file "lisp/main")))

View file

@ -0,0 +1,145 @@
LISP_FILES = $$files(lisp/*) app.asd make.lisp
android {
32bit {
ECL = $$(ECL_ANDROID_32)
} else {
ECL = $$(ECL_ANDROID)
}
lisp.commands = $$ECL/../ecl-android-host/bin/ecl \
-norc -shell $$PWD/make.lisp
} else:ios {
lisp.commands = $$(ECL_IOS)/../ecl-ios-host/bin/ecl \
-norc -shell $$PWD/make.lisp
} else:unix {
lisp.commands = /usr/local/bin/ecl -shell $$PWD/make.lisp
} else:win32 {
lisp.commands = ecl.exe -shell $$PWD/make.lisp
}
lisp.input = LISP_FILES
win32: lisp.output = tmp/app.lib
!win32: lisp.output = tmp/libapp.a
QMAKE_EXTRA_COMPILERS += lisp
win32: PRE_TARGETDEPS = tmp/app.lib
!win32: PRE_TARGETDEPS = tmp/libapp.a
QT += quick qml quickcontrols2
TEMPLATE = app
CONFIG += c++17 no_keywords release
DEFINES += DESKTOP_APP INI_LISP INI_ASDF INI_ECL_CONTRIB
INCLUDEPATH = /usr/local/include
ECL_VERSION = $$lower($$system(ecl -v))
ECL_VERSION = $$replace(ECL_VERSION, " ", "-")
LIBS = -L/usr/local/lib -lecl
LIBS += -L/usr/local/lib/$$ECL_VERSION
LIBS += -lasdf -lecl-help -ldeflate -lecl-cdb -lecl-curl -lql-minitar -lsockets
DESTDIR = .
TARGET = app
OBJECTS_DIR = tmp
MOC_DIR = tmp
linux: LIBS += -L../../../platforms/linux/lib
macx: LIBS += -L../../../platforms/macos/lib
win32: LIBS += -L../../../platforms/windows/lib
win32 {
LIBS += -lws2_32
RC_ICONS = platforms/windows/icon.ico
include(../../src/windows.pri)
}
android {
DEFINES -= DESKTOP_APP
INCLUDEPATH = $$ECL/include
ECL_VERSION = $$lower($$system($$ECL/../ecl-android-host/bin/ecl -v))
ECL_VERSION = $$replace(ECL_VERSION, " ", "-")
LIBS = -L$$ECL/lib -lecl
LIBS += -L$$ECL/lib/$$ECL_VERSION
LIBS += -lasdf -lecl-help -ldeflate -lecl-cdb -lecl-curl -lql-minitar -lsockets
LIBS += -L../../../platforms/android/lib
equals(QT_MAJOR_VERSION, 6) {
QT += core-private
}
lessThan(QT_MAJOR_VERSION, 6) {
QT += androidextras
}
ANDROID_MIN_SDK_VERSION = 21
ANDROID_TARGET_SDK_VERSION = 34
ANDROID_EXTRA_LIBS += $$ECL/lib/libecl.so
ANDROID_PACKAGE_SOURCE_DIR = ../platforms/android
# can be downloaded from:
# https://github.com/KDAB/android_openssl/tree/master/latest
32bit {
SSL_PATH = ../../../platforms/android/lib32
} else {
SSL_PATH = ../../../platforms/android/lib
}
ANDROID_EXTRA_LIBS += $$SSL_PATH/libcrypto.so $$SSL_PATH/libssl.so
32bit {
ANDROID_ABIS = "armeabi-v7a"
} else {
ANDROID_ABIS = "arm64-v8a"
}
}
ios {
DEFINES -= DESKTOP_APP
INCLUDEPATH = $$(ECL_IOS)/include
ECL_VERSION = $$lower($$system($ECL_IOS/../ecl-ios-host/bin/ecl -v))
ECL_VERSION = $$replace(ECL_VERSION, " ", "-")
LIBS = -L$$(ECL_IOS)/lib -lecl
LIBS += -leclatomic -leclffi -leclgc -leclgmp
LIBS += -L$$(ECL_IOS)/lib/$$ECL_VERSION
LIBS += -lasdf -lecl-help -ldeflate -lecl-cdb -lecl-curl -lql-minitar -lsockets
LIBS += -L../../../platforms/ios/lib
}
32bit {
android {
equals(QT_MAJOR_VERSION, 6) {
LIBS += -llqml32_armeabi-v7a
}
lessThan(QT_MAJOR_VERSION, 6) {
LIBS += -llqml32
}
}
!android {
LIBS += -llqml32
}
LIBS += -llisp32
} else {
android {
equals(QT_MAJOR_VERSION, 6) {
LIBS += -llqml_arm64-v8a
}
lessThan(QT_MAJOR_VERSION, 6) {
LIBS += -llqml
}
}
!android {
LIBS += -llqml
}
LIBS += -llisp
}
LIBS += -Ltmp -lapp
INCLUDEPATH += ../../../src/cpp
HEADERS += ../../src/cpp/main.h
SOURCES += ../../src/cpp/main.cpp
RESOURCES += $$files(qml/*)
RESOURCES += $$files(i18n/*.qm)
lupdate_only {
SOURCES += i18n/tr.h
}

View file

@ -0,0 +1,6 @@
# install/update (keeps app data)
adb install -r android-build/*.apk
# try both
adb shell am start -n org.qtproject.example.app/org.qtproject.qt5.android.bindings.QtActivity # Qt5
adb shell am start -n org.qtproject.example.app/org.qtproject.qt.android.bindings.QtActivity # Qt6

View file

@ -0,0 +1,6 @@
# filter for logcat to show only messages from:
# * (qlog ...) in Lisp
# * console.log(...) in QML
adb logcat -c
adb logcat -s "[LQML]"

View file

@ -0,0 +1,3 @@
../../../platforms/ios/cross-compile.sh ../make.lisp
open app.xcodeproj

View file

@ -0,0 +1,2 @@
*
!.gitignore

View file

@ -0,0 +1,31 @@
Translations
------------
Wrap all strings which need to be translated in either `(tr "")` (Lisp files)
or `qsTr("")` (QML files).
* compile app (either desktop or mobile, you may need `touch ../app.asd` to
force recompilation of all files); this will generate a dummy file `tr.h`,
containing all Lisp strings to translate
* run Qt command `lupdate` (here: Spanish, French) for creating the translation
source files from both Lisp and QML strings:
```
lupdate ../app.pro -ts es.ts fr.ts
```
* translate all `*.ts` files using **Qt Linguist**
* run Qt command `lrelease` to create compiled translation files:
```
lrelease es.ts fr.ts
```
* run respective `qmake` again (destop/mobile) in order to include all `*.qm`
files (compiled translations)
* next time you compile the app, the translation files will be included as
resources in the executable
Now when you launch the app, the translation file matching your system locale
setting of your platform (see `QLocale`) will be loaded, see `QTranslator` in
[main.cpp](../../../src/cpp/main.cpp).

View file

@ -0,0 +1,12 @@
(in-package :app)
#+android
(when (probe-file "libssl.so")
(ffi:load-foreign-library "libcrypto.so")
(ffi:load-foreign-library "libssl.so"))
(defun ini ()
(q> |text| ui:*label*
(first (last (multiple-value-list (drakma:http-request "https://duckduckgo.com"))))))
(qlater 'ini)

View file

@ -0,0 +1,4 @@
(defpackage :app
(:use :cl :qml)
(:export))

View file

@ -0,0 +1,9 @@
(defpackage ui
(:use :cl :qml)
(:export
#:*label*))
(in-package :ui)
(defparameter *label* "label")

View file

@ -0,0 +1,89 @@
;;; check target
(defvar *32bit* (<= most-positive-fixnum (expt 2 32)))
(let ((arg (first (ext:command-args))))
(mapc (lambda (name feature)
(when (search name arg)
(pushnew feature *features*)))
(list "/ecl-android" "/ecl-ios")
(list :android :ios)))
#+(or android ios)
(pushnew :mobile *features*)
(when (probe-file "/etc/sailfish-release")
(pushnew :sfos *features*))
;;; copy Swank and ECL contrib files (mobile only)
(defun cc (&rest args)
(apply 'concatenate 'string args))
#+mobile
(defvar *assets* #+android "../platforms/android/assets/lib/"
#+ios "../platforms/ios/assets/Library/")
#+mobile
(defun shell (command)
(ext:run-program "sh" (list "-c" command)))
;;; compile ASDF system
(require :asdf)
(require :cmp)
(push (merge-pathnames "../")
asdf:*central-registry*)
(setf *default-pathname-defaults*
(truename (merge-pathnames "../../../"))) ; LQML root
(defvar *current*
(let ((name (namestring *load-truename*)))
(subseq name
(length (namestring *default-pathname-defaults*))
(1+ (position #\/ name :from-end t)))))
(dolist (file (list "package" "x" "ecl-ext" "ini" "qml")) ; load LQML symbols
(load (merge-pathnames file "src/lisp/")))
(progn
(defvar cl-user::*tr-path* (truename (cc *current* "i18n/")))
(load "src/lisp/tr"))
#-mobile
(progn
(require :ecl-curl)
(asdf:make-build "app"
:monolithic t
:type :static-library
:move-here (cc *current* "build/tmp/")
:init-name "ini_app"))
#+mobile
(progn
(pushnew :interpreter *features*)
(defvar *asdf-system* "app")
(defvar *ql-libs* (cc *current* "ql-libs.lisp"))
(defvar *init-name* "ini_app")
(defvar *library-path* (format nil "~Abuild-~A/tmp/"
*current*
#+android "android"
#+ios "ios"))
(defvar *require* (list :ecl-curl))
(load "platforms/shared/make"))
;;; rename lib
(let* ((from #-mobile (cc *current* (format nil "build/tmp/app--all-systems.~A"
#+msvc "lib"
#-msvc "a"))
#+mobile (cc *library-path* "app--all-systems.a"))
(to #-msvc "libapp.a"
#+msvc "app.lib")
(to* #-mobile (cc *current* "build/tmp/" to)
#+mobile (cc *library-path* to)))
(when (probe-file to*)
(delete-file to*))
(rename-file from to))

View file

@ -0,0 +1,3 @@
mkdir build
mkdir build-android
mkdir build-ios

View file

@ -0,0 +1,86 @@
<?xml version="1.0"?>
<manifest package="org.qtproject.example.app" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
Remove the comment if you do not require these default permissions. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
Remove the comment if you do not require these default features. -->
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="app" android:extractNativeLibs="true">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="app" android:screenOrientation="unspecified" android:launchMode="singleTop" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<!-- Application arguments -->
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
<!-- Application arguments -->
<meta-data android:name="android.app.lib_name" android:value="app"/>
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
<meta-data android:name="android.app.repository" android:value="default"/>
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
<!-- Deploy Qt libs as part of package -->
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="1"/>
<!-- Run with local libs -->
<meta-data android:name="android.app.use_local_qt_libs" android:value="1"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
<meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
<meta-data android:name="android.app.load_local_jars" android:value="jar/QtAndroid.jar:jar/QtAndroidExtras.jar:jar/QtAndroidBearer.jar"/>
<meta-data android:name="android.app.static_init_classes" android:value=""/>
<!-- Used to specify custom system library path to run with local system libs -->
<!-- <meta-data android:name="android.app.system_libs_prefix" android:value="/system/lib/"/> -->
<!-- Messages maps -->
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
<meta-data android:value="@string/unsupported_android_version" android:name="android.app.unsupported_android_version"/>
<!-- Messages maps -->
<!-- Splash screen -->
<!-- Orientation-specific (portrait/landscape) data is checked first. If not available for current orientation,
then android.app.splash_screen_drawable. For best results, use together with splash_screen_sticky and
use hideSplashScreen() with a fade-out animation from Qt Android Extras to hide the splash screen when you
are done populating your window with content. -->
<!-- meta-data android:name="android.app.splash_screen_drawable_portrait" android:resource="@drawable/logo_portrait" / -->
<!-- meta-data android:name="android.app.splash_screen_drawable_landscape" android:resource="@drawable/logo_landscape" / -->
<!-- meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/ -->
<!-- meta-data android:name="android.app.splash_screen_sticky" android:value="true"/ -->
<!-- Splash screen -->
<!-- Background running -->
<!-- Warning: changing this value to true may cause unexpected crashes if the
application still try to draw after
"applicationStateChanged(Qt::ApplicationSuspended)"
signal is sent! -->
<meta-data android:name="android.app.background_running" android:value="false"/>
<!-- Background running -->
<!-- auto screen scale factor -->
<meta-data android:name="android.app.auto_screen_scale_factor" android:value="false"/>
<!-- auto screen scale factor -->
<!-- extract android style -->
<!-- available android:values :
* default - In most cases this will be the same as "full", but it can also be something else if needed, e.g., for compatibility reasons
* full - useful QWidget & Quick Controls 1 apps
* minimal - useful for Quick Controls 2 apps, it is much faster than "full"
* none - useful for apps that don't use any of the above Qt modules
-->
<meta-data android:name="android.app.extract_android_style" android:value="default"/>
<!-- extract android style -->
</activity>
<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
</application>
</manifest>

View file

@ -0,0 +1,4 @@
;;; define here eventual Quicklisp dependencies
(ql:quickload :drakma)

View file

@ -0,0 +1,15 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
Item {
width: 300
height: 500
Label {
objectName: "label"
text: "downloading..."
anchors.centerIn: parent
font.pixelSize: 24
font.bold: true
}
}

View file

@ -0,0 +1,15 @@
This is here for testing SSL on android.
After doing `make apk`, please ensure files
```
libssl.so
libcrypto.so
```
are present in directory
```
build-android/android-build/libs/arm64-v8a/
```
When running the app, it should first display "downloading...", and after a few
seconds (if the android device is connected to the internet), it should display
"OK".

View file

@ -0,0 +1,31 @@
(in-package :qml-user)
(require :asdf)
(asdf:load-system :drakma)
(push (merge-pathnames "./")
asdf:*central-registry*)
(push :depends-loaded *features*)
(asdf:operate 'asdf:load-source-op :app)
(qset *quick-view*
|x| 0
|y| 0)
(defun option (name)
(find name (ext:command-args) :test 'search))
;;; trivial auto reload of all QML files after saving any change
(when (option "-auto")
(load "lisp/qml-reload/auto-reload"))
;;; for Slime after copying 'lqml-start-swank.lisp' from LQML sources
;;; to your Slime directory, which is assumed to be '~/slime/'
(when (option "-slime")
(load "~/slime/lqml-start-swank")) ; for 'slime-connect' from Emacs