Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/bash
- #####************ INFO *************#####
- # #
- # By: by uriid1 #
- # Version: 1.0 #
- # #
- #####******************************######
- #####************** Guide ***************************************************#####
- # #
- # 1] Put this script in the directory with love-android #
- # 2] And put game_icon.png #
- # 3] Put your game.love in /app/src/main/assets/ #
- # 4] Configure variables game_name, version_code... #
- # 5] Specify environment Variables ANDROID_HOME and ANDROID_NDK_HOME #
- # 6] Run the script ./build.bash #
- # #
- #####************************************************************************#####
- ############### SETUP ###################
- # Package
- icon="icon.png"; # Icon must be in the current directory, like the script itself.
- game_name="Super Game"; # Name of your cool game. :)
- version_code=1; # Application version relative to other versions.
- version_name=0.5.0; # The version of the application that users will use.
- screen_orientation="portrait"; # portrait or landscape.
- # Export env. (Environment Variables)
- export ANDROID_HOME=/home/uriid1/Android/Sdk/
- export ANDROID_NDK_HOME=/home/uriid1/Android/Sdk/ndk/21.3.6528147/
- # Application ID
- tmp_app_id=$(printf "$game_name" | sed s/' '//g);
- app_id="com.$tmp_app_id.android";
- ########### Assembly Process ############
- # Const
- readonly version="1.0";
- readonly c_error='\033[5m';
- readonly c_yellow='\033[33m';
- readonly c_red='\033[31m';
- readonly c_green='\033[32m';
- readonly c_def='\033[0m';
- readonly bold='\033[1m';
- # info
- printf "\n";
- printf "${c_green} Build Info: ${c_def} \n";
- (
- if [ -f $icon ]; then
- printf " + ${c_green} icon: ${c_def} | ${c_yellow} $icon ${c_def} \n";
- else
- printf " - ${c_green} icon: ${c_def} | ${c_red} $icon ${c_def} \n";
- fi;
- printf " + ${c_green} game name: ${c_def} | ${c_yellow} $game_name ${c_def} \n";
- printf " + ${c_green} app id: ${c_def} | ${c_yellow} $app_id ${c_def} \n";
- printf " + ${c_green} version code: ${c_def} | ${c_yellow} $version_code ${c_def} \n";
- printf " + ${c_green} version name: ${c_def} | ${c_yellow} $version_name ${c_def} \n";
- printf " + ${c_green} screen orientation: ${c_def} | ${c_yellow} $screen_orientation ${c_def} \n";
- ) | column -t -s '|';
- printf "\n";
- # Set config for build.gradle ( '"''text''"' -> "text" )
- printf "Set config for build.gradle \n";
- sed -i 's/applicationId.*/applicationId'' "'"$app_id"'"''/' app/build.gradle # applicationId
- sed -i 's/versionCode.*/versionCode'" $version_code"'/' app/build.gradle # versionCode
- sed -i 's/versionName.*/versionName'' "'"$version_name"'"''/' app/build.gradle # versionName
- # Set conf for AndroidManifest
- printf "Set config for AndroidManifest \n";
- sed -i 's/screenOrientation.*/screenOrientation=''"'"$screen_orientation"'"''/' app/src/main/AndroidManifest.xml # screenOrientation
- sed -i 's/label.*/label=''"'"$game_name"'"''/' app/src/main/AndroidManifest.xml # android:label
- # Converting icon
- if [ -f $icon ]; then
- printf "Converting icon. \n";
- convert $icon -resize 42 app/src/main/res/drawable-mdpi/love.png # 42x42
- convert $icon -resize 72 app/src/main/res/drawable-hdpi/love.png # 72x72
- convert $icon -resize 96 app/src/main/res/drawable-xhdpi/love.png # 96x96
- convert $icon -resize 144 app/src/main/res/drawable-xxhdpi/love.png # 144x144
- convert $icon -resize 192 app/src/main/res/drawable-xxxhdpi/love.png # 192x192
- else
- printf "${c_error}No icon file in this directory :( ${c_def} \n";
- fi
- printf "\n";
- # Build APK ( debug )
- rm -f app/build/outputs/apk/debug/app-debug.apk
- printf "Build... \n";
- # For APK
- # bash gradlew assembleRelease
- # bash gradlew assembleEmbedRelease
- bash gradlew assembleDebug
- # For AAB
- # bash gradlew bundleEmbed
- printf "\n";
- # If the apk was not built successfully
- if ! [ -f app/build/outputs/apk/debug/app-debug.apk ]; then
- exit 0;
- fi
- # Copy app-debug.apk and rename to game_name.apk
- if ! [ -d builds_apk ]; then
- printf "Create folder builds_apk \n";
- mkdir builds_apk
- fi
- # Copy APK
- apk_name=$(printf "$game_name" | sed s/' '/_/g);
- apk_name_to_cp="$apk_name""_($version_name)"".apk";
- cp -u app/build/outputs/apk/debug/app-debug.apk builds_apk/$apk_name_to_cp
- # If apk exists
- if [ -f builds_apk/$apk_name_to_cp ]; then
- printf "${c_green}${bold}APK COPY SUCCESS! ${c_def} \n";
- else
- printf "${c_error}${bold}ERROR COPY APK. ${c_def} \n";
- fi
- # For adb installation
- case $1 in
- -a | --adb)
- printf "Adb installation run. \n";
- adb install builds_apk/"$apk_name""_($version_name)".apk
- ;;
- esac
- printf "\n";
Add Comment
Please, Sign In to add comment