Build libtorch for android error, ‘ATen/core/TensorBody.h’ file not found

Sining_Sun: <p>Hi all,</p>
<p>I just want to build libtorch for android. My pytorch verson is 1.6 and ndk version is t19c. I build the libtorch is the follow command:<br>
BUILD_CAFFE2_MOBILE=1 ./scripts/build_android.sh，<br>
But I got this error:</p>
<p>/workspace/tvm/pytorch-mobile/pytorch-1.6/aten/src/ATen/Tensor.h:3:10: fatal error: ‘ATen/core/TensorBody.h’ file not found<br>
<span class="hashtag">#include</span> &lt;ATen/core/TensorBody.h&gt;<br>
^~~~~~~~~~~~~~~~~~~~~~~~<br>
1 error generated.<br>
caffe2/CMakeFiles/torch_cpu.dir/build.make:7262: recipe for target ‘caffe2/CMakeFiles/torch_cpu.dir/operators/rms_norm_op.cc.o’ failed<br>
make[2]: *** [caffe2/CMakeFiles/torch_cpu.dir/operators/rms_norm_op.cc.o] Error 1<br>
make[2]: *** Waiting for unfinished jobs…<br>
CMakeFiles/Makefile2:1362: recipe for target ‘caffe2/CMakeFiles/torch_cpu.dir/all’ failed<br>
make[1]: *** [caffe2/CMakeFiles/torch_cpu.dir/all] Error 2<br>
Makefile:140: recipe for target ‘all’ failed<br>
make: *** [all] Error 2</p>
<p>Anyone knows the reason and how to solve this issue?</p>

ptrblck: <p>Have you updated all submodules via <code>git submodule update --init --recursive</code> and cleaned a recent build via <code>python setup.py clean</code>?</p>

Sining_Sun: <p>I just clone the pytorch 1.6 again with --recursive option. When I compile with the following command, I still got the same error:</p>
<blockquote>
<p>BUILD_CAFFE2_MOBILE=1 ./scripts/build_android.sh，</p>
</blockquote>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/d/fdf6f969df81ce3e0872c6997c18fce2c8c8c397.png" data-download-href="https://discuss.pytorch.org/uploads/default/fdf6f969df81ce3e0872c6997c18fce2c8c8c397" title="微信截图_20201025233227"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/d/fdf6f969df81ce3e0872c6997c18fce2c8c8c397_2_690x166.png" alt="微信截图_20201025233227" data-base62-sha1="AeFWhcTx723Vl2q1326YPdSWl6v" width="690" height="166" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/d/fdf6f969df81ce3e0872c6997c18fce2c8c8c397_2_690x166.png, https://discuss.pytorch.org/uploads/default/optimized/3X/f/d/fdf6f969df81ce3e0872c6997c18fce2c8c8c397_2_1035x249.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/f/d/fdf6f969df81ce3e0872c6997c18fce2c8c8c397_2_1380x332.png 2x" data-dominant-color="151615"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">微信截图_20201025233227</span><span class="informations">2775×671 92.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I don’t know if this is a bug? Previously I have  built libtorch.a using pytorch version 1.4 sucessfully with cmd:</p>
<blockquote>
<p>BUILD_PYTORCH_MOBILE=1 ./scripts/build_android.sh.</p>
</blockquote>
<p>and I can inference using C++ code.</p>
<p>I also want to know the diffenrence between flags BUILD_PYTORCH_MOBILE (v1.4) and BUILD_CAFFE2_MOBILE(v1.6).</p>
<p>Thank you very much</p>

Sining_Sun: <p>I just found that the pytorch I cloned from github is version 1.8. Maybe this is a bug of version 1.8?</p>

Paran0: <p>Same thing happening to me in realease/1.9.0</p>

Linbin: <aside class="quote no-group" data-username="Sining_Sun" data-post="1" data-topic="100526">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sining_sun/48/30231_2.png" class="avatar"> Sining_Sun:</div>
<blockquote>
<p>BUILD_CAFFE2_MOBILE=1 ./scripts/build_android.sh</p>
</blockquote>
</aside>
<p>I think that script is for Caffe2. Use this one for PyTorch android:</p>
<aside class="onebox githubblob" data-onebox-src="https://github.com/pytorch/pytorch/blob/main/scripts/build_pytorch_android.sh">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/blob/main/scripts/build_pytorch_android.sh" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/main/scripts/build_pytorch_android.sh" target="_blank" rel="noopener nofollow ugc">pytorch/pytorch/blob/main/scripts/build_pytorch_android.sh</a></h4>


      <pre><code class="lang-sh">#!/bin/bash
set -eux

##############################################################################
# Master script to build PyTorch Android library with Java bindings.
##############################################################################
# Example usage:
# - Build default AARs:
#   scripts/build_pytorch_android.sh
#
# - Build for specific ABI(s):
#   scripts/build_pytorch_android.sh armeabi-v7a
#   scripts/build_pytorch_android.sh arm64-v8a,x86,x86_64
#
# Script's workflow:
# 1. Builds libtorch for android for specified android abisi (by default for all 4).
# Custom list of android abis can be specified as a bash argument as comma separated list.
# For example just for testing on android x86 emulator we need only x86 build.
# ./scripts/build_pytorch_android.sh x86
# 2. Creates symbolic links to android/pytorch_android/src/main/jniLibs/${abi} for libtorch build output,
</code></pre>



  This file has been truncated. <a href="https://github.com/pytorch/pytorch/blob/main/scripts/build_pytorch_android.sh" target="_blank" rel="noopener nofollow ugc">show original</a>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>