【问题标题】:Application class not loading when disabling instant run禁用即时运行时未加载应用程序类
【发布时间】:2017-01-02 05:54:01
【问题描述】:

我正在做一个示例项目,我同时使用 google play 服务和 FireBase 来实现位置和 FCM。

我正在使用 android studio 2.1.1 和 gradle:2.1.0

所以我得到的原始问题是:

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

为此,我找到了禁用即时运行的解决方案,所以我做到了。 现在我得到了DexOverflowException,所以我从依赖项中排除了几个模块,一切都很好。但是现在我的 Application 类中的代码将不起作用。应用程序类onCreate() 方法未被调用。

如果有人想知道我是否在清单中放置了应用程序类引用,我做到了。

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

这是我的项目 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
    }
}

这是应用程序 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'

【问题讨论】:

  • 有趣的是,这只发生在应用程序第一次运行时。之后该应用程序运行正常。
  • 你使用的是什么版本的 gradle/gradle-wrapper?你试过Invalidate Caches/Restart 然后Clean 项目吗?
  • 好的,我尝试过Invalidate Caches/RestartClean,但没有成功。我正在使用distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
  • 你能用com.android.tools.build:gradle:2.1.3和Gradle 2.14.1试试吗?
  • 我也试过了,还是不行。 :(

标签: android android-studio android-gradle-plugin android-instant-run


【解决方案1】:

我使用 com.android.tools.build:gradle:2.1.3 将 studio 更新到 2.13 和 gradle 到 2.14.1,这解决了原来的问题 -

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

禁用即时运行对我仍然不起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    • 2011-08-10
    • 1970-01-01
    相关资源
    最近更新 更多