From 8b7a2d582c4c3030c48c799a4384a62be8f605b0 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Thu, 7 Aug 2014 13:04:35 +0300 Subject: [PATCH] Android: Say hello to gradle! Add build.gradle script, move Android template files to another folder. These files are specific to every project, and they should be copied to then project android folder. Switching from Ant to Gradle brings lots of advantages: - it is way faster when rebuilding (25-50% faster than ant). - it enables first class Android Studio integration. - adding Android Extras libs (e.g. Google Play services, OBB, etc.) to your project is now painless. [ChangeLog][Android] Added Gradle support to build the APK. Change-Id: I9c8cb355118c9ac1997270c8b80916eca43fce4d Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/android/android.pro | 2 +- .../qt5/android/QtActivityDelegate.java | 3 ++ src/android/java/java.pro | 4 -- src/android/java/res/values/strings.xml | 3 +- src/android/java/version.xml | 8 --- .../{java => templates}/AndroidManifest.xml | 4 +- src/android/templates/build.gradle | 51 +++++++++++++++++++ .../{java => templates}/res/values/libs.xml | 0 src/android/templates/templates.pro | 21 ++++++++ 9 files changed, 79 insertions(+), 17 deletions(-) delete mode 100644 src/android/java/version.xml rename src/android/{java => templates}/AndroidManifest.xml (97%) create mode 100644 src/android/templates/build.gradle rename src/android/{java => templates}/res/values/libs.xml (100%) create mode 100644 src/android/templates/templates.pro diff --git a/src/android/android.pro b/src/android/android.pro index 1850f012c0..55a94a2c06 100644 --- a/src/android/android.pro +++ b/src/android/android.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = jar java accessibility +SUBDIRS = jar java templates accessibility diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java index 9407db932f..f57497069a 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -507,6 +507,9 @@ public class QtActivityDelegate ? extras.getString("gdbserver_socket") : "+debug-socket"; + if (!(new File(gdbserverPath)).exists()) + gdbserverPath += ".so"; + // start debugger m_debuggerProcess = Runtime.getRuntime().exec(gdbserverPath + socket diff --git a/src/android/java/java.pro b/src/android/java/java.pro index cff2d55d86..9d37eb1026 100644 --- a/src/android/java/java.pro +++ b/src/android/java/java.pro @@ -1,8 +1,6 @@ CONFIG -= qt android_install javaresources.files = \ - $$PWD/AndroidManifest.xml \ - $$PWD/version.xml \ $$PWD/res \ $$PWD/src @@ -18,8 +16,6 @@ INSTALLS += javaresources OUT_PATH = $$shell_path($$OUT_PWD) QMAKE_POST_LINK += \ - $${QMAKE_COPY} $$shell_path($$PWD/AndroidManifest.xml) $$OUT_PATH $$RETURN \ - $${QMAKE_COPY} $$shell_path($$PWD/version.xml) $$OUT_PATH $$RETURN \ $${QMAKE_COPY_DIR} $$shell_path($$PWD/res) $$OUT_PATH $$RETURN \ $${QMAKE_COPY_DIR} $$shell_path($$PWD/src) $$OUT_PATH } diff --git a/src/android/java/res/values/strings.xml b/src/android/java/res/values/strings.xml index 300f0673a4..fcc3eb097b 100644 --- a/src/android/java/res/values/strings.xml +++ b/src/android/java/res/values/strings.xml @@ -1,7 +1,6 @@ - - + Can\'t find Ministro service.\nThe application can\'t start. This application requires Ministro service. Would you like to install it? Your application encountered a fatal error and cannot continue. diff --git a/src/android/java/version.xml b/src/android/java/version.xml deleted file mode 100644 index e05bba7588..0000000000 --- a/src/android/java/version.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - AndroidManifest.xml - libs.xml - logo.png - icon.png - - diff --git a/src/android/java/AndroidManifest.xml b/src/android/templates/AndroidManifest.xml similarity index 97% rename from src/android/java/AndroidManifest.xml rename to src/android/templates/AndroidManifest.xml index e5060f0de9..60c612976f 100644 --- a/src/android/java/AndroidManifest.xml +++ b/src/android/templates/AndroidManifest.xml @@ -1,9 +1,9 @@ - + diff --git a/src/android/templates/build.gradle b/src/android/templates/build.gradle new file mode 100644 index 0000000000..d1ff362269 --- /dev/null +++ b/src/android/templates/build.gradle @@ -0,0 +1,51 @@ +buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:0.12.1' + } +} + +apply plugin: 'android' + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) +} + +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() + + buildToolsVersion androidBuildToolsVersion + + 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'] + } + } + + lintOptions { + abortOnError false + } +} diff --git a/src/android/java/res/values/libs.xml b/src/android/templates/res/values/libs.xml similarity index 100% rename from src/android/java/res/values/libs.xml rename to src/android/templates/res/values/libs.xml diff --git a/src/android/templates/templates.pro b/src/android/templates/templates.pro new file mode 100644 index 0000000000..684a556c5b --- /dev/null +++ b/src/android/templates/templates.pro @@ -0,0 +1,21 @@ +CONFIG -= qt android_install + +templates.files = \ + $$PWD/AndroidManifest.xml \ + $$PWD/res + +templates.path = $$[QT_INSTALL_PREFIX]/src/android/templates + +INSTALLS += templates + +!prefix_build:!equals(OUT_PWD, $$PWD) { + RETURN = $$escape_expand(\\n\\t) + equals(QMAKE_HOST.os, Windows) { + RETURN = $$escape_expand(\\r\\n\\t) + } + OUT_PATH = $$shell_path($$OUT_PWD) + + QMAKE_POST_LINK += \ + $${QMAKE_COPY} $$shell_path($$PWD/AndroidManifest.xml) $$OUT_PATH $$RETURN \ + $${QMAKE_COPY_DIR} $$shell_path($$PWD/res) $$OUT_PATH +}