Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android build: Execution failed for task ':app:mergeExtDexDebug'. #21494

Open
kapsyst opened this issue Jul 25, 2024 · 12 comments
Open

Android build: Execution failed for task ':app:mergeExtDexDebug'. #21494

kapsyst opened this issue Jul 25, 2024 · 12 comments
Labels
build build issues; typically submitted using template platform:mobile issues related to ONNX Runtime mobile; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot

Comments

@kapsyst
Copy link

kapsyst commented Jul 25, 2024

Describe the issue

I get this error when running the following command:

python3 tools/ci_build/github/android/build_aar_package.py --android_sdk_path /Users/kapsyproductivity/Library/Android/sdk --android_ndk_path /Users/kapsyproductivity/Library/Android/sdk/ndk/27.0.11902837 tools/ci_build/github/android/default_full_aar_build_settings.json --config Release

Relevant log output is attached to "Error/output" section.

Have tried suggested Stack Overflow fix for this error with no change to output.

Worth noting that this build command also results in the same error:

./build.sh --android --android_sdk_path /Users/kapsyproductivity/Library/Android/sdk --android_ndk_path /Users/kapsyproductivity/Library/Android/sdk/ndk/27.0.11902837 --android_abi arm64-v8a --android_api 30 --build_java --use_nnapi --config Release --build_shared_lib --parallel

Urgency

Reasonably urgent.

Target platform

Android

Build script

build_aar_package.py

Error / output

ort_java_build_error.log

Visual Studio Version

No response

GCC / Compiler Version

No response

@kapsyst kapsyst added the build build issues; typically submitted using template label Jul 25, 2024
@github-actions github-actions bot added the platform:mobile issues related to ONNX Runtime mobile; typically submitted using template label Jul 25, 2024
@skottmckay
Copy link
Contributor

I was able to build successfully on WSL with NDK 27 and the latest code from main using the build.sh command.

I did see some StackOverflow answers to similar questions where the problem was resolved by reinstalling Android Studio so maybe there's a system config issue affecting your builds.

@kapsyst
Copy link
Author

kapsyst commented Jul 26, 2024

Thanks @skottmckay. I'll try installing the latest version of Android Studio.

Would it be possible to share the full build.sh command you used?

@kapsyst
Copy link
Author

kapsyst commented Jul 26, 2024

Also, I should have mentioned I'm using macOS Sonoma 14.1.2 (23B92) and Android Studio Iguana | 2023.2.1 Patch 2.

@kapsyst
Copy link
Author

kapsyst commented Jul 26, 2024

I updated Android Studio to Koala (2024.1.1 Patch 1), and ran the following command:

 ./build.sh --android --android_sdk_path /Users/kapsyproductivity/Library/Android/sdk --android_ndk_path /Users/kapsyproductivity/Library/Android/sdk/ndk --android_abi arm64-v8a --android_api 27 --build_java --use_nnapi --config Release --build_shared_lib

And now I'm getting a different error:

 68%] Built target onnxruntime4j
[ 68%] Building C object CMakeFiles/onnxruntime4j_jni.dir/Users/kapsyproductivity/projects/onnxruntime/java/src/main/native/ai_onnxruntime_OnnxMap.c.o
In file included from /Users/kapsyproductivity/projects/onnxruntime/java/src/main/native/ai_onnxruntime_OnnxMap.c:7:
/Users/kapsyproductivity/projects/onnxruntime/java/src/main/native/OrtJniUtil.h:110:10: error: call to undeclared function 'reallocarray'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  110 |   return reallocarray(NULL, nmemb, size);
      |          ^
