2020-08-27 17:00:40 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-10-29 17:46:35 +00:00
|
|
|
#
|
|
|
|
# This script generates the scrcpy binary "manually" (without gradle).
|
|
|
|
#
|
|
|
|
# Adapt Android platform and build tools versions (via ANDROID_PLATFORM and
|
|
|
|
# ANDROID_BUILD_TOOLS environment variables).
|
|
|
|
#
|
|
|
|
# Then execute:
|
|
|
|
#
|
|
|
|
# BUILD_DIR=my_build_dir ./build_without_gradle.sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2019-11-18 13:33:14 +00:00
|
|
|
SCRCPY_DEBUG=false
|
2023-07-14 16:58:58 +00:00
|
|
|
SCRCPY_VERSION_NAME=2.1.1
|
2019-11-18 13:30:21 +00:00
|
|
|
|
2022-09-02 12:41:23 +00:00
|
|
|
PLATFORM=${ANDROID_PLATFORM:-33}
|
|
|
|
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-33.0.0}
|
2022-06-10 13:19:53 +00:00
|
|
|
BUILD_TOOLS_DIR="$ANDROID_HOME/build-tools/$BUILD_TOOLS"
|
2019-10-29 17:46:35 +00:00
|
|
|
|
|
|
|
BUILD_DIR="$(realpath ${BUILD_DIR:-build_manual})"
|
|
|
|
CLASSES_DIR="$BUILD_DIR/classes"
|
2023-01-26 09:40:48 +00:00
|
|
|
GEN_DIR="$BUILD_DIR/gen"
|
2019-10-29 17:46:35 +00:00
|
|
|
SERVER_DIR=$(dirname "$0")
|
2019-10-30 22:40:10 +00:00
|
|
|
SERVER_BINARY=scrcpy-server
|
2021-11-13 23:34:12 +00:00
|
|
|
ANDROID_JAR="$ANDROID_HOME/platforms/android-$PLATFORM/android.jar"
|
2023-01-27 21:08:21 +00:00
|
|
|
LAMBDA_JAR="$BUILD_TOOLS_DIR/core-lambda-stubs.jar"
|
2019-10-29 17:46:35 +00:00
|
|
|
|
|
|
|
echo "Platform: android-$PLATFORM"
|
|
|
|
echo "Build-tools: $BUILD_TOOLS"
|
|
|
|
echo "Build dir: $BUILD_DIR"
|
|
|
|
|
2023-01-26 09:40:48 +00:00
|
|
|
rm -rf "$CLASSES_DIR" "$GEN_DIR" "$BUILD_DIR/$SERVER_BINARY" classes.dex
|
|
|
|
mkdir -p "$CLASSES_DIR"
|
|
|
|
mkdir -p "$GEN_DIR/com/genymobile/scrcpy"
|
2019-10-29 17:46:35 +00:00
|
|
|
|
2023-01-26 09:40:48 +00:00
|
|
|
<< EOF cat > "$GEN_DIR/com/genymobile/scrcpy/BuildConfig.java"
|
2019-10-29 17:46:35 +00:00
|
|
|
package com.genymobile.scrcpy;
|
|
|
|
|
|
|
|
public final class BuildConfig {
|
2019-11-18 13:33:14 +00:00
|
|
|
public static final boolean DEBUG = $SCRCPY_DEBUG;
|
2019-11-18 13:30:21 +00:00
|
|
|
public static final String VERSION_NAME = "$SCRCPY_VERSION_NAME";
|
2019-10-29 17:46:35 +00:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo "Generating java from aidl..."
|
|
|
|
cd "$SERVER_DIR/src/main/aidl"
|
2023-01-26 09:40:48 +00:00
|
|
|
"$BUILD_TOOLS_DIR/aidl" -o"$GEN_DIR" android/view/IRotationWatcher.aidl
|
|
|
|
"$BUILD_TOOLS_DIR/aidl" -o"$GEN_DIR" \
|
2020-06-06 22:02:21 +00:00
|
|
|
android/content/IOnPrimaryClipChangedListener.aidl
|
2023-06-21 21:56:06 +00:00
|
|
|
"$BUILD_TOOLS_DIR/aidl" -o"$GEN_DIR" android/view/IDisplayFoldListener.aidl
|
2019-10-29 17:46:35 +00:00
|
|
|
|
|
|
|
echo "Compiling java sources..."
|
|
|
|
cd ../java
|
2023-01-27 21:08:21 +00:00
|
|
|
javac -bootclasspath "$ANDROID_JAR" \
|
|
|
|
-cp "$LAMBDA_JAR:$GEN_DIR" \
|
|
|
|
-d "$CLASSES_DIR" \
|
2021-11-13 23:34:12 +00:00
|
|
|
-source 1.8 -target 1.8 \
|
2019-10-29 17:46:35 +00:00
|
|
|
com/genymobile/scrcpy/*.java \
|
|
|
|
com/genymobile/scrcpy/wrappers/*.java
|
|
|
|
|
|
|
|
echo "Dexing..."
|
|
|
|
cd "$CLASSES_DIR"
|
|
|
|
|
2021-12-02 19:49:35 +00:00
|
|
|
if [[ $PLATFORM -lt 31 ]]
|
2021-11-13 23:23:36 +00:00
|
|
|
then
|
|
|
|
# use dx
|
2022-06-10 13:19:53 +00:00
|
|
|
"$BUILD_TOOLS_DIR/dx" --dex --output "$BUILD_DIR/classes.dex" \
|
2021-11-13 23:23:36 +00:00
|
|
|
android/view/*.class \
|
|
|
|
android/content/*.class \
|
|
|
|
com/genymobile/scrcpy/*.class \
|
|
|
|
com/genymobile/scrcpy/wrappers/*.class
|
|
|
|
|
|
|
|
echo "Archiving..."
|
|
|
|
cd "$BUILD_DIR"
|
|
|
|
jar cvf "$SERVER_BINARY" classes.dex
|
2023-01-26 09:40:48 +00:00
|
|
|
rm -rf classes.dex
|
2021-11-13 23:23:36 +00:00
|
|
|
else
|
|
|
|
# use d8
|
2022-06-10 13:19:53 +00:00
|
|
|
"$BUILD_TOOLS_DIR/d8" --classpath "$ANDROID_JAR" \
|
2021-11-13 23:23:36 +00:00
|
|
|
--output "$BUILD_DIR/classes.zip" \
|
|
|
|
android/view/*.class \
|
|
|
|
android/content/*.class \
|
|
|
|
com/genymobile/scrcpy/*.class \
|
|
|
|
com/genymobile/scrcpy/wrappers/*.class
|
|
|
|
|
|
|
|
cd "$BUILD_DIR"
|
|
|
|
mv classes.zip "$SERVER_BINARY"
|
|
|
|
fi
|
2019-10-29 17:46:35 +00:00
|
|
|
|
2023-01-26 09:40:48 +00:00
|
|
|
rm -rf "$GEN_DIR" "$CLASSES_DIR"
|
|
|
|
|
2019-10-30 22:40:10 +00:00
|
|
|
echo "Server generated in $BUILD_DIR/$SERVER_BINARY"
|