assDefFoundError的与Android工作室的安卓4

assDefFoundError的与Android工作室的安卓4

本文介绍了NoClassDefFoundError的与Android工作室的安卓4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在把现有的应用程序从Eclipse中的Andr​​oid Studio的过程。然而,当我在一个设备运行4.x的(我已经在模拟器测试过几个版本)运行它,它立即崩溃一个的NoClassDefFoundError

I'm in the process of converting an existing app from Eclipse to Android Studio. However, when I run it on a device running 4.x (I've tested several versions on emulators), it immediately crashes with a NoClassDefFoundError.

我已经试过注释掉引用的类无法找到,但总有另一个。至于所知道的,有问题的类总是

I've tried commenting out references to the classes it can't find, but there's always another. As far as can tell, the offending class is always

  1. 在我自己的code
  2. 在一个内部类(更新:随着越来越多的调查,这个人是不是总是正确的)
  1. Within my own code
  2. An inner class (Update: With more investigation, this one isn't always true)

一切工作正常,在5.0.1仿真器(我没有设备来测试)。我的 build.gradle 文件是相当长的,但看起来是这样的:

Everything works fine on a 5.0.1 emulator (I don't have a device to test on). My build.gradle file is fairly long, but looks like this:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

def AAVersion = "2.7.1"

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.myapp.android"
        minSdkVersion 8
        targetSdkVersion 19
        multiDexEnabled = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    packagingOptions {
        *snip*
    }
}

buildscript {
    repositories {
        mavenCentral()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

repositories {
    maven {
        url "https://repo.commonsware.com.s3.amazonaws.com"
    }
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName 'com.pact.android'
    }
}

dependencies {
    *snip compile project(':...') declarations

    apt "com.googlecode.androidannotations:androidannotations:$AAVersion"
    compile "com.googlecode.androidannotations:androidannotations-api:$AAVersion"

    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.android.support:support-v4:21.0.3'
    compile 'com.google.android.gms:play-services:3.1.36'

    *snip many more compile declarations*

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

类的一些实例引起的麻烦:

Some examples of classes that cause trouble:

  • 实现Facebook的库中的界面(库项目)匿名类
  • Parcelable.CREATOR 在我的模型实施
  • 在扩展android.os.Library内部类
  • 在我自己的code内部类
  • 在实现接口的库从行家的类
  • An anonymous class that implements an interface inside the facebook library (as a library project)
  • Parcelable.CREATOR implementations in my models
  • An inner class that extends android.os.Library
  • An inner class in my own code
  • A class that implements an interface in a library from maven

什么错误,以及如何解决呢?

What's going wrong, and how do I fix it?

推荐答案

我不完全执行MultiDex的支持,所以我的一些类没有在正确的DEX文件。为了解决这个问题,你所要做的不仅仅是建立 multiDexEnabled = TRUE defaultConfig 块。您还可以:

I was incompletely implementing MultiDex support, so some of my classes weren't in the proper dex file. To fix it, you have to do more than just set multiDexEnabled = true in your defaultConfig block. You also have to:

  1. 包含在你的依赖编译com.android.support:multidex:1.0.0
  2. 让您的应用程序类扩展的 MultiDexApplication 而不仅仅是应用程序。另外,您也可以致电 MultiDex.install() attachBaseContext()您的应用程序。
  1. Include compile 'com.android.support:multidex:1.0.0' in your dependencies
  2. Have your Application class extend MultiDexApplication instead of just Application. Alternatively, you can call MultiDex.install() in attachBaseContext() of your application.

请参阅https://developer.android.com/tools/building/multidex.html了解更多详情。

这篇关于NoClassDefFoundError的与Android工作室的安卓4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 17:07