app:dexDebug - UNEXPECTED TOP-LEVEL EXCEPTION - on AsyncTask

允我心安 提交于 2019-12-24 14:02:59

问题


Oh how I hate this error.

I'm getting the dreaded dexDebug error, but this time around I have no idea how to fix it.

The exact error is:

 Information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42300Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:preDexDebug
:app:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.util.ExceptionWithContext
    at com.android.dex.util.ExceptionWithContext.withContext(ExceptionWithContext.java:45)
    at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:369)
    at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)
    at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)
    at com.android.dx.command.dexer.Main.processClass(Main.java:729)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
    at com.android.dx.command.dexer.Main.access$300(Main.java:83)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)
    at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
    at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
    at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
    at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
    at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
    at com.android.dx.command.dexer.Main.processOne(Main.java:632)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)
Caused by: java.lang.NullPointerException
    at com.android.dx.cf.code.ConcreteMethod.<init>(ConcreteMethod.java:87)
    at com.android.dx.cf.code.ConcreteMethod.<init>(ConcreteMethod.java:75)
    at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:271)
    ... 24 more
...while processing <init> (Lcom/appzylabs/pratik/dailydeals/WebFragment;)V
...while processing com/appzylabs/pratik/dailydeals/WebFragment$1.class
1 error; aborting
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_71\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 16.398 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

I have only two dependencies and a fairly clean app.gradle as below:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.appzylabs.pratik.dailydeals"
        minSdkVersion 8
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"

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

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:support-v4:23.0.0'
}

Here are the things I have tried to fix this, to no avail: 1) I was including the jar for JSoup but I removed that. No help. 2) I added multidex support (multiDexEnabled true) AND android:name="android.support.multidex.MultiDexApplication" in my AndroidManifest.xml. Nada. 3) I did a clean/build, and cleared caches and restarted android studio. Again, nothing.

Note that this is happening ONLY when I am trying to run an asyncTask. If I comment out that line it compiles like a charm:

new MyLoadWebView().execute("");

What is the issue? Can someone help please?


回答1:


OK, based on Android dex issue: nested class + final boolean : com.android.dex.util.ExceptionWithContext, I figured there is something wrong with the inner class I am creating for the async task. So what I did was I changed the class declaration of the AsyncTask from private to public:

private class MyLoadWebView extends AsyncTask<String, Void, Void> { ..

to

public class MyInnerLoadWebView extends AsyncTask<String, Void, Void> { ..

And it worked!!!!

I still don't know why this is, but seems like a serious bug. Any comments?



来源:https://stackoverflow.com/questions/37113591/appdexdebug-unexpected-top-level-exception-on-asynctask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!