Unity command line arguments for android and iOS - android

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.

Related

One command for multiple deployments

I'd like to know if some of you worked out how to generate signed APKs and IPA with multiple configurations (ie : beta for hockeyapp, and production for stores) in a single command.
I'm exploring all the possibilities there, it looks like there are lots of ways to do this.
I'd also like to be able to pass a variable like ENVIRONMENT to set Javascript constants such as an API url or turn on/off debugs.
Here's what I'm thinking right now :
Using https://www.npmjs.com/package/react-native-config to solve the former problem.
On android :
I'm thinking about adding a type in buildTypes in gradle. So far, I couldn't get it to work, I'm not very experienced with native configurations.
I would then make a bash script to create the offline bundle with the chosen env (staging / dev / prod) and use gradle's assembleRelease / assembleBeta. Do you think that's doable ?
On iOS, it looks a bit more complicated :
It looks like it's hard to change the project's configuration in CLI when building. So I was thinking that I should duplicate the project for each environement : project-dev.xcodeproj, project-prod.xcodeproj... you got the point.
Once again, I would make the bundle, then cp it inside the given project. A nice touch would be to trigger the xcode compilation in CLI too, I don't know if this is hard to set up.
What do you think about this ? Maybe some of you are already using custom scripts to do that ?
The icing on the cake would be to use HockeyApp's 'puck' cli tool to upload it, but that should be quite easy to set up once the application has been build for both iOS and Android.
This is the process I use for command line build with parameters. My system builds a release version .ips file and then copies and resigns that file with a development provisioning profile that I can put on my development devices to test exactly what is being sent to the customer or to the app store. Not all of this will be useful to you, but hopefully some will.
First, I have a variables file that sets the global parameters that I'm going to use for the build:
Scheme="(The scheme I am going to build inside my project)"
WindowsSavePath="(path to my source archive directory on a shared computer)"
InstallSavePath="(path to my .ipa archive directory on a shared computer"
Customer="(relative path inside archive directories)"
Fleet="(Continued relative path)"
PathToProject="(path to the folder on my Mac with the xcode project file)"
ProjectName="(project name).xcodeproj"
PlistPath="$Scheme-Info.plist"
appScheme="$Scheme"
AppName="(The name that I want to give my .ipa file)"
Version="(The version number for this build)"
AppendedFileName="-QA" //I use this for QA and Production distinction
exportPath="$InstallSavePath/$Fleet/$Customer/$Version$AppendedFileName/"
CompanyAppIdentifierPrefix="(my generic provisioning profile identifier)"
ArchiveLocation="$WindowsSavePath/$Fleet/$Customer/$Version$AppendedFileName"
SourceCodeDestination="(my compiled absolute path to the archive directories)"
This is all contained in a SetVariables.sh file. Now we get to start building the project. In another .sh file first I call the SetVariables file, then I start compilation:
#Update the version number in the plist file for the project
/usr/libexec/PListBuddy -c "Set :CFBundleShortVersionString $Version" "$PathToProject/$PlistPath"
/usr/libexec/PListBuddy -c "Set :CFBundleVersion $BuildVersion" "$PathToProject/$PlistPath"
#Now build and archive the project, the create the .ipa file for either submittal or giving to customers
mkdir -p "$exportPath"
mkdir -p "${ArchiveLocation}/dSYM"
xcodebuild -project "$PathToProject/$ProjectName" -scheme "$Scheme" DSTROOT="$exportPath" DEBUG_INFORMATION_FORMAT="dwarf-with-dsym" DWARF_DSYM_FOLDER_PATH="${ArchiveLocation}/dSYM" archive -archivePath "$exportPath${appScheme} $Version$AppendedFileName.xcarchive"
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${exportPath}Applications/${AppName}.app" -o "${exportPath}${appScheme} $Version$AppendedFileName.ipa"
#Now resign and create an internal dev version to test on development ipads
rm -r Payload SwiftSupport
unzip -q "${exportPath}${appScheme} $Version$AppendedFileName.ipa"
BUNDLE_ID=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "Payload/${AppName}.app/Info.plist")
. ./CreateInternalEntitlements.sh "$CompanyAppIdentifierPrefix.$BUNDLE_ID"
. ./resign.sh "${exportPath}${appScheme} $Version$AppendedFileName.ipa" "${exportPath}${appScheme} ${Version}${AppendedFileName} Internal" internalDev.mobileprovision "(My developer account tied to the internal provisioning profile" Entitlements.plist
rm -r Payload SwiftSupport
#Now delete the intermediate files from the installs directory
rm -rf "$exportPath${appScheme} $Version$AppendedFileName.xcarchive"
rm -rf "${exportPath}Applications"
I have left out a few things in there (resign.sh, createentitlements.sh), but those processes I found on stackoverflow, so it shouldn't be too hard for you to find as well.
I've never done it, but I'm relatively certain that you can change the command line arguments for the xcodebuild to build either release or debug like you are trying to do. You could also run the xcodebuild twice, once for debug and once for release, and save the builds to different locations.
I hope this helps you at least a little with your goals. This took my a week or two to put all together and get working for my needs. Good luck.

Jenkins hanged when I try to build Unity project

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.

Run Python for Android (Qpython) in Android Terminal

