uriid1

love-android script helper

Jun 13th, 2021 (edited)
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.64 KB | None | 0 0
  1. #!/usr/bin/bash
  2.  
  3. #####************ INFO *************#####
  4. #                                       #
  5. #   By: by uriid1                       #
  6. #   Version: 1.0                        #
  7. #                                       #
  8. #####******************************######
  9.  
  10. #####************** Guide ***************************************************#####
  11. #                                                                                #
  12. #   1] Put this script in the directory with love-android                        #
  13. #   2] And put game_icon.png                                                     #
  14. #   3] Put your game.love in /app/src/main/assets/                               #
  15. #   4] Configure variables game_name, version_code...                            #
  16. #   5] Specify environment Variables ANDROID_HOME and ANDROID_NDK_HOME           #
  17. #   6] Run the script ./build.bash                                               #
  18. #                                                                                #
  19. #####************************************************************************#####
  20.  
  21. ############### SETUP ###################
  22. # Package
  23. icon="icon.png";                # Icon must be in the current directory, like the script itself.
  24. game_name="Super Game";         # Name of your cool game. :)
  25. version_code=1;                 # Application version relative to other versions.
  26. version_name=0.5.0;             # The version of the application that users will use.
  27. screen_orientation="portrait";  # portrait  or landscape.
  28.  
  29. # Export env. (Environment Variables)
  30. export ANDROID_HOME=/home/uriid1/Android/Sdk/
  31. export ANDROID_NDK_HOME=/home/uriid1/Android/Sdk/ndk/21.3.6528147/
  32.  
  33. # Application ID
  34. tmp_app_id=$(printf "$game_name" | sed s/' '//g);
  35. app_id="com.$tmp_app_id.android";
  36.  
  37.  
  38. ########### Assembly Process ############
  39. # Const
  40. readonly version="1.0";
  41. readonly c_error='\033[5m';
  42. readonly c_yellow='\033[33m';
  43. readonly c_red='\033[31m';
  44. readonly c_green='\033[32m';
  45. readonly c_def='\033[0m';
  46. readonly bold='\033[1m';
  47.  
  48. # info
  49. printf "\n";
  50. printf "${c_green} Build Info: ${c_def} \n";
  51. (
  52. if [ -f $icon ]; then
  53.     printf "  + ${c_green} icon: ${c_def} | ${c_yellow} $icon ${c_def} \n";
  54. else
  55.     printf "  - ${c_green} icon: ${c_def} | ${c_red} $icon ${c_def} \n";
  56. fi;
  57. printf "  + ${c_green} game name: ${c_def} | ${c_yellow} $game_name  ${c_def} \n";
  58. printf "  + ${c_green} app id: ${c_def} | ${c_yellow} $app_id  ${c_def} \n";
  59. printf "  + ${c_green} version code: ${c_def} | ${c_yellow} $version_code ${c_def} \n";
  60. printf "  + ${c_green} version name: ${c_def} | ${c_yellow} $version_name ${c_def} \n";
  61. printf "  + ${c_green} screen orientation: ${c_def} | ${c_yellow} $screen_orientation ${c_def} \n";
  62. ) | column -t -s '|';
  63. printf "\n";
  64.  
  65. # Set config for build.gradle ( '"''text''"' -> "text" )
  66. printf "Set config for build.gradle \n";
  67. sed -i 's/applicationId.*/applicationId'' "'"$app_id"'"''/' app/build.gradle        # applicationId
  68. sed -i 's/versionCode.*/versionCode'" $version_code"'/' app/build.gradle            # versionCode
  69. sed -i 's/versionName.*/versionName'' "'"$version_name"'"''/' app/build.gradle      # versionName
  70.  
  71. # Set conf for AndroidManifest
  72. printf "Set config for AndroidManifest \n";
  73. sed -i 's/screenOrientation.*/screenOrientation=''"'"$screen_orientation"'"''/' app/src/main/AndroidManifest.xml    # screenOrientation
  74. sed -i 's/label.*/label=''"'"$game_name"'"''/' app/src/main/AndroidManifest.xml                                     # android:label
  75.  
  76. # Converting icon
  77. if [ -f $icon ]; then
  78.     printf "Converting icon. \n";
  79.     convert $icon -resize 42 app/src/main/res/drawable-mdpi/love.png        # 42x42
  80.     convert $icon -resize 72 app/src/main/res/drawable-hdpi/love.png        # 72x72
  81.     convert $icon -resize 96 app/src/main/res/drawable-xhdpi/love.png       # 96x96
  82.     convert $icon -resize 144 app/src/main/res/drawable-xxhdpi/love.png     # 144x144
  83.     convert $icon -resize 192 app/src/main/res/drawable-xxxhdpi/love.png    # 192x192
  84. else
  85.     printf "${c_error}No icon file in this directory :( ${c_def} \n";
  86. fi
  87. printf "\n";
  88.  
  89. # Build APK ( debug )
  90. rm -f app/build/outputs/apk/debug/app-debug.apk
  91. printf "Build... \n";
  92.  
  93. # For APK
  94. # bash gradlew assembleRelease
  95. # bash gradlew assembleEmbedRelease
  96. bash gradlew assembleDebug
  97.  
  98. # For AAB
  99. # bash gradlew bundleEmbed
  100.  
  101. printf "\n";
  102.  
  103. # If the apk was not built successfully
  104. if ! [ -f app/build/outputs/apk/debug/app-debug.apk ]; then
  105.     exit 0;
  106. fi
  107.  
  108. # Copy app-debug.apk and rename to game_name.apk
  109. if ! [ -d builds_apk ]; then
  110.     printf "Create folder builds_apk \n";
  111.     mkdir builds_apk
  112. fi
  113.  
  114. # Copy APK
  115. apk_name=$(printf "$game_name" | sed s/' '/_/g);
  116. apk_name_to_cp="$apk_name""_($version_name)"".apk";
  117. cp -u app/build/outputs/apk/debug/app-debug.apk builds_apk/$apk_name_to_cp
  118.  
  119. # If apk exists
  120. if [ -f builds_apk/$apk_name_to_cp ]; then
  121.     printf "${c_green}${bold}APK COPY SUCCESS! ${c_def} \n";
  122. else
  123.     printf "${c_error}${bold}ERROR COPY APK. ${c_def} \n";
  124. fi
  125.  
  126. # For adb installation
  127. case $1 in
  128.     -a | --adb)
  129.         printf "Adb installation run. \n";
  130.         adb install builds_apk/"$apk_name""_($version_name)".apk
  131.     ;;
  132. esac
  133. printf "\n";
Add Comment
Please, Sign In to add comment