Commit cca96b3a authored by Sharaf Zaman's avatar Sharaf Zaman

Added `create-apk` target in CMakeLists.txt to build apk

added `build.gradle` to build android

Depends on: https://phabricator.kde.org/D20558
parent d232b478
......@@ -265,17 +265,18 @@ if(ANDROID)
set (Qt5Quick_DIR $ENV{QT_ANDROID}/lib/cmake/Qt5Quick/)
set (Qt5QuickWidgets_DIR $ENV{QT_ANDROID}/lib/cmake/Qt5QuickWidgets/)
set (KF5_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/lib)
set(ECM_DIR ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/share/ECM/cmake)
set(KF5Config_DIR ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5Config/)
set(KF5Config_DIR ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5Config/)
set(KF5I18n_DIR ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5I18n/)
set(KF5WidgetsAddons_DIR ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5WidgetsAddons)
set(KF5Completion_DIR ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5Completion)
set(KF5GuiAddons_DIR ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5GuiAddons)
set(KF5ItemViews_DIR ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5ItemViews)
set(KF5WindowSystem_DIR ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5WindowSystem)
set(KF5ItemModels_DIR ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5ItemModels)
set(KF5CoreAddons_DIR ${CMAKE_CURRENT_BINARY_DIR}/kf5/kde/install/lib/cmake/KF5CoreAddons)
set(KF5Config_DIR ${KF5_LIBRARIES}/cmake/KF5Config/)
set(KF5Config_DIR ${KF5_LIBRARIES}/cmake/KF5Config/)
set(KF5I18n_DIR ${KF5_LIBRARIES}/cmake/KF5I18n/)
set(KF5WidgetsAddons_DIR ${KF5_LIBRARIES}/cmake/KF5WidgetsAddons)
set(KF5Completion_DIR ${KF5_LIBRARIES}/cmake/KF5Completion)
set(KF5GuiAddons_DIR ${KF5_LIBRARIES}/cmake/KF5GuiAddons)
set(KF5ItemViews_DIR ${KF5_LIBRARIES}/cmake/KF5ItemViews)
set(KF5WindowSystem_DIR ${KF5_LIBRARIES}/cmake/KF5WindowSystem)
set(KF5ItemModels_DIR ${KF5_LIBRARIES}/cmake/KF5ItemModels)
set(KF5CoreAddons_DIR ${KF5_LIBRARIES}/cmake/KF5CoreAddons)
endif()
......@@ -530,11 +531,15 @@ endif()
# set custom krita plugin installdir
if (ANDROID)
# use default ABI
if (NOT ANDROID_ABI)
set (ANDROID_ABI armeabi-v7a)
endif()
set (KRITA_PLUGIN_INSTALL_DIR ${LIB_INSTALL_DIR}/${ANDROID_ABI})
set (DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/assets)
set (ANDROID_SDK_ROOT $ENV{ANDROID_SDK_ROOT})
set (KRITA_PLUGIN_INSTALL_DIR ${LIB_INSTALL_DIR})
# set (DATA_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/assets)
else()
set (KRITA_PLUGIN_INSTALL_DIR ${LIB_INSTALL_DIR}/kritaplugins)
endif()
......@@ -561,6 +566,25 @@ if (ANDROID)
set (GSL_CBLAS_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/i/lib/libgslcblas.so)
set (GSL_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/i/include/)
set (GSL_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/i/bin/gsl-config)
set (EXPAT_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/i/lib/libexpat.so)
# libraries to be used when bundling android apk
# FIXME: better way to do this?
list (APPEND ANDROID_EXTRA_LIBS ${PNG_LIBRARY}
${LibExiv2_LIBRARIES}
${QUAZIP_LIBRARIES}
${LCMS2_LIBRARIES}
${EXPAT_LIBRARY}
${KF5_LIBRARIES}/libKF5Completion.so
${KF5_LIBRARIES}/libKF5WindowSystem.so
${KF5_LIBRARIES}/libKF5WidgetsAddons.so
${KF5_LIBRARIES}/libKF5ItemViews.so
${KF5_LIBRARIES}/libKF5ItemModels.so
${KF5_LIBRARIES}/libKF5GuiAddons.so
${KF5_LIBRARIES}/libKF5I18n.so
${KF5_LIBRARIES}/libKF5CoreAddons.so
${KF5_LIBRARIES}/libKF5ConfigGui.so
${KF5_LIBRARIES}/libKF5ConfigCore.so)
endif()
find_package(PNG REQUIRED)
......@@ -583,6 +607,9 @@ set_package_properties(GSL PROPERTIES
PURPOSE "Required by Krita's Transform tool.")
macro_bool_to_01(GSL_FOUND HAVE_GSL)
configure_file(config-gsl.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-gsl.h )
if (GSL_FOUND)
list (APPEND ANDROID_EXTRA_LIBS ${GSL_LIBRARIES} ${GSL_CBLAS_LIBRARIES})
endif()
###########################
############################
......@@ -871,3 +898,27 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/po OR EXISTS ${CMAKE_CURRENT_BINARY_DIR}/p
ki18n_install(po)
endif()
if(DEFINED QTANDROID_EXPORTED_TARGET AND NOT TARGET "create-apk")
set (_CMAKE_ANDROID_DIR "${ECM_DIR}/../toolchain")
list(LENGTH QTANDROID_EXPORTED_TARGET targetsCount)
include(${_CMAKE_ANDROID_DIR}/ECMAndroidDeployQt.cmake)
math(EXPR last "${targetsCount}-1")
foreach(idx RANGE 0 ${last})
list(GET QTANDROID_EXPORTED_TARGET ${idx} exportedTarget)
list(GET ANDROID_APK_DIR ${idx} APK_DIR)
if(APK_DIR AND NOT EXISTS "${ANDROID_APK_DIR}/AndroidManifest.xml" AND IS_ABSOLUTE ANDROID_APK_DIR)
message(FATAL_ERROR "Cannot find ${APK_DIR}/AndroidManifest.xml according to ANDROID_APK_DIR. ${ANDROID_APK_DIR} ${exportedTarget}")
elseif(NOT APK_DIR)
get_filename_component(_qt5Core_install_prefix "${Qt5Core_DIR}/../../../" ABSOLUTE)
set(APK_DIR "${_qt5Core_install_prefix}/src/android/templates/")
endif()
ecm_androiddeployqt("${exportedTarget}" "${ECM_ADDITIONAL_FIND_ROOT_PATH}")
set_target_properties(create-apk-${exportedTarget} PROPERTIES ANDROID_APK_DIR "${APK_DIR}")
endforeach()
else()
message(STATUS "You can export a target by specifying -DQTANDROID_EXPORTED_TARGET=<targetname> and -DANDROID_APK_DIR=<paths>")
endif()
......@@ -6,45 +6,55 @@ $KRITA_ROOT/3rdparty
KRITA_ROOT # project root directory
CMAKE_ANDROID_NDK
QT_ANDROID # example: /opt/Qt/5.12/android_armv7/
ANDROID_API_LEVEL # example: 21
ANDROID_API_LEVEL # example: 21 (I used 28)
ANDROID_SDK_ROOT
PY_INCLUDE_PATH # python3 includes directory usually /usr/includes/python3.5/
PY_LIBRARY # python3 lib directory usually /usr/lib/python3.5/
```
2) Create three directories in project root(KRITA_ROOT): d, i, b
2) Create three directories in build root(BUILD_ROOT): `d, i, b`
3) First we'll have to build kf5 dependencies which we use `kdesrc-build`
to do. So run `$KRITA_ROOT/packaging/android/build_kf5.sh`.
Now if package kcompletion, kcoreaddons fail at first, don't stop the
build, wait for the script to stop, it will be patched and rebuilt
automatically.
to do. So, run `$KRITA_ROOT/packaging/android/build_kf5.sh`.
4) `cd` to `$KRITA_ROOT/b` and run
4) `cd` to `$BUILD_ROOT/b` and run
```$KRITA_ROOT/packaging/android/build_ext.sh```
Now in this case
every package SHOULD be built. If it doesn't, then it's mostly a bug.
5) Now we have to build boost.
Run:
```$KRITA_ROOT/packaging/android/build_boost.sh```
This should build without any errors.
6) Create a directory in $KRITA_ROOT and set INSTALL_PREFIX environment
variable to set installation directory.
6) set `INSTALL_PREFIX` environment variable to install built binaries into
the directory.
(please create a new directory and use that as a location to install)
Then run `$KRITA_ROOT/packaging/android/configure_krita.sh`
```
mkdir $KRITA_ROOT/build-android && cd $KRITA_ROOT/build-android
```shell
$KRITA_ROOT/packaging/android/configure_krita.sh
```
This should build all the _required_ libraries.
7) If build is configured properly then run
```
```shell
make -j5
make install
```
arm binary should be ready
ARM binary should be ready
8) Now to create APK, run and sit back as gradle can be really slow
```shell
make create-apk
```
Now if `adb` is in your PATH then run `make install-apk-krita`, if it is not
in your `PATH` you can add it or use this:
```shell
$ANDROID_SDK_ROOT/platform-tools/adb -d -r krita_build_apk/build/outputs/apk/debug/krita_build_apk-debug.apk
```
Now if the app crashes you can use `logcat`, to see the trace.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
}
}
repositories {
google()
jcenter()
}
apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}
task ("configure") {
doLast {
def abi = System.getenv('ANDROID_ABI')
if (abi == null) {
abi = 'armeabi-v7a'
logger.error('ANDROID_ABI not specified using the default one instead: armeabi-7a')
}
def installPrefix = System.getenv('INSTALL_PREFIX')
if (installPrefix == null) {
throw new GradleException('Please set INSTALL_PREFIX to the location where binaries are installed')
}
def libs = new File(installPrefix, 'lib')
if (!libs.exists()) {
throw new GradleException('Please run `make install` first')
}
}
}
// copy libs(plugins) which start with krita*.so and rename
// them to start with `lib_`
task copyLibs(type: Copy, dependsOn: configure) {
from "${System.getenv('INSTALL_PREFIX')}/lib"
into 'libs/armeabi-v7a'
rename ('^krita(.*).so$', 'lib_krita$1.so')
}
task copyAssets(type: Copy) {
from "${System.getenv('INSTALL_PREFIX')}/share/"
into 'assets'
}
copyLibs.dependsOn configure
android {
/*******************************************************
* The following variables:
* - androidBuildToolsVersion,
* - androidCompileSdkVersion
* - qt5AndroidDir - holds the path to qt android files
* needed to build any Qt application
* on Android.
*
* are defined in gradle.properties file. This file is
* updated by QtCreator and androiddeployqt tools.
* Changing them manually might break the compilation!
*******************************************************/
compileSdkVersion androidCompileSdkVersion.toInteger()
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs', 'lib']
}
}
// This is needed because, gradle by default ignores hidden assets.
aaptOptions {
ignoreAssetsPattern "!.foajasoie"
}
lintOptions {
abortOnError false
}
defaultConfig {
targetSdkVersion 26
minSdkVersion 21
}
preBuild.dependsOn(copyLibs)
preBuild.dependsOn(copyAssets)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment