3

今天我遇到了一個大規模的錯誤,不允許我在手機上運行示例項目。Android Studio意外的頂級例外:

當Android的工作室正在建設的項目,它首先說明了以下目標爲UP-TO-DATE

.... 
:demoproject:processDebugResources UP-TO-DATE 
:demoproject:generateDebugSources UP-TO-DATE 
:demoproject:compileDebugJava UP-TO-DATE 
:demoproject:proguardDebug UP-TO-DATE 
.... 

有幾十個在生成過程中這些UP-TO-DATE日誌報表。然而,他們總是停在:demoproject:dexDebug。對於dexDebug,我似乎從未得到UP-TO-DATE日誌語句。

相反,dexDebug後跟此錯誤:

:demoproject:dexDebug 
warning: Ignoring InnerClasses attribute for an anonymous inner class 
(com.xyz.corp.sample.project.demo.a) that doesn't come with an 
associated EnclosingMethod attribute. This class was probably produced by a 
compiler that did not target the modern .class file format. The recommended 
solution is to recompile the class from source, using an up-to-date compiler 
and without specifying any "-target" type options. The consequence of ignoring 
this warning is that reflective operations on this class will incorrectly 
indicate that it is *not* an inner class. 

現在有幾十個,這些Ignoring InnerClasses attribute錯誤。它們甚至發生在v4支持庫中的類中,這真是令人困惑。

最後,這些錯誤有一個新的語句結尾:

UNEXPECTED TOP-LEVEL EXCEPTION: 
at com.android.dx.command.dexer.Main.access$300(Main.java:83) 
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472) 
at com.android.dx.command.dexer.Main.main(Main.java:215) 
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280) 
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) 
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406) 
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602) 
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) 
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284) 
at com.android.dx.command.dexer.Main.run(Main.java:246) 
at com.android.dx.command.dexer.Main.processOne(Main.java:632) 
at com.android.dx.command.Main.main(Main.java:106) 
...while parsing com/xyz/corp/sdk/AbcSDKConfig.class 
1 error; aborting 
Error:Execution failed for task ':demoproject:dexDebug'. 
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 1 
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000) 
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673) 
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388) 
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510) 
...while parsing com/xyz/corp/sdk/AbcSDKConfig.class 
1 error; aborting 
at com.android.dx.command.dexer.Main.processClass(Main.java:704) 
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251) 

我已經諮詢了以下鏈接:

Gradle finished with non-zero exit value 1

2.What is the 「Ignoring InnerClasses attribute」 warning output during compilation?

我不確定它們是否適用於我的情況。我甚至沒有能夠運行該項目。我已將我的IDE更新到SDK Tools 22.0.1,並在我的build.gradle文件中修改了buildToolsVersion標記,但無濟於事。有人可以指導我如何處理這個錯誤?所有的幫助將不勝感激。

哦,這裏是我的build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 22 
    buildToolsVersion '22.0.1' 

    packagingOptions { 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/NOTICE' 
    } 

    defaultConfig { 
     applicationId "com.xyz.corp.demo.project" 
     minSdkVersion 10 
     targetSdkVersion 22 

     versionCode 2060200 
     versionName '2.6.02.00' 
    } 

    buildTypes { 
     debug { 

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

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

      applicationVariants.all { variant -> 
       variant.outputs.each { output -> 
        def file = output.outputFile 
        output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk")) 
       } 
      } 
     } 
    } 
} 

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

    compile project(':xyzSDK') 
} 

幫助!

+0

你能重新啓動你的工作室/機器,並重建你的項目 – Sree

+0

什麼是你的Java版本? 1.8?如果是這樣,請回滾到1.7 – Nizam

+0

@NoName:我在錯誤之前描述了日誌:很多很多'UP-TO-DATE'語句。 'dexDebug'檢查沒有得到'UP-TO-DATE'語句;它接着是上面的日誌。這對你來說夠了嗎?不,我還沒有檢查multidex問題呢... –

回答

1

因爲這是報告:bad class file magic (cafebabe) or version (0034.0000)您應該檢查您是否正在使用與您嘗試在運行時使用相同的Java版本進行編譯。 如果您正在使用gradle這個你應該在你的build.gradle文件中使用以下或類似的條目:

apply plugin: 'java' 
sourceCompatibility = 1.7 
targetCompatibility = 1.7 

使用此link更多細節的gradle。

在Android Studio中,從File -> Project Structure -> SDK Location -> JDK Location開始,您應該使用jdk 1.7而不是在Project level設置上繼電器。請參閱link以瞭解類似的Android Studio問題。

+0

有趣。謝謝你的答案。讓我試試看,回到你身邊...... :) –

+0

在此期間,我有一個問題。我必須將這個SDK集成到使用Java 1.8的主項目中,並且我寧願保持這種狀態。我有沒有辦法用1.8編譯這個項目? –

+0

您應該能夠使用1.8進行編譯,但targetCompatibility應該設置爲1.7。這樣的二進制文件將是1.7兼容。 – dan

0

看來你文件夾&庫項目xyzSDK包含相同的庫,這是造成問題,同時轉換爲DEX

你可以嘗試找出這樣的庫,並從一個地方將其刪除。 或排除像這樣

compile project(':xyzSDK'){ 
     exclude module: 'support-v4' 
    } 

我已經採取了例如支持-V4的,因爲我已經遇到了類似的問題,因爲這個以前。

+0

謝謝你的答案。這確實是問題所在。你是否因爲我得到了完全相同的錯誤? –

+0

是的..意外的頂級例外: – Akhil

1

UNEXPECTED TOP-LEVEL EXCEPTION意味着您將收到兩次任何.jar

由於@Akhil說你應該排除support-v4,因爲我猜這是主要問題,但是如果@Akhil答案不能幫助你嘗試這種方法。

compile (':xyzSDK') { 
    exclude group: 'com.android.support', module: 'support-v4' 
} 

您是否嘗試刪除此行?

compile 'com.android.support:appcompat-v7:22.1.0' 

也許:xyzSDK媒體鏈接有appcompat-v7:22+ ..

我給你那裏good answer by @CommonsWare做出gradle這個報告,看看有什麼問題。

我正在爲您的答案工作,所以如果我找到interessant,我會更新我的答案。

一旦你做到了這一點,你必須Build -> Rebuild project

而且我在@丹回答看見......我讓你有可能answer

而不是1.7丹說嘗試:

compileOptions { 

    sourceCompatibility JavaVersion.VERSION_1_7 
    targetCompatibility JavaVersion.VERSION_1_7 
} 

否則,你可以檢查一下手動去File > Project Structure按Ctrl + Alt鍵 + + 小號,然後在JDK location看看你在用什麼,如果你正在使用1.8更改到你的1.7 SDK路徑

而btw我認爲我讀過,你問過你是否可以使用JAVA 8代替Android,而不是JAVA 7,如果我沒有錯誤的話......和是的,你可以使用​​,但前提是你也使用gradle-retrolamba就像在這個question上說的那樣。

+0

我現在接受這個答案,但我還沒有完成它。我需要重新檢查這個問題並做更多的研究...... :) –

相關問題