Skip to content

Commit 2314406

Browse files
committed
Add optional --output flag to both iOS and Android build scripts
1 parent b8c6ba8 commit 2314406

File tree

4 files changed

+94
-7
lines changed

4 files changed

+94
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ Thumbs.db
2727
# Native libs built locally
2828
libbdkffi.*
2929
android/libs
30+
bdk_demo/android/app/src/main/jniLibs
3031
ios/Release/
31-
bdk_demo/ios/ios/Release/
32+
bdk_demo/ios/ios/
3233
test_output.txt
3334
test output.txt
3435
lib/bdk.dart

lib/README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ scripts in `scripts/`.
2222
```bash
2323
./scripts/build-ios-xcframework.sh
2424
```
25-
The framework is written to `ios/Release/bdkffi.xcframework/`.
25+
The framework is written to `ios/Release/bdkffi.xcframework/`. Keep it there to
26+
reuse across multiple apps, or direct the output into a Flutter project with the
27+
optional flag:
28+
29+
```bash
30+
./scripts/build-ios-xcframework.sh --output bdk_demo/ios/ios
31+
```
2632

2733
### Android (.so libraries)
2834

@@ -42,12 +48,21 @@ scripts in `scripts/`.
4248
```
4349
3. Stage the artifacts for inclusion in a Flutter project (make script executable or run with `bash`):
4450
```bash
45-
chmod +x scripts/build-android.sh
51+
chmod +x scripts/build-android.sh
4652
./scripts/build-android.sh
47-
# or
53+
# or
4854
bash ./scripts/build-android.sh
4955
```
50-
Output libraries are copied to `android/libs/<abi>/libbdkffi.so`.
56+
57+
By default the script stages artifacts in `android/libs/<abi>/libbdkffi.so` so the same
58+
slices can be reused across multiple apps; direct them into the demo’s `jniLibs`
59+
by passing `--output` as shown below.
60+
61+
```bash
62+
chmod +x scripts/build-android.sh
63+
./scripts/build-android.sh --output bdk_demo/android/app/src/main/jniLibs
64+
# or, without changing permissions
65+
bash ./scripts/build-android.sh --output bdk_demo/android/app/src/main/jniLibs
5166
5267
### Desktop tests (macOS/Linux)
5368

scripts/build-android.sh

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,42 @@ set -euo pipefail
44
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
55
PROJECT_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
66
ANDROID_BUILD_ROOT="$PROJECT_ROOT/build/android"
7-
OUTPUT_ROOT="$PROJECT_ROOT/android/libs"
7+
OUTPUT_ROOT="android/libs"
8+
9+
usage() {
10+
cat <<EOF
11+
Usage: $(basename "$0") [--output <dir>]
12+
13+
Copy the built Android shared libraries into <dir>. When <dir> is relative,
14+
it is resolved from the repository root. Defaults to android/libs.
15+
EOF
16+
}
17+
18+
while [[ $# -gt 0 ]]; do
19+
case "$1" in
20+
--output|-o)
21+
OUTPUT_ROOT="${2:-}"
22+
if [[ -z "$OUTPUT_ROOT" ]]; then
23+
echo "Error: --output requires a value" >&2
24+
exit 1
25+
fi
26+
shift 2
27+
;;
28+
--help|-h)
29+
usage
30+
exit 0
31+
;;
32+
*)
33+
echo "Unknown option: $1" >&2
34+
usage >&2
35+
exit 1
36+
;;
37+
esac
38+
done
39+
40+
if [[ "$OUTPUT_ROOT" != /* ]]; then
41+
OUTPUT_ROOT="$PROJECT_ROOT/$OUTPUT_ROOT"
42+
fi
843

944
if [[ -z "${ANDROID_NDK_ROOT:-}" ]]; then
1045
echo "ANDROID_NDK_ROOT must be set" >&2

scripts/build-ios-xcframework.sh

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
55
PROJECT_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
66
IOS_BUILD_ROOT="$PROJECT_ROOT/build/ios"
7-
OUTPUT_ROOT="$PROJECT_ROOT/ios/Release"
7+
OUTPUT_ROOT="ios/Release"
88
XCFRAMEWORK_NAME="bdkffi.xcframework"
99

1010
DEVICE_LIB="$IOS_BUILD_ROOT/aarch64-apple-ios/libbdkffi.a"
@@ -13,6 +13,42 @@ SIM_X86_LIB="$IOS_BUILD_ROOT/x86_64-apple-ios/libbdkffi.a"
1313
SIM_UNIVERSAL_DIR="$IOS_BUILD_ROOT/simulator-universal"
1414
SIM_UNIVERSAL_LIB="$SIM_UNIVERSAL_DIR/libbdkffi.a"
1515

16+
usage() {
17+
cat <<EOF
18+
Usage: $(basename "$0") [--output <dir>]
19+
20+
Create an XCFramework from previously built static libraries and write it to
21+
<dir>. When <dir> is relative, it is resolved from the repository root.
22+
Defaults to ios/Release.
23+
EOF
24+
}
25+
26+
while [[ $# -gt 0 ]]; do
27+
case "$1" in
28+
--output|-o)
29+
OUTPUT_ROOT="${2:-}"
30+
if [[ -z "$OUTPUT_ROOT" ]]; then
31+
echo "Error: --output requires a value" >&2
32+
exit 1
33+
fi
34+
shift 2
35+
;;
36+
--help|-h)
37+
usage
38+
exit 0
39+
;;
40+
*)
41+
echo "Unknown option: $1" >&2
42+
usage >&2
43+
exit 1
44+
;;
45+
esac
46+
done
47+
48+
if [[ "$OUTPUT_ROOT" != /* ]]; then
49+
OUTPUT_ROOT="$PROJECT_ROOT/$OUTPUT_ROOT"
50+
fi
51+
1652
if [[ ! -f "$DEVICE_LIB" ]]; then
1753
echo "Missing device library: $DEVICE_LIB" >&2
1854
echo "Run scripts/generate_bindings.sh --target ios first." >&2

0 commit comments

Comments
 (0)