# File size of dynamic libraries for android are very large

**URL:** <https://discuss.pytorch.org/t/file-size-of-dynamic-libraries-for-android-are-very-large/155576>\
**Category:** Mobile\
**Created:** [July 1, 2022, 6:14pm UTC](https://discuss.pytorch.org/t/file-size-of-dynamic-libraries-for-android-are-very-large/155576 "2022-07-01T18:14:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![leigao97](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/leigao97/32/50294_2.png) [@leigao97](https://discuss.pytorch.org/u/leigao97)\
**Post date:** [July 1, 2022, 6:14pm UTC](https://discuss.pytorch.org/t/file-size-of-dynamic-libraries-for-android-are-very-large/155576/1 "2022-07-01T18:14:06Z")

</div>

The file size of dynamic libraries for android generated under `pytorch/build_android/install/lib` are very large. Here is the detail:

> -rw-r–r-- 1 ultraz ultraz 5.7M Jun 30 23:17 build\_android/install/lib/libc10.so  
> -rw-r–r-- 1 ultraz ultraz 82M Jun 30 23:19 build\_android/install/lib/libtorch\_cpu.so  
> -rw-r–r-- 1 ultraz ultraz 7.4K Jun 30 23:17 build\_android/install/lib/libtorch\_global\_deps.so  
> -rw-r–r-- 1 ultraz ultraz 7.4K Jun 30 23:19 build\_android/install/lib/libtorch.so

For libtorch\_cpu, it is 82M, which is considerably large once integrated into a mobile app. I see the `script/build_android.sh` has already disabled a lot of features. I would like to ask if it is possible to further reduce the size of libs?

---

<div class="post-metadata">

**Author:** ![chaoyanghe](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/chaoyanghe/32/21028_2.png) [@chaoyanghe](https://discuss.pytorch.org/u/chaoyanghe)\
**Post date:** [July 1, 2022, 6:16pm UTC](https://discuss.pytorch.org/t/file-size-of-dynamic-libraries-for-android-are-very-large/155576/2 "2022-07-01T18:16:33Z")

</div>

I also met this issue when compiling mobile version. 100M+ is too big for smartphones…

---

<div class="post-metadata">

**Author:** ![Linbin](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/linbin/32/18676_2.png) [@Linbin](https://discuss.pytorch.org/u/Linbin)\
**Post date:** [July 2, 2022, 5:45am UTC](https://discuss.pytorch.org/t/file-size-of-dynamic-libraries-for-android-are-very-large/155576/3 "2022-07-02T05:45:33Z")

</div>

Use selective build to only include the used operators in the final library, see

[https://pytorch.org/tutorials/recipes/mobile\_interpreter.html#how-to-use-mobile-interpreter-custom-build](https://pytorch.org/tutorials/recipes/mobile_interpreter.html#how-to-use-mobile-interpreter-custom-build)  
and  
[(prototype) Tracing-based Selective Build Mobile Interpreter in Android and iOS — PyTorch Tutorials 1.12.0+cu102 documentation](https://pytorch.org/tutorials/prototype/tracing_based_selective_build.html) (even smaller size)

---

<div class="post-metadata">

**Author:** ![leigao97](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/leigao97/32/50294_2.png) [@leigao97](https://discuss.pytorch.org/u/leigao97)\
**Post date:** [July 5, 2022, 8:12pm UTC](https://discuss.pytorch.org/t/file-size-of-dynamic-libraries-for-android-are-very-large/155576/4 "2022-07-05T20:12:29Z")

</div>

Thank you and I will try it.

---

<div class="post-metadata">

**Author:** ![cccclai](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/cccclai/32/35398_2.png) [@cccclai](https://discuss.pytorch.org/u/cccclai)\
**Post date:** [July 10, 2022, 3:26am UTC](https://discuss.pytorch.org/t/file-size-of-dynamic-libraries-for-android-are-very-large/155576/5 "2022-07-10T03:26:40Z")

</div>

```auto
[quote="leigao97, post:1, topic:155576"]
-rw-r–r-- 1 ultraz ultraz 82M Jun 30 23:19 build_android/install/lib/libtorch_cpu.so
[/quote]

```

1. Looks like it’s the size of an old interpreter. The size should be smaller if you check `build_android_lite/install/lib/libtorch_cpu.so`. See [(beta) Efficient mobile interpreter in Android and iOS — PyTorch Tutorials 1.12.0+cu102 documentation](https://pytorch.org/tutorials/recipes/mobile_interpreter.html)

2. From the number, this `libtorch_cpu.so` includes all 4 android abis (armeabi-v7a, arm64-v8a, x86, x86\_64). For one device, only one abi is needed and size should be much less. Select build is another way to bring down. the size.

---

<div class="post-metadata">

**Author:** ![leigao97](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/leigao97/32/50294_2.png) [@leigao97](https://discuss.pytorch.org/u/leigao97)\
**Post date:** [July 11, 2022, 12:10am UTC](https://discuss.pytorch.org/t/file-size-of-dynamic-libraries-for-android-are-very-large/155576/6 "2022-07-11T00:10:53Z")

</div>

I have tested a couple of cases for ANDROID\_ABI=arm64-v8a, and here is the result:

1. `BUILD_LITE_INTERPRETER=0 ./script/build_android.sh` → `libtorch_cpu.so ` is 89M
2. `BUILD_LITE_INTERPRETER=1 ./script/build_android.sh` → `libtorch_cpu.so ` is 81M
3. `BUILD_LITE_INTERPRETER=1 .SELECTED_OP_LIST=scripted_lenet_model.yaml /script/build_android.sh` → `libtorch_cpu.so ` is 75M

@cccclai Can you clarify that I am using the new interpreter? For your second point, I think it only builds one specific ABI because I have declared before compiling.

---

<div class="post-metadata">

**Author:** ![cccclai](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/cccclai/32/35398_2.png) [@cccclai](https://discuss.pytorch.org/u/cccclai)\
**Post date:** [July 11, 2022, 1:59am UTC](https://discuss.pytorch.org/t/file-size-of-dynamic-libraries-for-android-are-very-large/155576/7 "2022-07-11T01:59:14Z")

</div>

Try to use

```auto
BUILD_LITE_INTERPRETER=1 ./scripts/build_pytorch_android.sh x86

```

to build for x86.

The one with smaller size is the new interpreter. `BUILD_LITE_INTERPRETER=1` is the correct environement setting.

---

<div class="post-metadata">

**Author:** ![Cagatay\_Bilgin](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/cagatay_bilgin/32/62060_2.png) [@Cagatay\_Bilgin](https://discuss.pytorch.org/u/Cagatay_Bilgin)\
**Post date:** [May 15, 2025, 4:47pm UTC](https://discuss.pytorch.org/t/file-size-of-dynamic-libraries-for-android-are-very-large/155576/8 "2025-05-15T16:47:16Z")

</div>

Hey there! Just wanted to let you know that we’ve been using ExecuTorch for a bit now, and the old stack is no longer supported. You can find ExecuTorch on GitHub: [GitHub - pytorch/executorch: On-device AI across mobile, embedded and edge for PyTorch](https://github.com/pytorch/executorch). If you have any questions or want to stay in the loop, join our Discord server at [PyTorch Edge](https://discord.gg/Wyn9PWqP).
