2021-08-24 10:18:20 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
COLOR_RED="\e[1;31m"
|
|
|
|
COLOR_RESET="\e[0m"
|
|
|
|
|
|
|
|
if [ -z ${1+x} ]; then
|
|
|
|
printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass APK name to build script"
|
2021-08-24 10:18:20 +00:00
|
|
|
exit 1
|
2024-05-17 20:22:08 +00:00
|
|
|
fi
|
2021-08-24 10:18:20 +00:00
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
if [ -z ${2+x} ]; then
|
|
|
|
printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass package name to build script"
|
2021-08-24 10:18:20 +00:00
|
|
|
exit 1
|
2024-05-17 20:22:08 +00:00
|
|
|
fi
|
2021-08-24 10:18:20 +00:00
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
if [ -z ${3+x} ]; then
|
|
|
|
printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass build type to build script: Debug, Release"
|
2021-08-24 10:18:20 +00:00
|
|
|
exit 1
|
2024-05-17 20:22:08 +00:00
|
|
|
fi
|
2021-08-24 10:18:20 +00:00
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
APK_BASENAME="$1"
|
|
|
|
APK_PACKAGE_NAME="$2"
|
|
|
|
APK_BUILD_TYPE="$3"
|
2021-08-24 10:18:20 +00:00
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
if [[ "${APK_BUILD_TYPE}" == "Debug" ]]; then
|
|
|
|
RELEASE_TYPE_NAME=debug
|
|
|
|
elif [[ "${APK_BUILD_TYPE}" == "Release" ]]; then
|
|
|
|
RELEASE_TYPE_NAME=release
|
2024-05-11 16:34:42 +00:00
|
|
|
else
|
2024-05-17 20:22:08 +00:00
|
|
|
printf "${COLOR_RED}%s${COLOR_RESET}\n" "Did not pass build type to build script: Debug, Release"
|
2024-05-11 16:34:42 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
APK_PACKAGE_FOLDER=$(echo "$APK_PACKAGE_NAME" | sed 's/\./\//g')
|
2021-08-24 10:18:20 +00:00
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
sed -i "s/DDNet/${APK_BASENAME}/g" settings.gradle
|
2021-08-24 10:18:20 +00:00
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
sed -i "s/org.ddnet.client/${APK_PACKAGE_NAME}/g" build.gradle
|
2021-08-24 10:18:20 +00:00
|
|
|
|
2024-05-23 00:03:03 +00:00
|
|
|
TW_KEY_NAME_ESCAPED=$(echo "$TW_KEY_NAME" | sed 's/\//\\\//g')
|
|
|
|
TW_KEY_PW_ESCAPED=$(echo "$TW_KEY_PW" | sed 's/\//\\\//g')
|
|
|
|
TW_KEY_ALIAS_ESCAPED=$(echo "$TW_KEY_ALIAS" | sed 's/\//\\\//g')
|
2021-08-24 10:18:20 +00:00
|
|
|
|
|
|
|
sed -i "s/TW_KEY_NAME/${TW_KEY_NAME_ESCAPED}/g" build.gradle
|
|
|
|
sed -i "s/TW_KEY_PW/${TW_KEY_PW_ESCAPED}/g" build.gradle
|
|
|
|
sed -i "s/TW_KEY_ALIAS/${TW_KEY_ALIAS_ESCAPED}/g" build.gradle
|
|
|
|
|
|
|
|
sed -i "s/TW_NDK_VERSION/${ANDROID_NDK_VERSION}/g" build.gradle
|
|
|
|
sed -i "s/TW_VERSION_CODE/${TW_VERSION_CODE}/g" build.gradle
|
|
|
|
sed -i "s/TW_VERSION_NAME/${TW_VERSION_NAME}/g" build.gradle
|
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
sed -i "s/DDNet/${APK_BASENAME}/g" src/main/res/values/strings.xml
|
2024-05-09 09:52:37 +00:00
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
sed -i "s/\"DDNet\"/\"${APK_BASENAME}\"/g" src/main/AndroidManifest.xml
|
|
|
|
sed -i "s/org.ddnet.client/${APK_PACKAGE_NAME}/g" src/main/AndroidManifest.xml
|
2024-05-09 09:52:37 +00:00
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
if [ "${APK_PACKAGE_FOLDER}" != "org/ddnet/client" ]; then
|
|
|
|
mv src/main/java/org/ddnet/client src/main/java/"${APK_PACKAGE_FOLDER}"
|
|
|
|
fi
|
2021-08-24 10:18:20 +00:00
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
sed -i "s/org.ddnet.client/${APK_PACKAGE_NAME}/g" src/main/java/"${APK_PACKAGE_FOLDER}"/NativeMain.java
|
|
|
|
sed -i "s/org.ddnet.client/${APK_PACKAGE_NAME}/g" proguard-rules.pro
|
2021-08-24 10:18:20 +00:00
|
|
|
|
|
|
|
# disable hid manager for now
|
|
|
|
sed -i "s/mHIDDeviceManager = HIDDeviceManager.acquire(this);/mHIDDeviceManager=null;/g" src/main/java/org/libsdl/app/SDLActivity.java
|
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
if [[ "${APK_BUILD_TYPE}" == "Debug" ]]; then
|
2021-08-24 10:18:20 +00:00
|
|
|
sed -i "s/android.enableR8.fullMode=true/android.enableR8.fullMode=false/g" gradle.properties
|
|
|
|
fi
|
|
|
|
|
2024-05-11 16:29:46 +00:00
|
|
|
function build_gradle() {
|
|
|
|
java "-Dorg.gradle.appname=Gradle" -classpath gradle-wrapper.jar org.gradle.wrapper.GradleWrapperMain --warning-mode all "$1"
|
|
|
|
}
|
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
if [[ "${APK_BUILD_TYPE}" == "Debug" ]]; then
|
2024-05-11 16:29:46 +00:00
|
|
|
build_gradle builddebug
|
|
|
|
build_gradle assembleDebug
|
2024-05-11 16:26:39 +00:00
|
|
|
else
|
2024-05-11 16:29:46 +00:00
|
|
|
build_gradle buildrelease
|
|
|
|
build_gradle assembleRelease
|
2024-05-11 16:26:39 +00:00
|
|
|
fi
|
2024-05-17 20:22:08 +00:00
|
|
|
cp build/outputs/apk/"$RELEASE_TYPE_NAME"/"$APK_BASENAME"-"$RELEASE_TYPE_NAME".apk "$APK_BASENAME".apk
|
2024-05-11 16:26:39 +00:00
|
|
|
|
2024-05-17 20:22:08 +00:00
|
|
|
if [[ "${APK_BUILD_TYPE}" == "Release" ]]; then
|
2024-05-11 16:29:46 +00:00
|
|
|
build_gradle bundleRelease
|
2024-05-17 20:22:08 +00:00
|
|
|
cp build/outputs/bundle/"$RELEASE_TYPE_NAME"/"$APK_BASENAME"-"$RELEASE_TYPE_NAME".aab "$APK_BASENAME".aab
|
2021-08-24 10:18:20 +00:00
|
|
|
fi
|