Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve UNEXPECTED TOP-LEVEL EXCEPTION in Android Studio

I have two projects that share the same aidl file.

In the first project, the build runs to completion in Eclipse and Android Studio.

In the second project, the build runs to completion in Eclipse, BUT in Android Studio I see:

Error:[Tracker-PRO-Key] UNEXPECTED TOP-LEVEL EXCEPTION:
Error:[Tracker-PRO-Key] com.android.dx.util.ExceptionWithContext
Error:[Tracker-PRO-Key] at com.android.dx.util.ExceptionWithContext.withContext(ExceptionWithContext.java:46)
Error:[Tracker-PRO-Key] at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:344)
Error:[Tracker-PRO-Key] at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:134)
Error:[Tracker-PRO-Key] at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:87)
Error:[Tracker-PRO-Key] at com.android.dx.command.dexer.Main.processClass(Main.java:487)
Error:[Tracker-PRO-Key] at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
Error:[Tracker-PRO-Key] at com.android.dx.command.dexer.Main.access$400(Main.java:67)
Error:[Tracker-PRO-Key] at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
Error:[Tracker-PRO-Key] at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:135)
Error:[Tracker-PRO-Key] at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
Error:[Tracker-PRO-Key] at com.android.dx.command.dexer.Main.processOne(Main.java:422)
Error:[Tracker-PRO-Key] at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
Error:[Tracker-PRO-Key] at com.android.dx.command.dexer.Main.run(Main.java:209)
Error:[Tracker-PRO-Key] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Error:[Tracker-PRO-Key] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
Error:[Tracker-PRO-Key] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Error:[Tracker-PRO-Key] at java.lang.reflect.Method.invoke(Method.java:606)
Error:[Tracker-PRO-Key] at org.jetbrains.android.compiler.tools.AndroidDxRunner.runDex(AndroidDxRunner.java:139)
Error:[Tracker-PRO-Key] at org.jetbrains.android.compiler.tools.AndroidDxRunner.main(AndroidDxRunner.java:261)
Error:[Tracker-PRO-Key] at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:121)
Error:[Tracker-PRO-Key] Caused by: java.lang.NullPointerException
Error:[Tracker-PRO-Key] at com.android.dx.cf.code.ConcreteMethod.<init>(ConcreteMethod.java:87)
Error:[Tracker-PRO-Key] at com.android.dx.cf.code.ConcreteMethod.<init>(ConcreteMethod.java:75)
Error:[Tracker-PRO-Key] at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:247)
Error:[Tracker-PRO-Key] ... 22 more
Error:[Tracker-PRO-Key] ...while processing <init> (Lcom/DynaZu/Tracker/Prokey/MainActivity;)V
Error:[Tracker-PRO-Key] ...while processing /home/joel/workspace/Tracker-PRO-Key/out/production/Tracker-PRO-Key/com/DynaZu/Tracker/Prokey/MainActivity$1.class
Error:[Tracker-PRO-Key] 1 error; aborting

The aidl file is extremely simple:

package com.DynaZu.Tracker.Prokey;
interface IProKEYComm {
    long getLicenseInfo();
}

HOW to determine the problem???? What causes this? I am using com.google.android.vending.licensing. Could this be related?
I have seen problems where a library is included twice (with different versions), but this doesn't seem to be the issue here. Any ideas would be greatly appreciated!

like image 620
JoelParke Avatar asked Jul 02 '13 23:07

JoelParke


1 Answers

After months of fighting this exact problem, I have finally found a solution that works for me. It might not be your case. Make sure, that none of the classes you are using (in your case, it is probably the interface itself, since I don't see any others) is private. The Gradle is not able to handle it and cannot find the methods within the class. Just change it to public (in case of nested classes, you only need to remove the flag to make it default), and you should be good to go.

like image 190
Johny_G Avatar answered Oct 31 '22 17:10

Johny_G