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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[caffe2] Improve build_android experience #13116

t-vi opened this issue Oct 25, 2018 · 7 comments

[caffe2] Improve build_android experience #13116

t-vi opened this issue Oct 25, 2018 · 7 comments


Copy link

@t-vi t-vi commented Oct 25, 2018

馃殌 Feature

It would be nice to make it easier to build android libraries for caffe2.


I recently built the AICamera example with recent android studio. The result and steps are here:


Based on the feedback I got on the first day after mentioning this on the PyTorch slack, there are more people who have been trying this and had less success, even though I'd think they're pretty good with PyTorch in general.

  • To facilitate android x86 building, add a switch to disable AVX independent of detection.
    (Or make it work on android, but I guess android x86 is debugging mostly anyway.)
  • Make the build output path include the architecture.
  • Default to clang to adapt to what android seems to be doing toolchain-wise.
  • Add some instructions to build and copy the libs + includes.


  • Keep it a secret black art and find a business model helping people on a case by case basis.
  • Build libtorch for android and use that.

Additional context

The other changes in my fork might be the basis for a PR for the AICamera repo and an update to the tutorial once this is merged.

Needless to say, I would submit the PR.

Copy link

@infil00p infil00p commented Oct 26, 2018

I can't +1 this enough. I've sunk way too much time trying to figure this out, and I would love it if there was a reliable build for Caffe2 for Android that was well maintained.

@t-vi t-vi changed the title Caffe2: Improve build_android experience [caffe2] Improve build_android experience Oct 26, 2018
t-vi added a commit to t-vi/pytorch that referenced this issue Oct 26, 2018
- change toolchain defautl to clang
- discuss x86 building
- provide facility to turn off AVX
- add some commentary about libs and headers

Fixes: pytorch#13116
@zou3519 zou3519 added the caffe2 label Oct 29, 2018
Copy link

@Suhail Suhail commented Nov 21, 2018


1 similar comment
Copy link

@rivergold rivergold commented Nov 23, 2018


Copy link

@Suhail Suhail commented Dec 14, 2018

For those trying, this worked for me on Ubuntu 16.04:

$ export ANDROID_NDK=~/android-ndk-r18b/
$ ./scripts/ -DANDROID_TOOLCHAIN=clang

You'll need to download the android ndk files:

Copy link
Collaborator Author

@t-vi t-vi commented Dec 14, 2018

It also works on linux/bash if you put it all on one line, not sure why your OSX doesn't like it.

Copy link

@425172555 425172555 commented Jan 16, 2019

Please tell me why
Building protoc
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler


is not able to compile a simple test program.

It fails with the following output:

Change Dir: /home/tcl/pytorch/build_host_protoc/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_7ec42/fast"
/usr/bin/make -f CMakeFiles/cmTC_7ec42.dir/build.make CMakeFiles/cmTC_7ec42.dir/build
make[1]: 杩涘叆鐩綍鈥/home/tcl/pytorch/build_host_protoc/build/CMakeFiles/CMakeTmp鈥
Building C object CMakeFiles/cmTC_7ec42.dir/testCCompiler.c.o
/usr/bin/cc   -fembed-bitcode    -o CMakeFiles/cmTC_7ec42.dir/testCCompiler.c.o   -c /home/tcl/pytorch/build_host_protoc/build/CMakeFiles/CMakeTmp/testCCompiler.c
cc: error: unrecognized command line option 鈥-fembed-bitcode鈥
CMakeFiles/cmTC_7ec42.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_7ec42.dir/testCCompiler.c.o' failed
make[1]: *** [CMakeFiles/cmTC_7ec42.dir/testCCompiler.c.o] Error 1
make[1]: 绂诲紑鐩綍鈥/home/tcl/pytorch/build_host_protoc/build/CMakeFiles/CMakeTmp鈥
Makefile:126: recipe for target 'cmTC_7ec42/fast' failed
make: *** [cmTC_7ec42/fast] Error 2

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:12 (project)

-- Configuring incomplete, errors occurred!
See also "/home/tcl/pytorch/build_host_protoc/build/CMakeFiles/CMakeOutput.log".
See also "/home/tcl/pytorch/build_host_protoc/build/CMakeFiles/CMakeError.log".

Copy link

@soumith soumith commented May 3, 2019

Fixed on master via @ljk53 's PRs

@soumith soumith closed this May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants