Android Mace demo build failed
Thanks for your work. I built mace demo with android studio, but failed. those are error informations.
error information
I've tried all I could do, but no help.Could you please give me some instructions? Thanks.
@edvardHua I encounter error as follow when build mace_demo via AS 3.0.1, how can I solve it?

Here is what I get: Gradle sync successfull, but:
[1/1] Linking CXX shared library ........\build\intermediates\cmake\debug\obj\armeabi-v7a\libmace_mobile_jni.so
error: undefined reference to 'mace::MaceEngine::Init(mace::NetDef const*, std::__ndk1::vector<std::__ndk1::basic_string<char, std::__ndk1::char_traits
.......................................................................... : error: undefined reference to 'std::__throw_bad_cast()' clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
where in BUILD.gradle: {
externalNativeBuild {
cmake {
cppFlags "-fexceptions -std=gnu++11"
arguments '-DANDROID_STL=gnustl_static'
}
}
ndk{
abiFilters 'armeabi-v7a'
stl = "gnustl_shared"
}
}
->I even tried Mace Demo which produces ~same error.
Which platform do you use @edvardHua ? So that I can try on it, if it gets right there.
I clone my project and rebuild it again. Below is the environment of mine:
- Operation System:
macOS 10.13.6(mace not support build under windows now) - Android Studio:
3.0.1 - NDK Version:
r16
Very Thnks @edvardHua .
Well, I am working on Windows10 and for those who are also working on same platform, I am finding a way to get it done on win10.
Main reason for apk build failed is: It doesnot find "libmace_mobile_jni.so" file at all the addressed places.
Meanwhile if anybody finds the so, please post it here. Thnks
Previously I was trying to built the apk on Windows 10. After you mentioned - (mace not support build under windows now), I executed the code on Ubuntu.
Still it produces the following errors.:-
Error while executing process /...../Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /......../PoseEstimationForMobile-master/android_demo/demo_mace/macelibrary/.externalNativeBuild/cmake/debug/armeabi-v7a --target mace_mobile_jni} [1/1] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libmace_mobile_jni.so FAILED: : && /.../Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi --gcc-toolchain=/.../Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/.../Android/Sdk/ndk-bundle/sysroot -fPIC -isystem /.../Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -fexceptions -std=gnu++11 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /.../Android/Sdk/ndk-bundle/platforms/android-21/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--exclude-libs,libunwind.a -L/.../Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libmace_mobile_jni.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libmace_mobile_jni.so CMakeFiles/mace_mobile_jni.dir/src/main/cpp/spe.cc.o ../../../../src/main/cpp/lib/armeabi-v7a/libmace.a ../../../../src/main/cpp/model/armeabi-v7a/cpm.a /home/ts-pc03/Android/Sdk/ndk-bundle/platforms/android-21/arch-arm/usr/lib/liblog.so -latomic -..... ........ .......... ..... clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
@jestyf @MahajanTarun @Kanbo0409
Pls check the correct version of ndk and build it under unix-like operation system.
One of my friend try to build and encounter some errors and fixed by add
arguments '-DANDROID_STL=gnustl_static'
to both app and macelibrary build.gradle, the ndk version is r17.
Below is the link he ref.
https://stackoverflow.com/questions/50315422/opencv-undefined-reference-to-cvcascadeclassifierdetectmultiscale-after
If anyone of your guy make it done, pls let me know your solution.😁
@jestyf @MahajanTarun @Kanbo0409
Different environments may encounter different error when you build mace-demo ( I can't cover all situations). To avoid this, i suggest using docker.
Pls clone the repo in a new directory and then exec the following commands.
docker pull registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite
docker run -it
--privileged -d --name mace-dev
--net=host
-v to/you/path/PoseEstimationForMobile/android_demo/demo_mace:/demo_mace
registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite
docker run -it --privileged -d --name mace-dev --net=host \
-v to/you/path/PoseEstimationForMobile/android_demo/demo_mace:/demo_mace \
registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite
# Enter to docker
docker exec -it mace-dev bash
# Exec command inside the docker
cd /demo_mace && ./gradlew build
It took a long time to understand the reason why we were unable to build the apk, inspite of many successful builds. For those who are still unclear about the issue, here is the solution which we found: This should be in the build file. NOTE: both in build.gradle(app) and build.gradle(macelibrary)
externalNativeBuild {
cmake {
//arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static'
// cppFlags "-std=c++11","-frtti", "-fexceptions"
arguments '-DBUILD_TESTING=OFF', '-DANDROID_STL=gnustl_static'
//, '-DANDROID_TOOLCHAIN=gcc'
cppFlags "-std=c++11","-frtti", "-fexceptions", "-fopenmp"
abiFilters "armeabi-v7a"
}
}
This solution we mentioned earlier, but we only applied it to build.gradle(app) file. Also apply it in build.gradle(macelibrary) file.
Also, there's a bug in the app. On first run, the app crashes(Uninitiallized model or invalid context). But it works good on second attempt to run.
Million Thanks to @edvardHua for such an interesting project.
@jestyf @MahajanTarun @Kanbo0409
Different environments may encounter different error when you build mace-demo ( I can't cover all situations). To avoid this, i suggest using docker.
Pls clone the repo in a new directory and then exec the following commands.
docker pull registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite docker run -it --privileged -d --name mace-dev --net=host -v to/you/path/PoseEstimationForMobile/android_demo/demo_mace:/demo_mace registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite docker run -it --privileged -d --name mace-dev --net=host \ -v to/you/path/PoseEstimationForMobile/android_demo/demo_mace:/demo_mace \ registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite # Enter to docker docker exec -it mace-dev bash # Exec command inside the docker cd /demo_mace && ./gradlew build
@edvardHua with the docker environments, it still did not work for by raising the error below, can you help on this ? `* What went wrong: Execution failed for task ':app:generateJsonModelDebug'.
Error occurred while communicating with CMake server. Check log /demo_mace/to/path/demo_mace/app/.externalNativeBuild/cmake/debug/armeabi-v7a/cmake_server_log.txt for additional information.`
@jestyf @MahajanTarun @Kanbo0409 Different environments may encounter different error when you build mace-demo ( I can't cover all situations). To avoid this, i suggest using docker.
Pls clone the repo in a new directory and then exec the following commands.
docker pull registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite docker run -it --privileged -d --name mace-dev --net=host -v to/you/path/PoseEstimationForMobile/android_demo/demo_mace:/demo_mace registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite docker run -it --privileged -d --name mace-dev --net=host \ -v to/you/path/PoseEstimationForMobile/android_demo/demo_mace:/demo_mace \ registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite # Enter to docker docker exec -it mace-dev bash # Exec command inside the docker cd /demo_mace && ./gradlew build@edvardHua with the docker environments, it still did not work for by raising the error below, can you help on this ? `* What went wrong: Execution failed for task ':app:generateJsonModelDebug'.
Error occurred while communicating with CMake server. Check log /demo_mace/to/path/demo_mace/app/.externalNativeBuild/cmake/debug/armeabi-v7a/cmake_server_log.txt for additional information.`
I have a same error too.... and I can`t deal with it.....
@chenxingwei @burstchao Can you list what the command you used here for more detail?
This issue still persists... I've tried @MahajanTarun solution but it doesn't work because you are no longer able to use gnustl_static. I have changed to c++_shared instead. Im running the latest version of Mac OS, latest Android studio, latest version fo Gradle, latest NDK and put.externalNativeBuild { cmake { arguments '-DBUILD_TESTING=OFF', '-DANDROID_STL=c++_static' cppFlags "-std=c++11","-frtti", "-fexceptions", "-fopenmp" abiFilters "armeabi-v7a" } }
within module app and module mace library build.gradle files within the default config and still I'm getting this error: [1/1] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libmace_mobile_jni.so is it because were missing some uni libs? where should these be from I can't see any way to solve this issue and its driving me mad, also I don't want to use docker, im using latest everything there must be a solution
@AngryDuckFTW You have to use ndk17c version and change
cmake { //arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static' // cppFlags "-std=c++11","-frtti", "-fexceptions" arguments '-DBUILD_TESTING=OFF', '-DANDROID_STL=gnustl_static' //, '-DANDROID_TOOLCHAIN=gcc' cppFlags "-std=c++11","-frtti", "-fexceptions", "-fopenmp" abiFilters "armeabi-v7a" }
for app, build.gradle, and library.
then it will work.
I've tried everything but I am stuck, because cppFlags is not recognized, though I've tried different gradle versions. NDK version is r15c
Gradle DSL method not found: 'cppFlags()'
Possible causes:
The project 'PoseProject' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file
The build file may be missing a Gradle plugin.
Apply Gradle plugin
Thanks @edvardHua and @MahajanTarun. I got it working by modifying the build.gradle(app) and build.gradle(macelibrary) files.
build.gradle(app)
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=gnustl_static'
}
}
build.gradle(macelibrary)
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -fopenmp"
abiFilters "armeabi-v7a"
arguments '-DANDROID_STL=gnustl_static'
}
}
Additionally, here are the steps I took to get the android project running from a fresh repo clone on macOS Catalina 10.15.3 and Sony Z5 Compact as of 25 Mar 2020 2.30PM:
- Clone the PoseEstimationForMobile & open
demo_macein Android Studio separately from the mainPoseEstimationForMobileproject. - Android Studio will then pop this error, regardless of whether I installed the SDK and NDK globally or not.
ERROR: No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
This version of the NDK may be incompatible with the Android Gradle plugin version 3.0 or older.
Please use plugin version 3.1 or newer.
Upgrade plugin to version 3.6.1 and sync project
- So I clicked on
Upgrade plugin to version 3.6.1 and sync projectas Android Studio recommended, and got the following error:
A problem occurred evaluating project ':app'.
> Could not find method jackOptions() for arguments
<<<abrdiged>>>
I followed the advice here and commented out the jackOptions { enabled true } in build.gradle(app) then pressed “Sync Project with Gradle Files”
- Now Android Studio will give me a new error:
A problem occurred configuring project ':app'.
> NDK not configured. Download it with SDK manager. Preferred NDK version is '20.0.5594570'.
I then :
4.1 Downloaded the NDK 17c as @junwoo93s from this archive
4.2 Unzipped the file, and pasted the android-ndk-r17c in /Users/K/Library/Android/sdk/ndk
4.3 Added the ndk.dir in the local.properties file in the main demo_mace directory as such:
PoseEstimationForMobile/android_demo/demo_mace/local.properties
sdk.dir=/Users/K/Library/Android/sdk
ndk.dir=/Users/K/Library/Android/sdk/ndk/android-ndk-r17c
And press “Sync Project with Gradle Files” again.
- (Happens only once) macOS then may or may not pops up a few warnings, saying:
clang/Id/clang++/arm-linux-androidabi-strip cannot be opened because the developer cannot be verified.
5.1 To this I went to System Preferences > Security & Privacy > General tab and clicked “Allow anyway”.
5.2 And run the project again.
5.3 macOS will now ask me further: “Are you sure if you want to open it?”
5.4 Click “Open”
5.5 macOS will prompt another error for the remaining “clang/Id/clang++/arm-linux-androidabi-strip” so you have to repeat from step 5.1 again till all the packages are approved.
- Android Studio will now pop up another error:
Unsupported Modules Detected: Compilation is not supported for following modules: demo_mace, macelibrary, openCVLibrary341, app. Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.
I followed the instructions here and quit Android Studio, deleted my .idea folder and .iml files in demo_mace, mace library, and openCVLibrary341. Then open demo_mace in Android Studio again, wait for Grade: Build and press “Sync Project with Gradle Files” again.
- Now Android Studio will prompt me another error:
ERROR: The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file.
Remove minSdkVersion and sync project
Affected Modules: app, openCVLibrary341
So I clicked on Remove minSdkVersion and sync project suggestion, Android Studio then pops up the “Refactoring Preview” tab, and I just clicked “Do Refactor”. Again, I pressed “Sync Project with Gradle Files”.
🥳 And smiled at the message:
CONFIGURE SUCCESSFUL in 1s
- Now, I click on “Run ‘app’” with my phone plugged in. And this thread’s infamous error with the
libmace_mobile_jni.sopops up:
[2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libmace_mobile_jni.so
FAILED: ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libmace_mobile_jni.so
So I modified the build.gradle(app) and build.gradle(macelibrary) files as shared at the beginning:
build.gradle(app)
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=gnustl_static'
}
}
build.gradle(macelibrary)
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -fopenmp"
abiFilters "armeabi-v7a"
arguments '-DANDROID_STL=gnustl_static'
}
}
- My Phone (Sony Z5 Compact) runs the app 🎉🎉🎉