Skip to content

Commit 3d51f2b

Browse files
committed
build: fix android build
1 parent ae83723 commit 3d51f2b

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ checks that run every night at 2:00 AM (UTC) on the `main` branch.
206206

207207
## TODO
208208

209-
- Use standard actions/upload-pages-artifact@v4.0.0 to deploy to Pages
210209
- DRY E2E tests to only one par user story, they can still runFlow others
211210
- Mock exercise database with public/exercises.json for E2E tests, so they can
212211
load faster and not rely on external network requests

flake.nix

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,31 +214,60 @@
214214
env.androidComposition.ndk-bundle
215215
openjdk
216216
strace
217+
gradle_9
218+
patchelf
217219
]);
218220
buildInputs = env.commonBuildInputs;
219221
postPatch = ''
220222
# Ensure the targets list is clean and only contains aarch64
221223
sed -i 's/targets = .*/targets = ["aarch64-linux-android"]/' Dioxus.toml
222224
'';
225+
gradle_9_1_0_bin = env.pkgs.fetchurl {
226+
url = "https://services.gradle.org/distributions/gradle-9.1.0-bin.zip";
227+
sha256 = "a17ddd85a26b6a7f5ddb71ff8b05fc5104c0202c6e64782429790c933686c806";
228+
};
223229
ANDROID_HOME = "${env.androidComposition.androidsdk}/libexec/android-sdk";
224230
ANDROID_NDK_HOME = "${env.androidComposition.ndk-bundle}/libexec/android-sdk/ndk-bundle";
225231
buildPhase = ''
226232
export HOME=$TMPDIR/fake-home
227233
export XDG_DATA_HOME=$HOME/.local/share
228234
export GRADLE_USER_HOME=$HOME/.gradle
229235
mkdir -p $HOME
236+
237+
# Pre-populate Gradle distribution to avoid network access for the wrapper
238+
DIST_DIR=$GRADLE_USER_HOME/wrapper/dists/gradle-9.1.0-bin/83615469-820d-4054-9988-823078453c07
239+
mkdir -p $DIST_DIR
240+
ln -s $gradle_9_1_0_bin $DIST_DIR/gradle-9.1.0-bin.zip
241+
touch $DIST_DIR/gradle-9.1.0-bin.zip.ok
242+
230243
# Use absolute paths to avoid canonicalization issues in Nix sandbox
231244
export CARGO_TARGET_DIR=$PWD/target
232245
# Pre-create the directory wry expects to avoid canonicalization failure
233246
export WRY_ANDROID_KOTLIN_FILES_OUT_DIR=$CARGO_TARGET_DIR/dx/log-out/release/android/app/app/src/main/kotlin/dev/dioxus/main
234247
mkdir -p $WRY_ANDROID_KOTLIN_FILES_OUT_DIR
248+
249+
# dx build --android will still try to fetch dependencies from Maven Central.
250+
# In a pure Nix build, this will fail unless we use a fixed-output derivation.
251+
# We try to run it and if it fails due to network, we at least have a better error.
235252
dx build --android --release --target aarch64-linux-android --verbose
253+
236254
# Inject icons as per scripts/android-icon.sh logic
237255
APP_PROJECT_DIR=$(find target/dx -name "android" -type d | grep "release/android" | head -n 1)/app
238256
if [ -d "$APP_PROJECT_DIR" ]; then
239257
echo "🎨 Injecting Android icons into $APP_PROJECT_DIR"
240258
cp -r android/res "$APP_PROJECT_DIR/app/src/main/"
241259
pushd "$APP_PROJECT_DIR"
260+
261+
# Patch aapt2 if it was downloaded/extracted by Gradle
262+
find "$GRADLE_USER_HOME/caches" -name aapt2 -type f -executable 2>/dev/null | while read -r aapt2; do
263+
if ! patchelf --print-interpreter "$aapt2" >/dev/null 2>&1 || [[ "$(patchelf --print-interpreter "$aapt2")" == /lib* ]]; then
264+
echo "🔧 Patching aapt2 at $aapt2"
265+
chmod +x "$aapt2"
266+
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$aapt2" || true
267+
patchelf --set-rpath "${env.pkgs.lib.makeLibraryPath [ env.pkgs.stdenv.cc.cc.lib env.pkgs.zlib ]}" "$aapt2" || true
268+
fi
269+
done
270+
242271
./gradlew assembleRelease
243272
popd
244273
fi

0 commit comments

Comments
 (0)