-
Notifications
You must be signed in to change notification settings - Fork 21
/
buildsource
executable file
·72 lines (52 loc) · 1.97 KB
/
buildsource
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
[ -z "$JAVA_PATH" ] && JAVA_PATH=java
[ -z "$JAVAC_PATH" ] && JAVAC_PATH=javac
[ -z "$ANDROID_SDK_ROOT" ] && ANDROID_SDK_ROOT=~/Android/Sdk
[ -z "$BAKSMALI_PATH" ] && BAKSMALI_PATH=/opt/baksmali/baksmali-2.4.0.jar
[ -z "$1" ] && TARGETDIR=extracted || TARGETDIR=$1
[ -z "$BUILD_COMPANION" ] && BUILD_COMPANION=/opt/build-companion
echo "JAVA_PATH: $JAVA_PATH"
echo "JAVAC_PATH: $JAVAC_PATH"
echo "BAKSMALI_PATH: $BAKSMALI_PATH"
echo "TARGETDIR: $TARGETDIR"
echo "ANDROID_SDK_ROOT: $ANDROID_SDK_ROOT"
echo "BUILD_COMPANION: $BUILD_COMPANION"
export ANDROID_SDK_ROOT
# build mod
cd mod
bash gradlew assemble
# fail if failed
[ $? = 0 ] || exit 1
# contants
TMP_DIR=app/build/.bttv_tmp
CONSUMER_APK=consumer/build/outputs/apk/release/consumer-release-unsigned.apk
DEX_FILE="$TMP_DIR/classes.dex"
FINAL_TARGET="../$TARGETDIR/smali_classes9"
RES_DIR="app/src/main/res"
RES_TARGET="../$TARGETDIR/res"
LIB_DIR="$TMP_DIR/lib"
LIB_TARGET="../$TARGETDIR/lib"
# extract classes
unzip -o "$CONSUMER_APK" "classes.dex" "lib/**/*" -d "$TMP_DIR"
# baksmali .dex file
$JAVA_PATH -jar $BAKSMALI_PATH d -o "$TMP_DIR" "$DEX_FILE"
# replace BTTVDefaultConstructorMarker with DefaultConstructorMarker
find "$TMP_DIR/bttv" -type f -exec sed -i -e 's/BTTVDefaultConstructorMarker/DefaultConstructorMarker/g' {} \;
# remove dir if already exists
mkdir -p "$FINAL_TARGET/bttv"
rm -rf "$FINAL_TARGET/bttv"
rm -rf "$FINAL_TARGET/com"
# move to target
mv "$TMP_DIR/bttv" "$FINAL_TARGET/."
mv "$TMP_DIR/com" "$FINAL_TARGET/."
rsync -ar --ignore-existing "$TMP_DIR/androidx/" "../$TARGETDIR/smali_classes9/androidx/"
# copy res
ls "$RES_DIR" -1 | grep -v values | xargs -i cp -R "$RES_DIR/{}" "$RES_TARGET"
ls "$LIB_DIR" -1 | xargs -i cp -r "$LIB_DIR/{}" "$LIB_TARGET"
# copy contributors
rm -f "../$TARGETDIR/assets/bttv_contributors.json"
cp "../.all-contributorsrc" "../$TARGETDIR/assets/bttv_contributors.json"
# add strings
$BUILD_COMPANION strings "$RES_DIR" "$RES_TARGET"
# remove temp dir
rm -rf "$TMP_DIR"