I found Jenkins(windows) hanged when I try to build Unity project for android package.
I'm trying to use Jenkins with Unity plugin and windows bat to build project, after windows exe exported successful, android package exported failed.
The arguemnt when I use Unity plugin is
-batchmode -quit -projectPath "D:\Program Files (x86)\Jenkins\jobs\UnityJenkinsTest\workspace\QBAD" -executeMethod QBADBuildScript.Android -logFile "${WORKSPACE}/Build-Log.txt"
Meanwhile, I try using a windows bat to execute the same command from Jenkins, the result is the same.
"D:\Program Files\Unity\Editor\Unity.exe" -batchmode -quit -projectPath "D:\Program Files (x86)\Jenkins\jobs\UnityJenkinsTest\workspace\QBAD" -executeMethod QBADBuildScript.Android -logFile "${WORKSPACE}/Build-Log.txt"
When the building process went to the some part of build process, it hanged, and the build of jenkins never ended. I check with succeed log, it hanged before entering the part of Android.
(succeed log)
Used Assets, sorted by uncompressed size:
....
AndroidSDKTools: // This line and below never showed when hanging happened.
root : D:/Android/sdk
tools : D:/Android/sdk\tools
platform-tools: D:/Android/sdk\platform-tools
build-tools : D:\Android\sdk\build-tools\23.0.1
On the contrary, when I call the same script from command console of windows, it ended and succeed. I wonder what went wrong. Maybe I need set up environment variable for Jenkins.
The version of my Jenkins is 1.614, the version of my Unity is 5.0.1 .
Thanks
public static class AndroidSDKFolder
{
public static string Path
{
get { return EditorPrefs.GetString("AndroidSdkRoot"); }
set { EditorPrefs.SetString("AndroidSdkRoot", value); }
}
}
http://answers.unity3d.com/questions/495735/setting-android-sdk-path-in-environment-variable.html <-- This should help, setting the android sdk path stops the hang.
Related
When I try to export the game build for the Android platform, I started getting this error:
Within the Project Settings - Minimum API Level and Target API Level not get loaded anyhow!
While I have used all default Unity provided settings to export Android build.
Here is the image to illustrate this:
Now what to do to solve this error?
I have already read all the threads related to same problem but overall I can't able to find the solution that actually worked for me.
Project Settings > Player > Target API Level: Change "Automatic" to "Android 11" (or else)
Play once and Stop.
Change target api level to Automatic.
I don't know if the problem is the same, but this is how I handle it every time.
Edit: Now I just do this; I open the Other Settings Tab in Player Settings. Error appears in console. I Play and Stop it once and the error goes away (No need to change API Levels)
I just got the same error on MacOS using both Unity 2019.4.18.f1/2019.2.21.f1 and after a lot of messing around I think I might have figured some of it out.
At times ( don't know why ) Unity ( or something else ) starts resetting the JAVA_HOME environment variable to string empty when you start Unity. So even if you set JAVA_HOME via console or .bashrc/.zshrc depending on MacOS version it still doesn't work.
Some posts mentioned adding "/" to the end of the external tools SDK path. I think that just forces Unity to set the path again which makes it work for a while. But for me the the error just came back the second day.
I permanently fixed it adding an editor script to the Editor folder that changes the JAVA_HOME environment variable every time Unity starts/loads.
Here's the method for MacOS, just paste it in a C# script in the editor folder.
[InitializeOnLoadMethod]
static void SetJavaHome()
{
//Debug.Log(EditorApplication.applicationPath);
Debug.Log("JAVA_HOME in editor was: " + Environment.GetEnvironmentVariable("JAVA_HOME"));
string newJDKPath = EditorApplication.applicationPath.Replace("Unity.app", "PlaybackEngines/AndroidPlayer/OpenJDK");
if (Environment.GetEnvironmentVariable("JAVA_HOME") != newJDKPath)
{
Environment.SetEnvironmentVariable("JAVA_HOME", newJDKPath);
}
Debug.Log("JAVA_HOME in editor set to: " + Environment.GetEnvironmentVariable("JAVA_HOME"));
}
This worked for me :- Edit>Prefrences>In JDK Click copy path> then Uncheck JDK and Paste the copied path again in that and after OpenJDK add \
like this : Before : C:\Program Files\Unity\Hub\Editor\2020.1.3f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK
After : C:\Program Files\Unity\Hub\Editor\2020.1.3f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\
If that doesn't works than uncheck JDK,SDK,NDK,Gradle and Stop Gradle (all five boxes) than close unity. Open Again and Check all five boxes again.
I don't know why, but on mac os unity may use latest version of java if you have one.
If you have installed a few versions of java, you can just remove all except java v1.8.
You can check which version of java you have by typing in terminal /usr/libexec/java_home -V.
You should have 2 or more versions.
If you installed them with brew, you can just use brew to uninstall extra java packages.
Also you can update JAVA_HOME system variable by type
echo export "JAVA_HOME=$(/usr/libexec/java_home -v 1.8)" >> ~/.zshrc.
This solution worked for me.
Using Android Studio 3.1.4 on Windows 64 Pro.
When running any app, including a sample project, Android Studio gets stuck the second time around on build/run cycle.
In Windows task manager I see java.exe suspended where one of the process threads it says is waiting on network i/o.
I have to kill java.exe from the Windows task manager every time I build/run an app.
I tried all of the following with no help:
deleted .gradle in my user folder
deleted .AndroidStudio3.1 folder in my user folder
invalidate caches/restart
use offline gradle option
disable instant run
Any ideas why this is happening? Seems that the build process is deadlocking on itself. This only happens on the second build/run.
I am encountering the same issue and have tried re-installs, differing JVMs, and countless other tactics. As a temporary workaround I have modified the Gradle build to create a flag file which a separate Powershell script then polls for and if found kills any running Open JDK process. This is a kludge without doubt but helps keep me sane.
Update build.gradle(Module:app) to include the following:
android {
compileSdkVersion 28
...
}
android.applicationVariants.all {
ant.touch(file:"D:/Build.flg")
}
}
Then run the following Powershell script
do {
Write-Host "Checking for D:\Build.flg"
if (Test-Path "D:\Build.flg") {
Remove-Item "D:\Build.flg"
Write-Host "Locating Java processes"
$JavaProcessos = Get-Process java | select Id, processname, Description
Foreach($Process in $JavaProcessos)
{
if($Process.Description -eq "OpenJDK Platform binary") {
Write-Host "Stopping process " $Process.Id $Process.Description
Start-Sleep -s 30
Stop-Process $Process.Id
}
}
}
Start-Sleep -s 10
}
While ($true)
Not pretty but functional.
I could not call the script directly from the build as it kills the JVM that Gradle itself is using at the time - thus the delay and flag approach.
I welcome suggestions to improve, until the root cause is addressed.
In the process of trying to fix the Android Studio alternate build hang, I damaged my Eclipse / Python install. Surprisingly, fixing Eclipse also seems to have eliminated the Android build problem. Came down to setting the right Java environment variables.
Press the ⊞ Win key and search for [Edit the system environment variables].
Then add / update the following based on the location of your JDK installation.
CLASSPATH=.;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_191
JDK_HOME=%JAVA_HOME%
JRE_HOME=%JAVA_HOME%\jre
Finally, add the Java bin to the start of your path
Path=%JAVA_HOME%\bin;...
After this my Android Studio builds no longer hang and Eclipse is fully functional.
I've used Sysinternals ProcessExplorer. In the context menu you can just RESUME the java process and the build will work
I am attempting to build a CommonJS module in Appcelerator Studio.
Following this recipe:
File > New > New Mobile Module Project
Set the project name to be testmodule
Leave the location as default
Set the Module Id to au.com.test.testmodule
Set the Titanium SDK Version to 5.3.1.GA
Set the Deployment Targets to Android
Click Next and then Finish
This will create a new module called testmodule.
Under this folder there is a one called assets, create a new file in there called au.com.test.testmodule.js. This will mark the module as a CommonJS module.
In this file just create an empty function and export it
function test() {
Ti.API.debug('test');
}
module.exports = test;
From the command line type:
ant
This will attempt to build the module.
In output you will see the ant target js.compile and this will have an error message
[exec] [DEBUG] "/Users/chris/Library/Application Support/Titanium/mobilesdk/osx/5.3.1.GA/android/titanium_prep.macos" au.com.example.testmodule /testmodule/android/build/generated/js au.com.example.testmodule.js
[exec] [ERROR] Not enough arguments.
[exec] [ERROR] Unabled to prepare JavaScript for packaging. Error code 1.
[exec] Result: 1
Running ant like the following:
ant -debug -logfile build.log
The problem seems to be an executable called titanium_prep.macos.
If you run the command
"/Users/chris/Library/Application Support/Titanium/mobilesdk/osx/5.3.1.GA/android/titanium_prep.macos" au.com.example.testmodule /testmodule/android/build/generated/js au.com.mobilogica.testmodule.js
It will give the error Not enough arguments. If you add one more parameter of anything, it will run without giving that message.
Of course being that the parameter is bogus, it will not generate the correct code.
It seems like titanium_prep.macos requires 4 parameters, but right now only three are being passed in.
au.com.example.testmodule
/testmodule/android/build/generated/js
au.com.example.testmodule.js
System:
Mac OSX 10.10.5
XCode 6.1
Appcelerator CLI 5.4.0
Appcelerator SDK 5.3.1
If you generate the example same module with 3.5.1.GA it works.
I have tried this in the 4.4 series of SDKs as well and have the same problem.
I have a project on Unity3d (working on a mac) and I am trying to generate the android apk file from the command line. Is this doable?
Right now I have a PerformBuild.cs file inside Assets/Editor
and I call inside it:
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.Android, BuildOptions.AcceptExternalModificationsToPlayer);
However this is only generating the Android Project for it, and not the apk.
Can I directly generate the APK using a cs build script or will I have to generate the project, import it to eclipse and then build the apk?
Thank you
Additional information:
Here is the full method in my script
[UnityEditor.MenuItem("CUSTOM/Test Android Build Step")]
static void androidBuild ()
{
Debug.Log("Command line build android version\n------------------\n------------------");
string[] scenes = GetBuildScenes();
string path = GetBuildPathAndroid();
if(scenes == null || scenes.Length==0 || path == null)
return;
Debug.Log(string.Format("Path: \"{0}\"", path));
for(int i=0; i<scenes.Length; ++i)
{
Debug.Log(string.Format("Scene[{0}]: \"{1}\"", i, scenes[i]));
}
Debug.Log("Starting Android Build!");
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.Android, BuildOptions.AcceptExternalModificationsToPlayer);
BuildPipeline.buil
}
and I call it from the command line using the following:
/Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -quit -executeMethod PerformBuild.androidBuild
and I have the android sdk setup and configured
Just remove AcceptExternalModificationsToPlayer from the BuildOptions.
BuildOptions.AcceptExternalModificationsToPlayer
On Android, this setting will create a new Eclipse project. Existing Eclipse project setting changes will be discarded.
Source:
http://docs.unity3d.com/ScriptReference/BuildOptions.AcceptExternalModificationsToPlayer.html
Ok, I must admit, it's not 100% clear from this, but this is the "switch" to change, to build directly an .apk file instead of creating an Android project.
So in your case, just change
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.Android, BuildOptions.AcceptExternalModificationsToPlayer);
to
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.Android, BuildOptions.None);
You may want to take a look at all the different BuildOptions e.g. if you want to make your build debuggable (to be able to attach the MonoDevelop debugger to it => BuildOptions.Development | BuildOptions.AllowDebugging)
Source:
http://docs.unity3d.com/ScriptReference/BuildOptions.html
d4Rk is right, buil doption should be set to none, unless you know what you are doing.
I encountered same issue recently, searched and drilled for one day.
Just found a special line in my build tool script:
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
I don't remember when I wrote it.. so just commented it and the buildpipeline build apk agian..
Please pardon my ignorance, relatively new to working with Unity3D. I am working on automating Unity3d builds from the command line.
I am looking for command line arguments to build apk & xcode project.
Unity's documentation does mention arguments to build a standalone Mac OSX player (-buildOSXPlayer) and a standalone Windows player (-buildWindowsPlayer) but not for android and iOS.
Any help would be really appreciated. Thanks.
Start with Unity's own documentation for command line builds for iOS and android.
For example, put this script in your Assets/Editor folder:
// C# example
using UnityEditor;
class Autobuilder
{
[MenuItem ("File/AutoBuilder/iOS")]
static void PerformBuild ()
{
string[] scenes = { "Assets/MyScene.unity" };
string buildPath = "../../../Build/iOS";
// Create build folder if not yet exists
Directory.CreateDirectory(buildPath);
BuildPipeline.BuildPlayer(scenes, buildPath, BuildTarget.iOS, BuildOptions.Development);
}
}
You can actually run this script in the Unity application by going to File -> Autobuilder -> iOS
To run on command line, it looks something like this:
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod Autobuilder.PerformBuild -email me#email.com -password myPassword
Of course, you're going to want to check the debug log for any errors:
Mac OS X ~/Library/Logs/Unity/Editor.log
Windows XP C:\Documents and Settings\username\Local Settings\Application Data_\Unity\Editor\Editor.log
Windows Vista/7 C:\Users\username\AppData\Local\Unity\Editor\Editor.log
The -executeMethod command line parameter is a very simple option to invoke any function in any of your scripts - which you can then use to do pretty much anything, including firing off an Android build.