Details
-
Bug
-
Resolution: Fixed
-
Not Evaluated
-
Qt Creator 4.2.1, Qt Creator 4.3.0-beta1
-
None
-
Qt 5.8, androiddepployqt, Alpine Linux Grsec, Android build tools 25, NDK r10e, QtCreator 4.2.1 enterprise, Gradle 3.3, Android Studio 2.3-beta3
-
48c17a1e07e29e93e0b23ad6a64d457835497ae6 (qt-creator/qt-creator/4.3)
Description
( This relates to the fix in QTCREATORBUG-15568 )
When trying to do builds using Gradle versions newer than 2.x androiddeployqt builds will fail because the previous fix for missing distributionUrl does an exact regexp match for gradle version 2.x and otherwise modify the distributionUrl to using gradle-2.2.1-all.zip. The build fails as follows:
FAILURE: Build failed with an exception. * Where: Build file '/home/user/src/build-theproject-Android_for_armeabi_v7a_GCC_4_9_Qt_5_8_0-Debug/android-build/build.gradle' line: 32 * What went wrong: A problem occurred evaluating root project 'android-build'. > Failed to apply plugin [id 'com.android.application'] > Minimum supported Gradle version is 3.3. Current version is 2.2.1. If using the gradle wrapper, try editing the distributionUrl in /home/user/src/build-theproject-Android_for_armeabi_v7a_GCC_4_9_Qt_5_8_0-Debug/android-build/gradle/wrapper/gradle-wrapper.properties to gradle-3.3-all.zip * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 31.49 secs Building the android package failed! -- For more information, run this command with --verbose. 19:10:49: The process "/home/user/Qt/5.8/android_armv7/bin/androiddeployqt" exited with code 14. Error while building/deploying project theproject (kit: Android for armeabi-v7a (GCC 4.9, Qt 5.8.0)) When executing step "Build Android APK"
The following is in build.gradle:
buildscript { // ... // dependencies { classpath 'com.android.tools.build:gradle:2.3.0-beta3' } }
and in gradle-wrapper.properties:
...
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip
The stable Android Studio 2.2.x use Gradle 2.x, while Android Studio 2.3 Beta3 now use Gradle 3.3 - causing the regexp match to modify the newer gradle version in gradle-wrapper.properties. See
- https://github.com/qtproject/qt-creator/blob/v4.2.1/src/plugins/android/androidmanager.cpp#L541
- https://github.com/qtproject/qt-creator/blob/master/src/plugins/android/androidmanager.cpp#L561
My project Qmake contains:
OTHER_FILES += \ android/AndroidManifext.xml \ android/build.gradle \ android/gradlew \ android/gradlew.bat \ android/gradle/wrapper/gradle-wrapper.properties \ android/gradle/wrapper/gradle-wrapper.jar android { QT += nativeandroid DISTFILES += \ android/build.gradle \ android/gradlew \ android/gradlew.bat \ android/gradle/wrapper/gradle-wrapper.jar \ android/gradle/wrapper/gradle-wrapper.properties ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android ANDROID_SUPPORT = v4 v7 contains(ANDROID_TARGET_ARCH,armeabi-v7a) { ANDROID_EXTRA_LIBS = } }
For others possibly running into the same problem - I avoid the modification from androidmanager.cpp by moving the wrapper folder one level up and changing the CLASSPATH in gradlew from gradle/wrapper/gradle-wrapper.jar to wrapper/gradle-wrapper.jar and similarly change the path in the project Qmake file.
Also, rather than inject QtCreator Build Environment variables, I autodetect what executes the gradlew script (but a simple env variable from QtCreator or CI/CLI androiddeployqt would suffice) by adding in the same gradlew script somewhere after line 26:
# changed to avoid QtCreator 4.2.1 modifying distributonUrl - pinning it to gradle-2.2.1-all.zip CLASSPATH=$APP_HOME/wrapper/gradle-wrapper.jar PSPPID="ps --no-headers --format ppid --quick-pid" PP1ID="`$PSPPID $$ | tr -d ' '`" [ -n "$PP1ID" -a "$PP1ID" != "0" ] && PP2ID="`$PSPPID $PP1ID | tr -d ' '`" [ -n "$PP2ID" -a "$PP2ID" != "0" ] && PP3ID="`$PSPPID $PP2ID | tr -d ' '`" [ -n "$PP3ID" -a "$PP3ID" != "0" ] && PP4ID="`$PSPPID $PP3ID | tr -d ' '`" PIDCMD="ps --no-headers --format comm --quick-pid" [ -n "$PP1ID" -a "$PP1ID" != "0" ] && PP1CMD="`$PIDCMD $PP1ID`" [ -n "$PP2ID" -a "$PP2ID" != "0" ] && PP2CMD="`$PIDCMD $PP2ID`" [ -n "$PP3ID" -a "$PP3ID" != "0" ] && PP3CMD="`$PIDCMD $PP3ID`" [ -n "$PP4ID" -a "$PP4ID" != "0" ] && PP4CMD="`$PIDCMD $PP4ID`" BINC="qtcreator" BIND="androiddeployqt" [ "$PP4CMD" = "$BINC" -o "$PP3CMD" = "$BINC" -o "$PP2CMD" = "$BINC" ] && BUILD_BY_QTCREATOR=true [ "$PP3CMD" = "$BIND" -o "$PP2CMD" = "$BIND" -o "$PP1CMD" = "$BIND" ] && BUILD_BY_ANDROIDDEPLOYQT=true # Qt gradle caching - use for all Qt builds [ -n "$BUILD_BY_ANDROIDDEPLOYQT" ] && { export GRADLE_USER_HOME="`readlink -f $APP_HOME/../../.gradle`" [ -d "$GRADLE_USER_HOME" ] || mkdir "$GRADLE_USER_HOME" }
This change make Gradle builds using QtCreator put all Gradle caching etc on the same level as the shadow build folders, but GRADLE_USER_HOME could be set anywhere fixed as e.g. ~/Qt/.gradle, ~/Qt/Tools/QtCreator/.gradle or just use the default ~/.gradle location. The latter interferes somewhat with Android Studio, so some users using QtCreator and Android Studio on the same project workspace report build problems concerning Gradle versions. For developers with project Java files in $$PWD/android/src/ this might be an issue.
The recommended way for Gradle builds is to include the gradlew scripts as well as the gradle/wrapper/ folder in version control - see:
Version controlling the build toolchain also makes sense for continuous integration (CI) and for having reproducable builds. Docker images makes that even more robust... although the Google Android Sdk calls home to check the license key - so the same license key as used by someone accepting license agreement should be used in such images.
For making this the default for new QtCreator projects with a Qt installation, put the gradlew scripts and wrapper/gradle-wrapper.* into e.g ~/Qt/5.8/android_armv7/src/android/templates/.
Also remember an important $$PWD/android/.gitignore with:
gradle.properties local.properties gradle-app.setting
Looking forward to more native mobile goodies and bundle size trimming with Qt 5.9 - especially cool if using Android fragments, mixing native surfaces could become a bit more straigthforward using Qt. taipan, also holding the candle for Android NDK clang and newer NDK version support in 5.9. Hope you can continue the Android episodes for more native stuff like fragments, surfaces or sensors etc in QML. Great stuff!