-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathverify.sh
More file actions
executable file
·181 lines (158 loc) · 4.88 KB
/
verify.sh
File metadata and controls
executable file
·181 lines (158 loc) · 4.88 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
set -e
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT_DIR"
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
echo "=========================================="
echo " Android Packer Verification Script"
echo "=========================================="
# 1. Check Rust
if [ -f "$HOME/.cargo/env" ]; then
source "$HOME/.cargo/env"
fi
if ! command -v cargo &> /dev/null; then
echo -e "${RED}[FAIL] Rust (cargo) is not installed.${NC}"
echo "Please install Rust: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
exit 1
else
echo -e "${GREEN}[OK] Rust is installed.$(cargo --version)${NC}"
fi
# 2. Check Android NDK targets
echo "Checking Android targets..."
TARGETS=$(rustup target list --installed)
REQUIRED_TARGETS=(
"aarch64-linux-android"
"armv7-linux-androideabi"
"x86_64-linux-android"
)
MISSING_TARGETS=()
for target in "${REQUIRED_TARGETS[@]}"; do
if [[ $TARGETS != *"$target"* ]]; then
MISSING_TARGETS+=("$target")
fi
done
if [ ${#MISSING_TARGETS[@]} -eq 0 ]; then
echo -e "${GREEN}[OK] Android targets installed.${NC}"
else
echo -e "${RED}[FAIL] Android targets missing: ${MISSING_TARGETS[*]}${NC}"
echo "Please run: rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android"
exit 1
fi
# 3. Check cargo-ndk
if ! command -v cargo-ndk &> /dev/null; then
echo -e "${RED}[FAIL] cargo-ndk is not installed.${NC}"
echo "Please run: cargo install cargo-ndk"
exit 1
fi
# 3.1 Check apktool
if ! command -v apktool &> /dev/null; then
echo -e "${RED}[WARN] apktool is not installed.${NC}"
echo "pack.py can auto-download apktool jar fallback if java is available."
else
echo -e "${GREEN}[OK] apktool is installed.${NC}"
fi
# 3.2 Check apksigner
if ! command -v apksigner &> /dev/null; then
echo -e "${RED}[WARN] apksigner is not in PATH.${NC}"
echo "pack.py will try Android SDK build-tools auto-discovery."
else
echo -e "${GREEN}[OK] apksigner is installed.${NC}"
fi
# 3.3 Check zipalign (recommended)
if ! command -v zipalign &> /dev/null; then
echo -e "${RED}[WARN] zipalign is not installed.${NC}"
echo "Install Android build-tools for better APK alignment compatibility."
else
echo -e "${GREEN}[OK] zipalign is installed.${NC}"
fi
# 4. Check Gradle (or Wrapper)
if [ ! -f "loader/gradlew" ]; then
echo -e "${RED}[WARN] Gradle Wrapper not found.${NC}"
echo "Generating Gradle Wrapper..."
# Try to use local gradle if available
if command -v gradle &> /dev/null; then
cd loader
gradle wrapper
cd ..
else
echo -e "${RED}[FAIL] Gradle not found. Cannot generate wrapper.${NC}"
echo "Please install Gradle or Android Studio."
exit 1
fi
fi
# 5. Build Packer
echo "Building Packer..."
cd packer
cargo build --release
if [ $? -eq 0 ]; then
echo -e "${GREEN}[OK] Packer built successfully.${NC}"
else
echo -e "${RED}[FAIL] Packer build failed.${NC}"
exit 1
fi
cd ..
# 6. Build Shell
echo "Ensuring NDK is installed..."
cd loader
if [ -f "./gradlew" ]; then
CMD="./gradlew"
else
CMD="gradle"
fi
# Trigger NDK install (tasks that need NDK but don't fail if we don't have sources yet? actually any task might verify NDK)
# 'dependencies' task usually triggers SDK/NDK checks if configured.
$CMD -q dependencies > /dev/null 2>&1 || true
cd ..
echo "Building Android Shell (Native)..."
cd loader/app/src/main/rust
# Ensure env vars are set
if [ -z "$ANDROID_NDK_HOME" ]; then
echo -e "${RED}[WARN] ANDROID_NDK_HOME is not set.${NC}"
# Try standard MacOS path
POSSIBLE_PATHS=(
"$HOME/Library/Android/sdk/ndk"
"${ANDROID_HOME}/ndk"
"${ANDROID_SDK_ROOT}/ndk"
"/usr/local/lib/android/sdk/ndk"
)
for SDK_NDK_DIR in "${POSSIBLE_PATHS[@]}"; do
if [ -d "$SDK_NDK_DIR" ]; then
# Pick the latest version
LATEST_NDK=$(ls -d "$SDK_NDK_DIR"/* | sort -V | tail -n 1)
if [ -d "$LATEST_NDK" ]; then
export ANDROID_NDK_HOME="$LATEST_NDK"
echo "Using detected NDK: $ANDROID_NDK_HOME"
break
fi
fi
done
fi
if [ -z "$ANDROID_NDK_HOME" ]; then
echo -e "${RED}[FAIL] Could not detect ANDROID_NDK_HOME. Please set it manually.${NC}"
exit 1
fi
cargo ndk -t arm64-v8a -t armeabi-v7a -t x86_64 -o ../jniLibs build --release
if [ $? -ne 0 ]; then
echo -e "${RED}[FAIL] Cargo NDK build failed.${NC}"
exit 1
fi
cd "$ROOT_DIR"
echo "Building Android Shell (APK)..."
cd loader
if [ -f "./gradlew" ]; then
CMD="./gradlew"
else
echo -e "${RED}[WARN] ./gradlew not found. Using system gradle.${NC}"
CMD="gradle"
fi
$CMD assembleRelease
if [ $? -eq 0 ]; then
echo -e "${GREEN}[OK] Android Shell built successfully.${NC}"
else
echo -e "${RED}[FAIL] Android Shell build failed.${NC}"
exit 1
fi
cd ..
echo -e "${GREEN}All verification steps passed!${NC}"