|
214 | 214 | env.androidComposition.ndk-bundle |
215 | 215 | openjdk |
216 | 216 | strace |
| 217 | + gradle_9 |
| 218 | + patchelf |
217 | 219 | ]); |
218 | 220 | buildInputs = env.commonBuildInputs; |
219 | 221 | postPatch = '' |
220 | 222 | # Ensure the targets list is clean and only contains aarch64 |
221 | 223 | sed -i 's/targets = .*/targets = ["aarch64-linux-android"]/' Dioxus.toml |
222 | 224 | ''; |
| 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 | + }; |
223 | 229 | ANDROID_HOME = "${env.androidComposition.androidsdk}/libexec/android-sdk"; |
224 | 230 | ANDROID_NDK_HOME = "${env.androidComposition.ndk-bundle}/libexec/android-sdk/ndk-bundle"; |
225 | 231 | buildPhase = '' |
226 | 232 | export HOME=$TMPDIR/fake-home |
227 | 233 | export XDG_DATA_HOME=$HOME/.local/share |
228 | 234 | export GRADLE_USER_HOME=$HOME/.gradle |
229 | 235 | 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 | +
|
230 | 243 | # Use absolute paths to avoid canonicalization issues in Nix sandbox |
231 | 244 | export CARGO_TARGET_DIR=$PWD/target |
232 | 245 | # Pre-create the directory wry expects to avoid canonicalization failure |
233 | 246 | export WRY_ANDROID_KOTLIN_FILES_OUT_DIR=$CARGO_TARGET_DIR/dx/log-out/release/android/app/app/src/main/kotlin/dev/dioxus/main |
234 | 247 | 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. |
235 | 252 | dx build --android --release --target aarch64-linux-android --verbose |
| 253 | +
|
236 | 254 | # Inject icons as per scripts/android-icon.sh logic |
237 | 255 | APP_PROJECT_DIR=$(find target/dx -name "android" -type d | grep "release/android" | head -n 1)/app |
238 | 256 | if [ -d "$APP_PROJECT_DIR" ]; then |
239 | 257 | echo "🎨 Injecting Android icons into $APP_PROJECT_DIR" |
240 | 258 | cp -r android/res "$APP_PROJECT_DIR/app/src/main/" |
241 | 259 | 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 | +
|
242 | 271 | ./gradlew assembleRelease |
243 | 272 | popd |
244 | 273 | fi |
|
0 commit comments