如何修复java.lang.NoClassDefFoundError:com.mymodule.R $ array

时间:2016-01-25 15:20:50

标签: android android-studio

在没有让我的某个应用程序的项目打开大约半年后,由于应用程序启动时出现NoClassDefFoundError,我无法启动该项目。 我最后一次打开项目,一切都很顺利。应用程序构建似乎很好,没有任何例外。 Android Studio没有向我显示源代码内的任何错误(没有任何文件的红色下划线或文件的任何行 - 我已打开它们,以防万一)。如果我在R.array.xyz元素上按ctrl + b,android studio会打开带有该元素的字符串文件。

但是当访问R.array字段时,我得到了一个:

java.lang.RuntimeException: An error occured while executing doInBackground()
  at android.os.AsyncTask$3.done(AsyncTask.java:278)
  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
  at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.NoClassDefFoundError: com.abc.xyz.R$array
  at com.myapp.aClass.createContainerList(aClass.java:323)

命令是:

        String[] Fehlerklassen = context.getResources().getStringArray(R.array.someStrArray);

,导入是:

import com.myapp.moduleOfClass.R; 

再次:Android Studio说一切都很好。如果我使用自动完成,例如R.array。,它为我提供了正确的数组

删除对R.array的每次访问,R.drawable都会出现同样的错误。同时,Android Studio会在文本编辑器中显示正确图像的缩略图。

相关模块的build.gradle文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    compileOptions.encoding = 'windows-1252'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile project(':aModuleThatWorksFineInAnotherProject1')
    compile project(':aModuleThatWorksFineInAnotherProject2')
    compile project(':aModuleThatWorksFineInAnotherProject3')
    compile project(':aModuleThatWorksFineInAnotherProject4')
}

在构建应用程序后,gradle控制台仅包含两条红色消息。两者都可能没有错。

第一个也显示在另一个应用程序中,工作正常:

AGPBI: {"kind":"SIMPLE","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","position":{},"original":"warning: Ignoring InnerClasses attribute for an anonymous inner class"}
AGPBI: {"kind":"SIMPLE","text":"(org.ksoap2.transport.KeepAliveHttpsTransportSE$1) that doesn\u0027t come with an","position":{},"original":"(org.ksoap2.transport.KeepAliveHttpsTransportSE$1) that doesn\u0027t come with an"}
AGPBI: {"kind":"SIMPLE","text":"associated EnclosingMethod attribute. This class was probably produced by a","position":{},"original":"associated EnclosingMethod attribute. This class was probably produced by a"}
AGPBI: {"kind":"SIMPLE","text":"compiler that did not target the modern .class file format. The recommended","position":{},"original":"compiler that did not target the modern .class file format. The recommended"}
AGPBI: {"kind":"SIMPLE","text":"solution is to recompile the class from source, using an up-to-date compiler","position":{},"original":"solution is to recompile the class from source, using an up-to-date compiler"}
AGPBI: {"kind":"SIMPLE","text":"and without specifying any \"-target\" type options. The consequence of ignoring","position":{},"original":"and without specifying any \"-target\" type options. The consequence of ignoring"}
AGPBI: {"kind":"SIMPLE","text":"this warning is that reflective operations on this class will incorrectly","position":{},"original":"this warning is that reflective operations on this class will incorrectly"}
AGPBI: {"kind":"SIMPLE","text":"indicate that it is *not* an inner class.","position":{},"original":"indicate that it is *not* an inner class."}

,第二个是根据其他stackoverflow线程不是真正的错误,但更多的挑剔输出。对于我的一些图像我得到:

AAPT err(1171159410): C:\Users\myName\AndroidStudioProjects\myproject\someName\build\intermediates\bundles\debug\res\drawable-mdpi\edit_query.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited

1 个答案:

答案 0 :(得分:0)

解决方案是扩展MultiDexApplication而不是Application 以及来设置multidexenabled为true。有关详细信息,请参阅https://stackoverflow.com/a/30266339/1171328