build-android.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/sh
  2. basedir="$(dirname "$0")"
  3. [ "$(echo "$basedir" | cut -c1)" = '/' ] || basedir="$PWD/$basedir"
  4. project="timeshift"
  5. builddir="$basedir/build-android"
  6. appbuilddir="$builddir/app"
  7. venvdir="$builddir/venv"
  8. sysrootdir="$builddir/sysroot"
  9. sysrootconfig="$basedir/sysroot.json"
  10. plugindir="$basedir/sysroot-plugins"
  11. sourcedir="$basedir/sources"
  12. qtinstalldir="$HOME/Qt/5.12.2"
  13. target="android-32"
  14. export ANDROID_NDK_PLATFORM=android-21
  15. export ANDROID_NDK_ROOT="$HOME/Android/Sdk/ndk-bundle"
  16. export ANDROID_SDK_ROOT="$HOME/Android/Sdk"
  17. die()
  18. {
  19. echo "$*" >&2
  20. exit 1
  21. }
  22. info()
  23. {
  24. echo "--- $*"
  25. }
  26. mkdir -p "$builddir" || die "Failed to create builddir."
  27. if ! [ -d "$venvdir" ]; then
  28. virtualenv "$venvdir" || die "Failed to create virtualenv."
  29. fi
  30. (
  31. info "Setting up virtualenv"
  32. . "$venvdir/bin/activate" || die "Failed to activate virtualenv."
  33. pip3 install pyqtdeploy || die "Failed to install pyqtdeploy."
  34. pip3 install PyQt5 || die "Failed to install PyQt5."
  35. info "Building sysroot"
  36. if ! [ -d "$sysrootdir" ]; then
  37. mkdir -p "$sysrootdir" || die "Failed to create sysrootdir."
  38. pyqtdeploy-sysroot \
  39. --target "$target" \
  40. --sysroot "$sysrootdir" \
  41. --source-dir "$sourcedir" \
  42. --source-dir "$qtinstalldir" \
  43. --plugin-dir "$plugindir" \
  44. "$sysrootconfig" ||\
  45. die "Failed to build sysroot."
  46. fi
  47. info "App pyqtdeploy"
  48. rm -rf "$appbuilddir"
  49. pyqtdeploy-build \
  50. --target "$target" \
  51. --sysroot "$sysrootdir" \
  52. --build-dir "$appbuilddir" \
  53. "$project.pdy" ||\
  54. die "Failed to pyqtdeploy-build."
  55. cd "$appbuilddir" || die "Failed to enter appbuilddir."
  56. info "Building app"
  57. "$sysrootdir/host/bin/qmake" || die "qmake failed."
  58. make || die "make failed."
  59. make INSTALL_ROOT="$project" install || die "make install failed."
  60. "$sysrootdir/host/bin/androiddeployqt" \
  61. --gradle \
  62. --input "android-lib$project.so-deployment-settings.json" \
  63. --output "$project" ||\
  64. die "androiddeployqt failed."
  65. cp "$appbuilddir/$project/build/outputs/apk/debug/$project-debug.apk" \
  66. "$basedir/$project.apk" ||\
  67. die "Failed to copy apk."
  68. echo "Android package built: $project.apk"
  69. ) || die