Android apk too big using OpenCV and Nd4j

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:

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

How can i reduce the size?

It is pretty easy to do. See this: Reducing the Number of Dependencies · bytedeco/javacpp-presets Wiki · GitHub

1 Like

The most popular architectures now are arm64 and x86_64?

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”

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

1 Like

and for my purpose which libraries should i include?

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

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

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

Now apk size is 480MB but still big…