Open kapsyst opened 1 month ago
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.
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?
Also, I should have mentioned I'm using macOS Sonoma 14.1.2 (23B92) and Android Studio Iguana | 2023.2.1 Patch 2.
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.
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
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.
@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
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
@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:
minSdkVersion
of 24 (which all SO answers suggest)multiDexEnabled true
, and including multi-dex dependenciesWe'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: https://github.com/microsoft/onnxruntime/pull/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?
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.
@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.
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.
Describe the issue
I get this error when running the following command:
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:
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