UnityAds don't compile

Hi,

I’ve just installed 4.6.0f3 and downloaded unityads from asset store and I get this error :

Assets/Standard Assets/UnityAds/Scripts/Advertisements/PictureAds/PictureAdsRequestsManager.cs(92,48): error CS0117: System.IO.File' does not contain a definition for WriteAllBytes’

Sounds like your build platform might be currently set to webplayer. Make sure that your build platform is set to either Android or iOS. Select File > Build Settings. Then select either of the two platforms and select Switch Platform.

The appropriate fix for this issue is to wrap the C# scripts included in this package with conditional compilation statements. We’ll have to do this in the next update.

It solves the problem, thx. But there is a new one :

Failed to compile resources with the following parameters:
-bootclasspath “C:/adt-bundle-windows-x86_64-20131030/sdk/platforms/android-21\android.jar” -d “C:\Users\cédrik\Documents\unity\Boonsy\Temp\StagingArea\bin\classes” -source 1.6 -target 1.6 -encoding UTF-8 “com\unity3d\ads\android\R.java” “com\w77\Boonsy\R.java”
warning: java\lang\Object.class(java\lang:Object.class): major version 51 is newer than 50, the highest major version supported by this compiler.
It is recommended that the compiler be upgraded.
1 warning

UnityEditor.HostView:OnGUI()

Unity version : 4.6.1f1
adt updated 2 1 2015

Error building Player: Win32Exception: ApplicationName=‘javac.exe’, CommandLine=‘-bootclasspath “C:/adt-bundle-windows-x86_64-20131030/sdk/platforms/android-21\android.jar” -d “C:\Users\cédrik\Documents\unity\Boonsy\Temp\StagingArea\bin\classes” -source 1.6 -target 1.6 -encoding UTF-8 “com\unity3d\ads\android\R.java” “com\w77\Boonsy\R.java”’, CurrentDirectory=‘C:\Users\cédrik\Documents\unity\Boonsy\Temp\StagingArea\gen’

You need to go to your “My Computer” right click and select properties advanced settings then environment variables. Add JAVA_HOME to user and set it to your jdk location, you need JDK I suggest the newest one. Also add PATH add it to the jdk/bin; folder remember the semi colon. If you don’t get it working tell me and I should be able to help I had the same issue, just on my phone right now so can’t give screenshots

Edit :

Never mind I’m going to go to the computer and show you.

Right click on My Computer and go to properties.


Select advanced system settings.


Set JAVA_HOME and PATH like mine but change the jdk version based off which one you have installed.


Same with the PATH in system variables.

Hope this helps!

3 Likes

Thanks.
Solutions I’ve found on the web talk about JDK_HOME. Google is definitly not my friend.

Is there any ETA on when this may get included? It’s a pain to have to add/remove the package to switch from testing modile to web.

I’m sorry, I don’t have an ETA. We are working towards an update but, it’s at least a month out from now.

The fix for this is relatively simple though:

// For each script in the Unity Ads asset package
// Insert the following line as the first line of the script:
#if UNITY_IOS || UNITY_ANDROID

//*** KEEP CONTENTS OF UNITY ADS SCRIPT HERE ***

// Then add the following line as the last line in the script:
#endif

Keep in mind that anywhere you reference the Unity Ads code in your own scripts, you will need to wrap it with the same compiler conditional statements as well.

This helper script for example, the using directive should be commented out as well as anything out side of public variables. By leaving the public variables outside the bounds of the conditional statement, you’ll be able to retain the values set via the inspector when you change between platforms.

I want to note that the problem is with Unity and JDK 32 bits version (seems that the new Unity 4.6.1p5 version will fix it).

I had this problem, and I finally solved it installing JDK 64 bits version, and setting only the JAVA_HOME variable to the 64 bits path “C:\Program Files\Java\jdk1.8.0_31”. I didn´t need to set up the other two PATH variables (in my case).

Regards.

1 Like

It don’t compile with a blank project set to build webplayer with unityad imported from asset store but not used : Only one empty scene + unityads →
Assets/Standard Assets/UnityAds/Scripts/Advertisements/PictureAds/PictureAdsRequestsManager.cs(92,48): error CS0117: System.IO.File' does not contain a definition for WriteAllBytes’

But it does if build platform is set to standalone.