/Users/kapsyproductivity/projects/onnxruntime/java/src/main/native/OrtJniUtil.h:110:10: note: did you mean 'allocarray'?
/Users/kapsyproductivity/projects/onnxruntime/java/src/main/native/OrtJniUtil.h:108:21: note: 'allocarray' declared here
  108 | static inline void* allocarray(size_t nmemb, size_t size) {
      |                     ^
  109 | #ifdef HAS_REALLOCARRAY
  110 |   return reallocarray(NULL, nmemb, size);
      |          ~~~~~~~~~~~~
      |          allocarray
/Users/kapsyproductivity/projects/onnxruntime/java/src/main/native/OrtJniUtil.h:110:10: error: incompatible integer to pointer conversion returning 'int' from a function with result type 'void *' [-Wint-conversion]
  110 |   return reallocarray(NULL, nmemb, size);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
make[2]: *** [CMakeFiles/onnxruntime4j_jni.dir/Users/kapsyproductivity/projects/onnxruntime/java/src/main/native/ai_onnxruntime_OnnxMap.c.o] Error 1
make[1]: *** [CMakeFiles/onnxruntime4j_jni.dir/all] Error 2
make: *** [all] Error 2
Traceback (most recent call last):
  File "/Users/kapsyproductivity/projects/onnxruntime/tools/ci_build/build.py", line 2971, in <module>
    sys.exit(main())
  File "/Users/kapsyproductivity/projects/onnxruntime/tools/ci_build/build.py", line 2863, in main
    build_targets(args, cmake_path, build_dir, configs, num_parallel_jobs, args.target)
  File "/Users/kapsyproductivity/projects/onnxruntime/tools/ci_build/build.py", line 1741, in build_targets
    run_subprocess(cmd_args, env=env)
  File "/Users/kapsyproductivity/projects/onnxruntime/tools/ci_build/build.py", line 862, in run_subprocess
    return run(*args, cwd=cwd, capture_stdout=capture_stdout, shell=shell, env=my_env)
  File "/Users/kapsyproductivity/projects/onnxruntime/tools/python/util/run.py", line 49, in run
    completed_process = subprocess.run(
  File "/Users/kapsyproductivity/miniforge3/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/opt/homebrew/bin/cmake', '--build', '/Users/kapsyproductivity/projects/onnxruntime/build/Android/Release', '--config', 'Release']' returned non-zero exit status 2.

I'm not sure if this is related -- if not, can start a new issue.

@skottmckay
Copy link
Contributor

I cut-and-pasted your command and adjusted the path to my Android SDK.

What NDK are you using? I noted the one in your command was the RC and the actual release is out. Not sure that's relevant though.

I've never seen an error about reallocarray and afaik the JNI code hasn't changed lately.

There seems to be a mismatch between what was found during configuration and what's available at runtime.

cmake found a reallocarray function

image

but the compiler didn't

/Users/kapsyproductivity/projects/onnxruntime/java/src/main/native/OrtJniUtil.h:110:10: error: call to undeclared function 'reallocarray'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

Based on the android source it should come from malloc.h for libc which seems like it should be consistently available given how basic it is.

@kapsyst
Copy link
Author

kapsyst commented Jul 30, 2024

@skottmckay Sorry for the late reply. I just realized that in your initial messsage you said NDK 27 and not SDK 27. My bad.
I downloaded the latest NDK (27.0.12077973) and tried it with the following command:

./build.sh --android --android_sdk_path /Users/kapsyproductivity/Library/Android/sdk --android_ndk_path /Users/kapsyproductivity/Library/Android/sdk/ndk/27.0.12077973 --android_abi arm64-v8a --android_api 33 --build_java --use_nnapi --config Release --build_shared_lib

The reallocarray error disappears but unfortunately the original :app:mergeExtDexDebug error is back.

The entire build output is here: ort_java_build_error_7_30_1359.log

@kapsyst
Copy link
Author

kapsyst commented Aug 5, 2024

Just looking into this issue more, I'm wondering if this warning is a factor?

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

Current version:

onnxruntime % ./java/gradlew --version

------------------------------------------------------------
Gradle 8.6
------------------------------------------------------------

Build time:   2024-02-02 16:47:16 UTC
Revision:     d55c486870a0dc6f6278f53d21381396d0741c6e

Kotlin:       1.9.20
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          21.0.1 (Oracle Corporation 21.0.1+12-29)
OS:           Mac OS X 14.1.2 aarch64

@kapsyst
Copy link
Author

kapsyst commented Aug 5, 2024

Just adding another update. I tried the same build on an Ubuntu instance that I use and experienced the same error.
Here are the logs:
build.log
error.log
Here is the output of ./java/gradlew -- version:
image (5)

@kapsyst
Copy link
Author

kapsyst commented Aug 7, 2024

@skottmckay Sorry for directly mentioning you, but we were wondering if you had any further advice on this issue? We're quite stuck here, having tried the following suggested answers:

  • Using minSdkVersion of 24 (which all SO answers suggest)
  • Using multiDexEnabled true, and including multi-dex dependencies
  • Building on separate macOS machines and Ubuntu (all giving the same error)

We're able to build the .so file and run that, but we require the AAR for production. We want to build from source, instead of using a release, to make use of this fix: #21286
When do you think the next release of ORT will be likely? And, would there be some way to get access to the nightly builds as a way of getting around this?

@skottmckay
Copy link
Contributor

There's an AAR in the native nuget package: https://aiinfra.visualstudio.com/PublicPackages/_artifacts/feed/ORT-Nightly/NuGet/Microsoft.ML.OnnxRuntime/overview/1.19.0-dev-20240805-1630-ee2fe87e2d

The nupkg file is just a zip file, and the AAR is in runtimes/android/native/onnxruntime.aar

Next release should be this month.

Not sure what else we could change. I can't repro the issue locally and our CI builds have no issues.

@kapsyst
Copy link
Author

kapsyst commented Aug 7, 2024

@skottmckay Thank you very much! With that AAR I was at least able to try out our models without the NNAPI error we were getting before.

Appreciate your help.

I will continue trying to get the build going as it would be great to debug, try out latest releases etc.

Copy link
Contributor

github-actions bot commented Sep 6, 2024

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build issues; typically submitted using template platform:mobile issues related to ONNX Runtime mobile; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

2 participants