PoseEstimationForMobile icon indicating copy to clipboard operation
PoseEstimationForMobile copied to clipboard

Android Mace demo build failed

Open jestyf opened this issue 7 years ago • 15 comments

Thanks for your work. I built mace demo with android studio, but failed. those are error informations. info error information I've tried all I could do, but no help.Could you please give me some instructions? Thanks.

jestyf avatar Aug 01 '18 05:08 jestyf

@edvardHua I encounter error as follow when build mace_demo via AS 3.0.1, how can I solve it? image

zsf23 avatar Aug 06 '18 11:08 zsf23

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, std::__ndk1::allocator >, std::__ndk1::allocator<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > > > const&, std::__ndk1::vector<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator >, std::__ndk1::allocator<std::__ndk1::basic_string<char, std::__ndk1::char_traits, std::__ndk1::allocator > > > const&, unsigned char const*)'

.......................................................................... : 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.

MahajanTarun avatar Aug 07 '18 09:08 MahajanTarun

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

edvardHua avatar Aug 07 '18 09:08 edvardHua

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

MahajanTarun avatar Aug 07 '18 09:08 MahajanTarun

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.

MahajanTarun avatar Aug 09 '18 09:08 MahajanTarun

@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.😁

edvardHua avatar Aug 10 '18 02:08 edvardHua

@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 avatar Aug 10 '18 04:08 edvardHua

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.

MahajanTarun avatar Aug 23 '18 06:08 MahajanTarun

@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.`

chenxingwei avatar Jan 07 '19 03:01 chenxingwei

@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.....

burstchao avatar Jan 09 '19 07:01 burstchao

@chenxingwei @burstchao Can you list what the command you used here for more detail?

littleGnAl avatar Jan 10 '19 02:01 littleGnAl

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 avatar Jan 30 '19 11:01 AngryDuckFTW

@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.

junwoo93s avatar Feb 04 '19 01:02 junwoo93s

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

ffriande avatar Jul 15 '19 13:07 ffriande

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:

  1. Clone the PoseEstimationForMobile & open demo_mace in Android Studio separately from the main PoseEstimationForMobile project.
  2. 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
  1. So I clicked on Upgrade plugin to version 3.6.1 and sync project as 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”

  1. 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.

  1. (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.

  1. 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.

  1. 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

  1. Now, I click on “Run ‘app’” with my phone plugged in. And this thread’s infamous error with thelibmace_mobile_jni.so pops 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'
  }
}
  1. My Phone (Sony Z5 Compact) runs the app 🎉🎉🎉

keanecodes avatar Mar 25 '20 07:03 keanecodes