Home Enabling Gradle minifying for OpenCv library in Android Studio
Reply: 1

Enabling Gradle minifying for OpenCv library in Android Studio

Roberto Manfreda
1#
Roberto Manfreda Published in 2017-10-22 20:37:18Z

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

Mike
2#
Mike Reply to 2017-10-22 20:53:42Z

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309969 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO