# Android apk too big using OpenCV and Nd4j

**URL:** <https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718>\
**Category:** DL4J\
**Created:** [July 10, 2020, 8:50am UTC](https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718 "2020-07-10T08:50:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![met9898](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@met9898](https://community.konduit.ai/u/met9898)\
**Post date:** [July 10, 2020, 8:50am UTC](https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718/1 "2020-07-10T08:50:03Z")

</div>

I have an android application that needs the OpenCV and Nd4j libraries. The problem is, the app is too big (almost 700MB), and i have no idea how to slim it down.

build.gradle:

```auto
implementation fileTree(dir: 'libs', include: ['*.jar'])
    // https://mvnrepository.com/artifact/org.nd4j/nd4j-api
implementation group: 'org.nd4j', name: 'nd4j-api', version: '1.0.0-beta7'
implementation group: 'org.nd4j', name: 'nd4j-native-platform', version: '1.0.0-beta7'
implementation group: 'org.datavec', name: 'datavec-data-image', version: '1.0.0-beta7'

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'org.tensorflow:tensorflow-lite:+'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

```

apk: [https://i.stack.imgur.com/3OZ2y.png](https://i.stack.imgur.com/3OZ2y.png)

How can i reduce the size?

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [July 10, 2020, 8:51am UTC](https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718/2 "2020-07-10T08:51:30Z")

</div>

It is pretty easy to do. See this: [Reducing the Number of Dependencies · bytedeco/javacpp-presets Wiki · GitHub](https://github.com/bytedeco/javacpp-presets/wiki/Reducing-the-Number-of-Dependencies)

---

<div class="post-metadata">

**Author:** ![met9898](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@met9898](https://community.konduit.ai/u/met9898)\
**Post date:** [July 10, 2020, 8:56am UTC](https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718/3 "2020-07-10T08:56:18Z")

</div>

The most popular architectures now are arm64 and x86\_64?

---

<div class="post-metadata">

**Author:** ![met9898](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@met9898](https://community.konduit.ai/u/met9898)\
**Post date:** [July 10, 2020, 9:03am UTC](https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718/4 "2020-07-10T09:03:02Z")

</div>

Do i need all?

implementation group: ‘org.nd4j’, name: ‘nd4j-native’, version: ‘1.0.0-beta6’

implementation group: ‘org.nd4j’, name: ‘nd4j-native’, version: ‘1.0.0-beta6’, classifier: “android-arm”

implementation group: ‘org.nd4j’, name: ‘nd4j-native’, version: ‘1.0.0-beta6’, classifier: “android-arm64”

implementation group: ‘org.nd4j’, name: ‘nd4j-native’, version: ‘1.0.0-beta6’, classifier: “android-x86”

implementation group: ‘org.nd4j’, name: ‘nd4j-native’, version: ‘1.0.0-beta6’, classifier: “android-x86\_64”

implementation group: ‘org.bytedeco’, name: ‘openblas’, version: ‘0.3.7-1.5.2’

implementation group: ‘org.bytedeco’, name: ‘openblas’, version: ‘0.3.7-1.5.2’, classifier: “android-arm”

implementation group: ‘org.bytedeco’, name: ‘openblas’, version: ‘0.3.7-1.5.2’, classifier: “android-arm64”

implementation group: ‘org.bytedeco’, name: ‘openblas’, version: ‘0.3.7-1.5.2’, classifier: “android-x86”

implementation group: ‘org.bytedeco’, name: ‘openblas’, version: ‘0.3.7-1.5.2’, classifier: “android-x86\_64”

implementation group: ‘org.bytedeco’, name: ‘opencv’, version: ‘4.1.2-1.5.2’

implementation group: ‘org.bytedeco’, name: ‘opencv’, version: ‘4.1.2-1.5.2’, classifier: “android-arm”

implementation group: ‘org.bytedeco’, name: ‘opencv’, version: ‘4.1.2-1.5.2’, classifier: “android-arm64”

implementation group: ‘org.bytedeco’, name: ‘opencv’, version: ‘4.1.2-1.5.2’, classifier: “android-x86”

implementation group: ‘org.bytedeco’, name: ‘opencv’, version: ‘4.1.2-1.5.2’, classifier: “android-x86\_64”

implementation group: ‘org.bytedeco’, name: ‘leptonica’, version: ‘1.78.0-1.5.2’

implementation group: ‘org.bytedeco’, name: ‘leptonica’, version: ‘1.78.0-1.5.2’, classifier: “android-arm”

implementation group: ‘org.bytedeco’, name: ‘leptonica’, version: ‘1.78.0-1.5.2’, classifier: “android-arm64”

implementation group: ‘org.bytedeco’, name: ‘leptonica’, version: ‘1.78.0-1.5.2’, classifier: “android-x86”

implementation group: ‘org.bytedeco’, name: ‘leptonica’, version: ‘1.78.0-1.5.2’, classifier: “android-x86\_64”

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [July 10, 2020, 10:43am UTC](https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718/5 "2020-07-10T10:43:21Z")

</div>

The most popular architectures are `arm` and `arm64`. `x86_64` is only really needed when you run your application in the Android emulator.

---

<div class="post-metadata">

**Author:** ![met9898](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@met9898](https://community.konduit.ai/u/met9898)\
**Post date:** [July 10, 2020, 10:45am UTC](https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718/6 "2020-07-10T10:45:51Z")

</div>

and for my purpose which libraries should i include?

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [July 10, 2020, 11:22am UTC](https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718/7 "2020-07-10T11:22:05Z")

</div>

those that you’ve listed look like a good start.

---

<div class="post-metadata">

**Author:** ![met9898](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@met9898](https://community.konduit.ai/u/met9898)\
**Post date:** [July 10, 2020, 11:35am UTC](https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718/8 "2020-07-10T11:35:55Z")

</div>

I mainly have to use INDarray, OpenCV (like Mat) and NativeImageLoader

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [July 10, 2020, 11:37am UTC](https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718/9 "2020-07-10T11:37:32Z")

</div>

Yes, and INDArray, i.e. ND4J, uses Openblas and OpenCV and NativeImageLoader need both opencv and leptonica.

---

<div class="post-metadata">

**Author:** ![met9898](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@met9898](https://community.konduit.ai/u/met9898)\
**Post date:** [July 10, 2020, 1:27pm UTC](https://community.konduit.ai/t/android-apk-too-big-using-opencv-and-nd4j/718/12 "2020-07-10T13:27:19Z")

</div>

Now apk size is 480MB but still big…