Python for Android (Py4A 2.6) is wonderful!!! But QPython (2.7) is a lot more powerful and continuously developed. Now I try to integrate Qpython's Python into Android (5.1 CM12) Terminal / ADB described in this Tutorial:http://wiki.qpython.org/en/diveinto/
My Script to import the environment variables qpython needs looks like:
TERM=screen
PATH=/data/data/com.hipipal.qpyplus/files/bin:/system/bin:/system/xbin
LD_LIBRARY_PATH=.:/data/data/com.hipipal.qpyplus/files/lib/:/data/data/com.hipipal.qpyplus/files/:/data/data/com.hipipal.qpyplus/lib/
PYTHONHOME=/data/data/com.hipipal.qpyplus/files
ANDROID_PRIVATE=/data/data/com.hipipal.qpyplus/files
PYTHONPATH=/storage/emulated/0/com.hipipal.qpyplus/lib/python2.7/site-packages/:/data/data/com.hipipal.qpyplus/files/lib/python2.7/site-packages/:/data/data/com.hipipal.qpyplus/files/lib/python2.7/:/data/data/com.hipipal.qpyplus/files/lib/python27.zip:/data/data/com.hipipal.qpyplus/files/lib/python2.7/lib-dynload/:/storage/emulated/0/com.hipipal.qpyplus/scripts
PYTHONSTARTUP=/storage/emulated/0/com.hipipal.qpyplus/lib/python2.7/site-packages/qpythoninit.py
PYTHONOPTIMIZE=2
TMPDIR=/storage/emulated/0/com.hipipal.qpyplus/cache
AP_HOST=127.0.0.1
AP_PORT=58418
AP_HANDSHAKE=01805a68-c04c-4e21-bd54-ac8732f3a8da
ANDROID_PUBLIC=/storage/emulated/0/com.hipipal.qpyplus
ANDROID_PRIVATE=/data/data/com.hipipal.qpyplus/files
ANDROID_ARGUMENT=/storage/emulated/0/com.hipipal.qpyplus/scripts
Shell session:
u0_a101#C1905:/ $ source /sdcard/qpyenvnew.sh
u0_a101#C1905:/ $ $python
u0_a101#C1905:/ $ hmm do nothing?!
I get no output.
I have found here on Stackoverflow the same Question but the posted solution ist a link how is down.
Other Tutorial on throws only errors
http://dinostest.com/node/28
Try this command in your terminal:
$sh data/data/com.hipipal.qpyplus/files/bin/qpython.sh
Terminal will prompt a Python console.
If your script for the environment variables was obtained by running the code from the tutorial link, it should be correct.
If what you have pasted is exactly what you entered, the problem would be that you tried to run pyhton by typing $python when it should have just been python
Pre-fixing with $ is used to reference the value of a variable, so entering $python referenced the value of the variable python but does nothing with it, hence no feedback.
EDIT2: Although it's not a direct answer to this question I suggest having a look at the App 'Termux'. You can install Python2/3 via apt, virtualenv/-wrapper etc... Much more powerfull!
EDIT: Since /data/data... is only accessible as root, the following must be done as root!
Take care that the python executables path is in your $PATH. That wasn't the case even after having run the script from the tutorial (your script). If it's not present simply type:export PATH=/data/data/com.hipipal.qpyplus/files/bin:$PATH
or follow theses steps. In short: create a file in /sdcard (here ".bashrc") with the above line. After that type: source .bashrcsource init.sh (init.sh is located in /data/data/com.hipipal.qpyplus/files/bin as well) Then fire up Python with python-android5 which is the PIE compatible executable for Phone with Lollipop and above. But be aware: For whatever reason I couldn't exit() or quit() the Python prompt but I was able to run Script from the Terminal! Have fun!
EDIT: I spotted this: PythonForAndroid. It is a fork of PythonForAndroid that is still alive, and this versions are able to run on Android L (Python3 on 5.1.1 in my case). Also check the SL4A linked there, it works great on Lollipop.
Thanks to the answers above I made a super easy solution. If you have root: Create a file "python" and type the following line in it:
sh data/data/com.hipipal.qpyplus/files/bin/qpython-android5.sh
Place this file in your /system/bin directory and you can access python from everywhere using the command 'python'.

Build an APK on unity using a command on the terminal

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..

Chromium for android eclipse debugging / DDD for chromium C++ debugging

I'm developing simple project using Chromium for android is there some way to debug Chromium C++ code through eclipse debugger?
Right now i have possibility to debug C++ through Terminal using GDB or DDD.
In case how to use DDD here is short instruction:
1.Install ddd application
sudo apt-get install ddd
2.Change adb_gdb file in directory chromium/src/build/android
change the line $GDB $GDBARGS -x $COMMANDS && to
ddd --debugger $GDB $GDBARGS -x $COMMANDS &&
cd /chromium/src
. build/android/envsetup.sh
build/android/adb_install_apk.py --apk ContentShell.apk
build/android/adb_run_content_shell
build/android/adb_gdb_content_shell
DDD application (example, how to use)
a. File->Open Source -> Filter -> set filename "ipc_chnnel_proxy.cc" -> Open
b. set breakpoints in the function ChannelProxy::Context::OnMessageReceived
c. run the command Cont
d. DDD will break on this breakpoint
See https://code.google.com/p/chromium/wiki/LinuxEclipseDev in particular the "Optional: Building inside Eclipse" section. It's still a bit flaky but works most of the time.
I got a working solution to debug Chromium for Android from Eclipse. It involves the creation of some wrappers following the idea you propose in your step 2. Your proposal lacks a way of telling Eclipse to use that debugging scripts, but it can be done by properly tweaking the debug configuration in Eclipse to use the gdb/mi debugger and open the proper wrappers.
All the steps are explained in this post: http://blogs.igalia.com/eocanha/2014/10/14/hacking-on-chromium-for-android-from-eclipse-part-2

Categories

Resources