简体   繁体   English

禁用即时运行时不加载应用程序类

[英]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. 我正在做一个示例项目,我正在使用谷歌播放服务和FireBase来实现位置和FCM。

I am using android studio 2.1.1 and gradle:2.1.0 我正在使用android studio 2.1.1和gradle:2.1.0

So the original issue I got was : 所以我得到的原始问题是:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/tools/fd/runtime/AppInfo; java.lang.NoClassDefFoundError:解析失败:Lcom / android / tools / fd / runtime / AppInfo;
at com.android.tools.fd.runtime.BootstrapApplication.(BootstrapApplication.java:126) 在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. 现在我得到了DexOverflowException ,所以我从依赖项中排除了一些模块,一切都很好。 But now the code in my Application class won't work. 但是现在我的Application类中的代码不起作用。 Application class onCreate() method does not get called. 应用程序类onCreate()方法不会被调用。

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 : 这是我的项目 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 : 这是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 - 我将工作室更新为2.13并使用com.android.tools.build:gradle:2.1.3学习到2.14.1,这解决了原来的问题 -

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/tools/fd/runtime/AppInfo; java.lang.NoClassDefFoundError:解析失败:Lcom / android / tools / fd / runtime / AppInfo; at com.android.tools.fd.runtime.BootstrapApplication.(BootstrapApplication.java:126) 在com.android.tools.fd.runtime.BootstrapApplication。(BootstrapApplication.java:126)

Disabling instant run still doesn't worked for me. 禁用即时运行仍然不适合我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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