Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

game won't build after importing unity ads

Discussion in 'Unity Ads' started by mcconrad, Sep 25, 2014.

  1. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    after importing unity ads, the game will play fine in the editor, even loading the default dummy ad for testing, but will not build. gives error:
    Error building Player: Win32Exception: ApplicationName='C:\Program Files (x86)\Java\jre1.8.0_20\bin\javac.exe', CommandLine='-bootclasspath "C:/Users/C/Android SDK/sdk/platforms/android-20\android.jar" -d "C:\Users\C\Documents\MyGame\Temp\StagingArea\bin\classes" -source 1.6 -target 1.6 -encoding UTF-8 "com\unity3d\ads\android\R.java" "com\unity3d\tester\R.java"', CurrentDirectory='C:\Users\C\Documents\MyGame\Temp\StagingArea\gen'

    i have even deleted the game objects containing the ad scripts and still get error. cannot continue working on the project unless i delete all unity ads objects, but hoping there is a fix before i have to resort to that.

    EDIT: deleted all unity ads folders and objects and game builds fine, so there is def. a problem with unity ads and android
     
    Last edited: Sep 25, 2014
  2. fivearchers

    fivearchers

    Joined:
    Apr 17, 2009
    Posts:
    716
    Exact same problem here!
     
  3. fivearchers

    fivearchers

    Joined:
    Apr 17, 2009
    Posts:
    716
    Also i get the exact same error when trying to use Chartboost
     
  4. hamstar

    hamstar

    Joined:
    Sep 25, 2013
    Posts:
    82
    I have a feeling that this might be caused by duplicate .jar files, but I could be wrong.

    Try searching for all jar files and delete any duplicates. Sometimes different plugins import the same jar files.
     
  5. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Hmm, the mention of "game objects with ad scripts" is throwing a red flag for me. Are you using the latest version of the Unity Ads asset package? Before importing the new package, first delete the old package assets from your project.

    Could you try it again with a fresh import of the asset package?

    If you're interested, here's a link to the demo script I use to make sure everything works:
    https://gist.github.com/wcoastsands/3d003528a76f94fa2ede

    Let me know how it works out for you guys.
     
  6. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    it was a fresh import from whatever asset was live in the unity store as of this morning. no old packages to delete. as for the GO's, they were just buttons that referenced and turned on/off the ads. the scripts aren't the problem as they play fine, the error occurs during build and is some kind of conflict with the android SDK.

    EDIT: just reimported it again and made a build before touching anything after import and got the build error.
     
    Last edited: Sep 25, 2014
  7. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Thanks, for the info. Still trying to reproduce the issue here. What other packages are you using?
     
  8. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    the only *.jar files in my entire project are from unity ads. nothing else has that kind of build access to the SDK.
     
  9. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Getting the same error on my side. I'll try to get an answer for you guys here soon.

    Thanks for the heads up!
     
  10. HeikkiTunkelo

    HeikkiTunkelo

    Unity Technologies

    Joined:
    May 13, 2014
    Posts:
    104
    Hi guys!

    Noticed this line on the error message:

    ....C:\Program Files (x86)\Java\jre1.8.0_20\bin\javac.exe...

    It seems that Unity is trying to build with Java Runtime Environment, and not with Android SDK.

    Please check out this:
    http://docs.unity3d.com/Manual/android-sdksetup.html

    If you already have Android SDK setup, and still get this error make sure that Unity is actually using the correct path:

    -- (shameless copy & paste) --
    4. Add the Android SDK path to Unity
    The first time you build a project for Android (or if Unity later fails to locate the SDK) you will be asked to locate the folder where you installed the Android SDK (you should select the root folder of the SDK installation). The location of the Android SDK can also be changed in the editor by selecting Unity > Preferences from the menu and then clicking on External Tools in the preferences window.
     
  11. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    i have been building android games for a year now and this only became a problem when i imported unity ads and goes away immediately when i remove it, so that is not the issue, but ty.

    however, it does use the JRE because unity ads is built into a .jar file.
     
  12. HeikkiTunkelo

    HeikkiTunkelo

    Unity Technologies

    Joined:
    May 13, 2014
    Posts:
    104
    Ok, thanks for the info.

    And changing the path had no effect?

    I'll bump investigating this up in priority.

    Cheers,
    Heikki
     
  13. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    however, if unity ads were looking for the JRE in the wrong location (i dont remember having an option to set it) or were erroneously using the JRE instead of the android SDK (and i have no inner knowledge of how the two communicate), then that could be the issue.

    EDIT: in fact that IS the issue. there is no file by that name. no javac.exe. the java compiler is javacpl.exe. Good eyes, Heikki!
     
    Last edited: Sep 26, 2014
  14. HeikkiTunkelo

    HeikkiTunkelo

    Unity Technologies

    Joined:
    May 13, 2014
    Posts:
    104
    Just one clarification, so that I don't misunderstand:

    1. You were able to build the same project to android before you used the ads-plugin?
    2. With the ads plugin the same project gave the error message?
    3. When you removed the ads plugin it compiled again?

    Heikki
     
  15. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    yes to all 3.

    the ads plugin is looking for a file that does not exist. there is no javac.exe. the java compiler is javacpl.exe

    EDIT: not the compiler, but nonetheless there is no javac.exe file
     
    Last edited: Sep 26, 2014
  16. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    So, I was reproducing this issue. I checked the system PATH, which was missing the path to the JDK bin directory.

    Added the following to PATH and was able to build without the error:
    C:\Program Files\Java\jdk1.8.0_20\bin

    Can you confirm?
     
    HeikkiTunkelo likes this.
  17. HeikkiTunkelo

    HeikkiTunkelo

    Unity Technologies

    Joined:
    May 13, 2014
    Posts:
    104
    Well that is weird,

    There is no compiler (and shouldn't be) on JRE. The "javacpl.exe" is Java control panel and doesn't really help with compiling ;) http://www.java.com/en/download/help/win_controlpanel.xml

    Just importing the plugin shouldn't change what is used to build your game.

    Could you check where your JAVA_HOME environment variable points to?
     
  18. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    there was no PATH variable, so i create one that points to the java bin directory. however, it is still looking for a file that does not exist. there is no javac.exe:

    ApplicationName='C:\Program Files (x86)\Java\jre1.8.0_20\bin\javac.exe',
     
  19. HeikkiTunkelo

    HeikkiTunkelo

    Unity Technologies

    Joined:
    May 13, 2014
    Posts:
    104
    What happens if you point it to the Android SDK's bin directory?

    That should definitely have the javac.
     
  20. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
  21. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Which version of windows are you running?

    Also, the path your pointing to is the runtime, not the SDK:
    C:\Program Files (x86)\Java\jre1.8.0_20\bin

    Make sure you point to the SDK. I currently have the x64 version, located at:
    C:\Program Files\Java\jdk1.8.0_20\bin

    ...which does include javac.exe.
     
  22. HeikkiTunkelo

    HeikkiTunkelo

    Unity Technologies

    Joined:
    May 13, 2014
    Posts:
    104
    Yes, that is correct. The compiler is only available on JDK (and android SDK), not on the runtime environment.

    You said you were able to build the same project for android without ads. Now I'm wondering how was this possible if you don't have android SDK nor JDK in your computer.

    Did you actually manage to build an APK and install it to your device?
     
  23. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    so to clarify, i need the JDK to run unity ads?

    EDIT: i HAVE the JDK, but i am running 64 bit so it is not located in ProgramFiles(x86) but in plain ProgramFiles

    EDIT2: changed the PATH variable to point to the JDK, but the either the Android SDK or the ads plugin is still looking at the JRE directory.

    running windows 8 64 bit.
     
    Last edited: Sep 26, 2014
  24. HeikkiTunkelo

    HeikkiTunkelo

    Unity Technologies

    Joined:
    May 13, 2014
    Posts:
    104
    No worries, I can definitely understand your frustration.

    I'm myself on a mac, so I'm shooting in the dark a bit. (And the guys who actually know about the android build are already off for the weekend).

    Last I checked they were able to build on Windows without any additional steps.
     
  25. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    I've got a Windows 8 install here. Just set it up in order to repro.

    Yeah, you should have the Java Development Kit (JDK) installed to even be able build to Android. Not sure how you were able to build otherwise. The Android SDK installation usually requires you to install the JDK before continuing.

    Now, there are both x86 and x64 versions of the Java Development Kit. If you're not seeing it under C:\Program Files (x86), be sure to check for it under C:\Program Files, which is where x64 applications get installed.

    I have the 64-bit version, with javac.exe located at:
    C:\Program Files\Java\jdk1.8.0_20\bin
     
  26. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Ah, just seeing this.

    You also need to log out of your Windows session and log back in for any path changes take effect.
     
  27. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    i have the JDK, for 64 bit. unity is looking at the JRE folder instead of it.
    i have added JAVA, JAVA_HOME, to the system environment variables, pointing to the JDK bin directory. the error message is still referencing the JRE location.

    the PATH system variable is occupied by nVidia. i have a PATH user variable that points to the JDK.

    i will trying rebooting to see if that works. thank you
     
  28. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    the problem persists after reboot. it is still looking at the JRE directory
     
  29. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    After creating your environment variables, you need to make sure to add them to your path.

    Using your variables for instance:
    %JAVA%;%JAVA_HOME%;

    Once added to your path, log out and back it, should work.

    Edit:
    Also, be sure to add it to the beginning of your path, just so that it checks those first.

    Edit 2:
    Important note, user variables can't be referenced in system variables. You can reference system variables in user variables though. So you'll have to create a new PATH user variable and reference the two variables you created earlier, as well as the system PATH variable. Like so:

    %JAVA%;%JAVA_HOME%;%PATH%

    Adding a screenshot as reference.

    Edit 3:
    The system PATH reference isn't necessary in the user PATH. Both will be called by the system when %PATH% is referenced.

    You can test your PATH reference with the console using the echo command:
    echo %PATH%
     

    Attached Files:

    Last edited: Sep 26, 2014
  30. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    the problem persists. still looking at JRE folder, which is not in any of the environment variables.
     
  31. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    i'm just going to copy the darn JDK files into the JRE directory...
     
  32. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    hilariously that worked :p
     
    Cat-Beltine and unity-nikkolai like this.
  33. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
    Updated my earlier post.
     
    Last edited: Sep 26, 2014
  34. mcconrad

    mcconrad

    Joined:
    Jul 16, 2013
    Posts:
    155
    ok just made a new build and video ads are running fine. however there is no skip button appearing after 5 seconds, though my admin panel has it set to that option. i should probably make a new thread for that though.

    thanks again for the help!
     
  35. fivearchers

    fivearchers

    Joined:
    Apr 17, 2009
    Posts:
    716
    OK installed the 32 Bit JDK and pointed my path to it and it works now. Thanks unity-nikkolai! (whereas I had 64 bit JDK installed before)
     
    HeikkiTunkelo and unity-nikkolai like this.
  36. Soul_Raven

    Soul_Raven

    Joined:
    Apr 12, 2014
    Posts:
    13
    I installed the windows x86 jdk and routed my system to it manually. After that I rebooted my pc and it corrected the problem.
     
  37. jak_apps

    jak_apps

    Joined:
    Jan 25, 2015
    Posts:
    2
    Can someone give me a summary on what I need to do if I have this problem?
    Really appreciated if anyone with a greater understanding of this could do that.
    Thanks!
     
  38. unity-nikkolai

    unity-nikkolai

    Unity Technologies

    Joined:
    Sep 18, 2014
    Posts:
    541
  39. paskal007r

    paskal007r

    Joined:
    Sep 6, 2013
    Posts:
    66
    Had the same issue, solved by installing last 32bit jdk and adding path variables as in linked guide.
    I'd suggest to insert this check in installation guides. I've found this thread only after a couple hours of googling the wrong stuff.

    Thank you all for the solution :)
     
  40. jak_apps

    jak_apps

    Joined:
    Jan 25, 2015
    Posts:
    2
    Thanks, that worked out great.
     
  41. coopoot

    coopoot

    Joined:
    Oct 30, 2014
    Posts:
    2
    basta deleta todas a instalações do java jre e jdk e instalar novamente apenas o jdk java e está resolvido
     
  42. Yash987654321

    Yash987654321

    Joined:
    Oct 22, 2014
    Posts:
    729
    ok if anyone has both ads and example together on package just delete the example one then it should work great
     
  43. yosefjbreen

    yosefjbreen

    Joined:
    Aug 28, 2014
    Posts:
    1
    Hi how to adding path variables ?