2020-08-28 01:00:40 +08:00
|
|
|
#!/usr/bin/env bash
|
2019-10-30 01:46:35 +08: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 21:33:14 +08:00
|
|
|
SCRCPY_DEBUG=false
|
2021-11-30 05:15:28 +08:00
|
|
|
SCRCPY_VERSION_NAME=1.21
|
2019-11-18 21:30:21 +08:00
|
|
|
|
2021-12-03 03:54:23 +08:00
|
|
|
PLATFORM=${ANDROID_PLATFORM:-31}
|
2021-11-14 07:23:36 +08:00
|
|
|
BUILD_TOOLS=${ANDROID_BUILD_TOOLS:-31.0.0}
|
2019-10-30 01:46:35 +08:00
|
|
|
|
|
|
|
BUILD_DIR="$(realpath ${BUILD_DIR:-build_manual})"
|
|
|
|
CLASSES_DIR="$BUILD_DIR/classes"
|
|
|
|
SERVER_DIR=$(dirname "$0")
|
2019-10-31 06:40:10 +08:00
|
|
|
SERVER_BINARY=scrcpy-server
|
2021-11-14 07:34:12 +08:00
|
|
|
ANDROID_JAR="$ANDROID_HOME/platforms/android-$PLATFORM/android.jar"
|
2019-10-30 01:46:35 +08:00
|
|
|
|
|
|
|
echo "Platform: android-$PLATFORM"
|
|
|
|
echo "Build-tools: $BUILD_TOOLS"
|
|
|
|
echo "Build dir: $BUILD_DIR"
|
|
|
|
|
|
|
|
rm -rf "$CLASSES_DIR" "$BUILD_DIR/$SERVER_BINARY" classes.dex
|
|
|
|
mkdir -p "$CLASSES_DIR/com/genymobile/scrcpy"
|
|
|
|
|
|
|
|
<< EOF cat > "$CLASSES_DIR/com/genymobile/scrcpy/BuildConfig.java"
|
|
|
|
package com.genymobile.scrcpy;
|
|
|
|
|
|
|
|
public final class BuildConfig {
|
2019-11-18 21:33:14 +08:00
|
|
|
public static final boolean DEBUG = $SCRCPY_DEBUG;
|
2019-11-18 21:30:21 +08:00
|
|
|
public static final String VERSION_NAME = "$SCRCPY_VERSION_NAME";
|
2019-10-30 01:46:35 +08:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo "Generating java from aidl..."
|
|
|
|
cd "$SERVER_DIR/src/main/aidl"
|
2019-11-21 00:13:22 +08:00
|
|
|
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/aidl" -o"$CLASSES_DIR" \
|
2019-10-30 01:46:35 +08:00
|
|
|
android/view/IRotationWatcher.aidl
|
2020-06-07 06:02:21 +08:00
|
|
|
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/aidl" -o"$CLASSES_DIR" \
|
|
|
|
android/content/IOnPrimaryClipChangedListener.aidl
|
2019-10-30 01:46:35 +08:00
|
|
|
|
|
|
|
echo "Compiling java sources..."
|
|
|
|
cd ../java
|
2021-11-14 07:34:12 +08:00
|
|
|
javac -bootclasspath "$ANDROID_JAR" -cp "$CLASSES_DIR" -d "$CLASSES_DIR" \
|
|
|
|
-source 1.8 -target 1.8 \
|
2019-10-30 01:46:35 +08:00
|
|
|
com/genymobile/scrcpy/*.java \
|
|
|
|
com/genymobile/scrcpy/wrappers/*.java
|
|
|
|
|
|
|
|
echo "Dexing..."
|
|
|
|
cd "$CLASSES_DIR"
|
|
|
|
|
2021-12-03 03:49:35 +08:00
|
|
|
if [[ $PLATFORM -lt 31 ]]
|
2021-11-14 07:23:36 +08:00
|
|
|
then
|
|
|
|
# use dx
|
|
|
|
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/dx" --dex \
|
|
|
|
--output "$BUILD_DIR/classes.dex" \
|
|
|
|
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
|
|
|
|
rm -rf classes.dex classes
|
|
|
|
else
|
|
|
|
# use d8
|
|
|
|
"$ANDROID_HOME/build-tools/$BUILD_TOOLS/d8" --classpath "$ANDROID_JAR" \
|
|
|
|
--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"
|
|
|
|
rm -rf classes
|
|
|
|
fi
|
2019-10-30 01:46:35 +08:00
|
|
|
|
2019-10-31 06:40:10 +08:00
|
|
|
echo "Server generated in $BUILD_DIR/$SERVER_BINARY"
|