0

I almost completed a project in Android Studio that included OpenCV library, I imported the library by creating a new folder "jniLibs" under app/src/main. Now there is a big problem, the .apk file size is 105 MB. Using shrinkResources and minifyEnabled for the App module, the dimensions drop to 95 MB. Activating shrinkResources and minifyEnabled also for the OpenCV module, I am returned an error when compiling. Gradle can't find packages of the library!

This is my build.gradle(App)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

defaultConfig {
    applicationId 'it.project'
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
}

buildTypes {
    release {
        shrinkResources true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

sourceSets.main {
    jniLibs.srcDir 'src/main/jniLibs'
    jni.srcDirs = []
}
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:26.0.2'
    compile 'com.android.support:design:26.0.2'
    compile 'com.google.code.gson:gson:2.7'

    compile project(':openCVLibrary330')
}

and this is build.gradle(library)

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 26
    }
}

how can I activate gradle to clean up the library code too?

In this situation with this gradle builds i get an apk of 95 MB. But activating minify for library too i get the error. Cannot resolve org.opencv.core ecc ecc

STRUCTURE OF PROJECT

1 Answers1

0

You shouldn't enable minification for project OpenCV itself because when running proguard it doesn't know what you will use in your app project. Minification in the project app should do the work for project OpenCV as well.
Also, consider using Multiple APK to reduce the size of your apk.

Mike
  • 2,547
  • 3
  • 16
  • 30
  • yes, I know the practice of compiling multiple APKs. But I have never done it and I wonder if they do not get any trouble when I'm going to distribute the app. For example, if I were to load the app on the playstore, would not it be a problem? would i be able to load multiple apk ?? Thank you very much for helping :) –  Oct 22 '17 at 20:56
  • Yes, there is an option for multiple apk of Play Market. There is no problem I know about. – Mike Oct 22 '17 at 20:58