Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Can't build Android in Unity: UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: a

Discussion in 'Android' started by KarlShifflett, Jun 15, 2015.

  1. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38
    I have read this post: http://forum.unity3d.com/threads/ob...ets-plugins-android-res-is-deprecated.315889/ Didn't help.

    I have the latest version of Android Studio.

    I have an Android Library for my Unity3D plugin.

    I have to reference classes.jar in : C:\Program Files\Unity\Editor\Data\PlaybackEngines\androidplayer\release\bin

    My plugin class extends BroadcastReceiver.

    Inside a method I call: Activity currentActivity = UnityPlayer.currentActivity;

    My question is: how can I NOT include the referenced classes.jar in my "aar" file?

    I'm using an "aar" file because this is recommended over a ".jar" file implementation. I was trying to use a ".jar" file but was unable to get any of my images in the /res folder to be added to the ".jar"

    So I'm going with the recommended library approach. But now, I'm getting the below TOP-LEVEL-EXCEPTION.

    I only have a single reference in the /libs folder. I'm 100% sure I'm not referencing it twice in my library.

    What can I do?


    Thank you so very much!

    Karl

    CommandInvokationFailure: Unable to convert classes into dex format. See the Console for details.
    C:\Program Files\Java\jdk1.8.0_45\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/Users/mole/AppData/Local/Android/sdk\tools" -Dfile.encoding=UTF8 -jar "C:/Program Files/Unity/Editor/Data/BuildTargetTools/AndroidPlayer\sdktools.jar" -

    stderr[

    UNEXPECTED TOP-LEVEL EXCEPTION:
    java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/a$1;
    at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
    at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
    at com.android.dx.command.dexer.Main.processClass(Main.java:732)
    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.processArchive(ClassPathOpener.java:284)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
    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)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at SDKMain.main(SDKMain.java:129)
    1 error; aborting
    ]
    stdout[
    processing archive bin\classes.jar...
    processing com/unity3d/player/a$1.class...
    processing com/unity3d/player/a$2.class...
    processing com/unity3d/player/a$a.class...
    processing com/unity3d/player/a.class...
    processing com/unity3d/player/b$1.class...
    processing com/unity3d/player/b$2.class...
    processing com/unity3d/player/b.class...
    processing com/unity3d/player/c.class...
    processing com/unity3d/player/d$1.class...
    processing com/unity3d/player/d$2.class...
    processing com/unity3d/player/d.class...
    processing com/unity3d/player/e.class...
    processing com/unity3d/player/f.class...
    processing com/unity3d/player/g.class...
    processing com/unity3d/player/h.class...
    processing com/unity3d/player/i.class...
    processing com/unity3d/player/j$1.class...
    processing com/unity3d/player/j$2$1$1.class...
    processing com/unity3d/player/j$2$1.class...
    processing com/unity3d/player/j$2.class...
    processing com/unity3d/player/j.class...
    processing com/unity3d/player/k$1.class...
    processing com/unity3d/player/k.class...
    processing com/unity3d/player/l.class...
    processing com/unity3d/player/m.class...
    processing com/unity3d/player/n$1.class...
    processing com/unity3d/player/n.class...
    processing com/unity3d/player/NativeLoader.class...
    processing com/unity3d/player/o.class...
    processing com/unity3d/player/ReflectionHelper$1.class...
    processing com/unity3d/player/ReflectionHelper$a.class...
    processing com/unity3d/player/ReflectionHelper.class...
    processing com/unity3d/player/p.class...
    processing com/unity3d/player/q$1.class...
    processing com/unity3d/player/q$2.class...
    processing com/unity3d/player/q$3.class...
    processing com/unity3d/player/q.class...
    processing com/unity3d/player/r.class...
    processing com/unity3d/player/s.class...
    processing com/unity3d/player/UnityPlayer$1.class...
    processing com/unity3d/player/UnityPlayer$2.class...
    processing com/unity3d/player/UnityPlayer$4.class...
    processing com/unity3d/player/UnityPlayer$5.class...
    processing com/unity3d/player/UnityPlayer$6.class...
    processing com/unity3d/player/UnityPlayer$7.class...
    processing com/unity3d/player/UnityPlayer$8.class...
    processing com/unity3d/player/UnityPlayer$9.class...
    processing com/unity3d/player/UnityPlayer$10.class...
    processing com/unity3d/player/UnityPlayer$11.class...
    processing com/unity3d/player/UnityPlayer$12.class...
    processing com/unity3d/player/UnityPlayer$13$1.class...
    processing com/unity3d/player/UnityPlayer$13.class...
    processing com/unity3d/player/UnityPlayer$3.class...
    processing com/unity3d/player/UnityPlayer$14.class...
    processing com/unity3d/player/UnityPlayer$15.class...
    processing com/unity3d/player/UnityPlayer$16.class...
    processing com/unity3d/player/UnityPlayer$17.class...
    processing com/unity3d/player/UnityPlayer$18.class...
    processing com/unity3d/player/UnityPlayer$19.class...
    processing com/unity3d/player/UnityPlayer$a.class...
    processing com/unity3d/player/UnityPlayer$b.class...
    processing com/unity3d/player/UnityPlayer$c.class...
    processing com/unity3d/player/UnityPlayer.class...
    processing com/unity3d/player/UnityPlayerActivity.class...
    processing com/unity3d/player/UnityPlayerNativeActivity.class...
    processing com/unity3d/player/UnityPlayerProxyActivity.class...
    processing com/unity3d/player/t.class...
    processing com/unity3d/player/u$1.class...
    processing com/unity3d/player/u.class...
    processing com/unity3d/player/WWW.class...
    processing org/fmod/FMODAudioDevice$a.class...
    processing org/fmod/FMODAudioDevice.class...
    processing org/fmod/a.class...
    processing bin\classes\.\com\karlshifflett\notificationHelpMe\R$attr.class...
    processing bin\classes\.\com\karlshifflett\notificationHelpMe\R$drawable.class...
    processing bin\classes\.\com\karlshifflett\notificationHelpMe\R$mipmap.class...
    processing bin\classes\.\com\karlshifflett\notificationHelpMe\R$string.class...
    processing bin\classes\.\com\karlshifflett\notificationHelpMe\R.class...
    processing bin\classes\.\com\karlshifflett\notificationlibrary\R$attr.class...
    processing bin\classes\.\com\karlshifflett\notificationlibrary\R$drawable.class...
    processing bin\classes\.\com\karlshifflett\notificationlibrary\R$mipmap.class...
    processing bin\classes\.\com\karlshifflett\notificationlibrary\R$string.class...
    processing bin\classes\.\com\karlshifflett\notificationlibrary\R.class...
    processing archive C:\Unity3d\Logical Advantage\NotificationHell\Temp\StagingArea\android-libraries\notificationlibrary-debug\libs\.\classes.jar...
    processing com/unity3d/player/a$1.class...
    processing archive C:\Unity3d\Logical Advantage\NotificationHell\Temp\StagingArea\android-libraries\notificationlibrary-debug\bin\classes.jar...
    ignored resource META-INF/MANIFEST.MF
    processing com/karlshifflett/notificationlibrary/BuildConfig.class...
    processing com/karlshifflett/notificationlibrary/UnityNotificationManager.class...
    ]
    UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.Android.AndroidSDKTools.RunCommandInternal (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.Android.AndroidSDKTools.RunCommandSafe (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
    UnityEditor.HostView:OnGUI()
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,333
    Are you sure you don't have 2 copies of classes.jar in your UNITY project?
     
  3. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38
    Thank you for the reply.

    Yes. The real question is, how can I build my Android library and not include the classes.jar in the "aar" file. Many others have asked the same question.

    I've tried for so many hours to figure this out, without any success.

    Seems strange that Unity does not allow multiple "aar" library files to contain their dependencies. I wish there was a way to reference the Unity classes.jar without having it packaged in the "aar" library. Seems like a very standard workflow for developers.
     
  4. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38
    I do have 7 .jar files in my Unity project. One of them "could" be including the "classes.jar".

    So its up to me to be a good player, and not include "classes.jar" in my library. This seems like such a simple task.

    Best,

    Karl
     
  5. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,333
    You should make sure your project doesn't include the same JAR twice, and also not include the classes.jar file.

    Regarding the .aar - how are you creating it ? Could you share the grafle build file ?
     
    Last edited: Jan 13, 2016
  6. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38
    I'm using Android Studio. It's including the classes.jar file.
     
  7. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,333
    How did you add classes.jar as a dependency ?
    The build process uses gradle (you have a build.gradle file) that Android Studio uses to build your project.
    Can you please check the contents of this file, specifically relating to classes.jar
     
  8. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38
    I copied the classes.jar file into the /libs folder. Then right clicked on it and added as library. It updated the build.gradle file for me.

    Is there another way to reference the classes.jar?
     
  9. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,333
    Set the dependency's scope to "Provided" :
    upload_2015-6-16_21-58-28.png

    Go to your library project, right click and select "Module settings" and from there set this under Dependencies.

    Let me know if that helped.
     
  10. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38
    Get back to you soon. Thank you so very much.
     
  11. KarlShifflett

    KarlShifflett

    Joined:
    Feb 27, 2015
    Posts:
    38
    yes, this fixed the problem. Thank you so very much!
     
  12. scone

    scone

    Joined:
    May 21, 2008
    Posts:
    244
    Just a quick update on this guy: If you're extending the UnityPlayerActivity class, you'll be wanting to also set the include ['*.jar'] yadda yadda dependency to "provided" as well.
     
    unity_2iF5vx8QEKsZ7A likes this.
  13. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,692
    getting the same error.
    i made a new unity project exported it to android studio, where i get a unity-classes.jar in the libs folder.
    I have only add one simple function to the UnityPlayerActivity class, build the project and copy the unity-classes.jar together with the Manifest.xml.
    i wrote a simple testing script in unity and try to build the project to my phone. but get the exact same error as in this thread.
    I've build android plugins before with eclipse and am getting confused with the new manner of exporting to android studio.
    also tried the solution changing the dependency to provided but that didn't fix it.
     
  14. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,692
    nevermind, i shouldn't use unity-classes as jar :)
     
  15. capacitate

    capacitate

    Joined:
    Jan 7, 2016
    Posts:
    2
    Although following the above, you got error, please check up your android app:graddle
    change below
    compile filetree(include:['*.jar'], dir:'libs')​
    to
    compile filetree(dir:'libs', include:['*.jar'], exclude:['classes.jar'])​
     
  16. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,692
    Hey, just for people having trouble working with this, here's a bit of a step by step guide...
     
  17. capacitate

    capacitate

    Joined:
    Jan 7, 2016
    Posts:
    2
    One more, if you try aar plugin,
    you can open .aar file into a zip file and check out /libs/ folder
    If you have classes.jar file in your /libs/ folder, then get rid of it.
    Then build your project on Unity
     
  18. bpritchard

    bpritchard

    Joined:
    Jan 29, 2009
    Posts:
    444
    Hey all, I'm having this issue as well (likely due to the setup). I've not used gradle before coming from an ant bg so bear w/me. Basically I've an existing sdk that i'm working on integrating... and am getting similar errors as noted in this thread.

    Code (CSharp):
    1.  
    2. CommandInvokationFailure: Unable to convert classes into dex format. See the Console for details.
    3. C:/Program Files/Java/jdk1.8.0_65\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/Program Files (x86)/Android/android-sdk\tools" -Dfile.encoding=UTF8 -jar "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\sdktools.jar" -
    4.  
    5. stderr[
    6. Uncaught translation error: java.lang.IllegalArgumentException: already added: Lbitter/jnibridge/JNIBridge$a;
    7. Uncaught translation error: java.lang.IllegalArgumentException: already added: Lbitter/jnibridge/JNIBridge;
    8. Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/NativeLoader;
    9. Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/ReflectionHelper$1;
    10. Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/ReflectionHelper$a;
    11. Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/ReflectionHelper;
    12. Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/UnityPlayer$1;
    13. Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/UnityPlayer$10;
    14. Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/UnityPlayer$11;
    15.  
    16. UNEXPECTED TOP-LEVEL EXCEPTION:
    17. java.lang.RuntimeException: Translation has been interrupted
    18.     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:608)
    19.     at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
    20.     at com.android.dx.command.dexer.Main.run(Main.java:277)
    21.     at com.android.dx.command.dexer.Main.main(Main.java:245)
    22.     at com.android.dx.command.Main.main(Main.java:106)
    23.     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    24.     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    25.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    26.     at java.lang.reflect.Method.invoke(Method.java:497)
    27.     at SDKMain.main(SDKMain.java:129)
    28. Caused by: java.lang.InterruptedException: Too many errors
    29.     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:600)
    30.     ... 9 more
    31. ]
    32.  
    I didn't include the full stack above because its pretty much the same as everyone else's. Here's what my setup looks like in relation to the classes files..

    upload_2016-1-10_12-35-56.png

    I've got classes.jar added as a library as well, and have it set to Provided and not compiled. Everything builds outta Android studio just fint BUT when i build unity I get the duplicate errors. I've also dug into the JAR and do see the libraries from classes compiled in.

    Am I missing anything? A step perhaps i didn't take? If i don't include the library (and remove my wrapper) the jar compiles file, unity loads it fine, and i'm able to call to the file w/o the app breaking (of course the sdk doesn't work because its not extending unity).
     
  19. bpritchard

    bpritchard

    Joined:
    Jan 29, 2009
    Posts:
    444
    Able to get it to build properly now with the exclude addition to the gradle files.. but now I get a more interesting error... basically it can find my initial call but then the subsequent library calls (within the SDK) are missing. I see them in the JAR and everything IS there but for instance here's one of the errors...

    Code (CSharp):
    1. 01-11 06:33:36.124: W/dalvikvm(11325): VFY: unable to resolve static method 6358: Lnet/danlew/android/joda/JodaTimeAndroid;.init (Landroid/content/Context;)V
    2. 01-11 06:33:36.124: W/dalvikvm(11325): Unable to resolve superclass of Lcom/jr/sdk/views/activities/LoginActivity; (155)
    3. 01-11 06:33:36.124: W/dalvikvm(11325): Link of class 'Lcom/jr/sdk/views/activities/LoginActivity;' failed
    4. 01-11 06:33:36.124: E/dalvikvm(11325): Could not find class 'com.jr.sdk.views.activities.LoginActivity', referenced from method com.jr.sdk.JR.showDashboard
    5. 01-11 06:33:36.124: W/dalvikvm(11325): VFY: unable to resolve const-class 642 (Lcom/jr/sdk/views/activities/LoginActivity;) in Lcom/jr/sdk/JR;
    6.  
    Here's my manifest..
    Code (CSharp):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.       package="com.jr.spacearcade"
    4.       android:versionCode="1"
    5.       android:versionName="1.0">
    6.     <uses-sdk android:minSdkVersion="9" />
    7.     <application android:label="@string/app_name">
    8.         <activity android:name="com.jr.sdk.UnityJR"
    9.                   android:label="@string/app_name">
    10.             <intent-filter>
    11.                 <action android:name="android.intent.action.MAIN" />
    12.                 <category android:name="android.intent.category.LAUNCHER" />
    13.             </intent-filter>
    14.         </activity>
    15.     </application>
    16. </manifest>
    17.  
    And the call i'm using from within Unity..
    Code (CSharp):
    1.         AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
    2.         AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject> ("currentActivity");
    3.         currentActivity.Call ("UnityInit", APIKey);
    That hits the jar for sure, because its starting the INIT process from the original SDK but from there it all falls apart. Maybe i'm approaching this all wrong? Any suggestions on how to get the unity project to communicate wholly with a jar that includes a bunch of functionality?

    many thanks!
    Bryan