R
R
razer892015-11-09 17:49:57
Android
razer89, 2015-11-09 17:49:57

How to increase build speed in AndroidStudio if multidex is used?

Hello! I reached the limit of 65k methods in my application, I had to connect multidex. But the time spent on the build has increased many times, if not dozens of times. I found this method, however, after that the application began to crash with an exception

ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication"

This is what build.gradle looks like:
apply plugin: 'com.android.application'

repositories {
    mavenCentral()
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
    flatDir {
        dirs 'libs'
    }
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        targetSdkVersion 23
        versionCode 5
        versionName "0.5"
        multiDexEnabled true
    }
    productFlavors {
        dev {
            minSdkVersion 21
        }
        prod {
            minSdkVersion 14
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    compile 'com.android.support:cardview-v7:23.1.0'
    compile 'org.jsoup:jsoup:1.8.2'
    compile 'com.google.android.gms:play-services-maps:8.3.0'
    compile 'com.google.android.gms:play-services-appindexing:8.3.0'
    compile 'com.google.android.gms:play-services-auth:8.3.0'
    compile 'com.google.android.gms:play-services-plus:8.3.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.quinny898.library.persistentsearch:library:1.0.0-SNAPSHOT'
    compile 'com.android.support:design:23.0.1'
    compile('io.socket:socket.io-client:0.6.2') {
        exclude group: 'org.json', module: 'json'
    }
    compile 'org.parceler:parceler:1.0.4'
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'
    compile files('libs/universal-image-loader-1.9.4.jar')
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.ms-square:expandableTextView:0.1.4'
    compile 'uk.me.lewisdeane.ldialogs:[email protected]'
    compile 'com.daimajia.slider:library:[email protected]'
    compile 'info.hoang8f:fbutton:1.0.5'
    compile 'com.orhanobut:dialogplus:[email protected]'
    compile 'com.appyvet:materialrangebar:1.1'
    compile 'com.cocosw:bottomsheet:1.2.0'
}

The manifest, of course, says:
android:name="android.support.multidex.MultiDexApplication"

And the MyApplication class inherits from MultiDexApplication.
I suspect that something is wrong with productFlavors, because if you delete this block and move minSdkVersion to defaultConfig, everything builds fine, but it takes a VERY long time. Please help!
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tiberal, 2015-11-10
@razer89

And what build option did you choose in the studio? should be devrelease or something like that. There is a suspicion that you are building the entire project at once, and when you build prodrelease, it will crash. You can also try to extend from the usual application and limit yourself to the method

@Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

for multidex. Also, if I were you, I would try to assemble manually and see what's in the logs)
./gradlew tasks - will show all the tasks,
select the one you need and run ./gradlew assemble (task) --debug
well, look what the gradle says to you)
But I would not I was hoping for a particularly significant increase in assembly speed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question