简体   繁体   中英

Application class not loading when disabling instant run

I am doing a sample project where I am using both google play services and FireBase to implement location and FCM.

I am using android studio 2.1.1 and gradle:2.1.0

So the original issue I got was :

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/tools/fd/runtime/AppInfo;
at com.android.tools.fd.runtime.BootstrapApplication.(BootstrapApplication.java:126)

For this I found solution to disable instant run, so I did. Now I was getting DexOverflowException , so I excluded few modules from the dependencies and all is good. But now the code in my Application class won't work. Application class onCreate() method does not get called.

In case anyone wondering I placed application class reference in manifest or not, I did.

<application
    android:name=".HHApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

Here is my project build.gradle :

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

Here is the app build.gradle :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "xxxxxxxxxxx"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.google.code.gson:gson:2.3'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile ('com.google.android.gms:play-services-location:9.0.2') {
        exclude module: 'support-v4'
        exclude module: 'support-annotations'
        exclude module: 'firebase-common'
    }
    compile ('com.google.firebase:firebase-messaging:9.0.0') {
        exclude module: 'play-services-base'
        exclude module: 'play-services-basement'
        exclude module: 'play-services-task'
        exclude module: 'support-v4'
        exclude module: 'support-annotations'
    }
    compile files('libs/android-query.0.26.7.jar')
}

apply plugin: 'com.google.gms.google-services'

I updated the studio to 2.13 and gradle to 2.14.1 with com.android.tools.build:gradle:2.1.3, this solved the original problem -

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/tools/fd/runtime/AppInfo; at com.android.tools.fd.runtime.BootstrapApplication.(BootstrapApplication.java:126)

Disabling instant run still doesn't worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM