- Home /
Custom Pre Build Process?
Greetings,
So when you build for Android, Unity starts the build, compiles scripts, converts classes to dex format, finds a device and installs/launches the game on it.
In the build settings there are two things you need to specify: the cube store password and the bundle identifier.
The problem is, if you fail to provide the cube password correctly, Unity won't tell you that you don't have a correct password right away but instead stupidly continues the build process and lets you at 75% of it.
Same thing for the bundle identifier, if it's older than the one installed on the device it screams unable to install downgraded version etc.
It blows my mind that it has to wait till almost the end of the build to do those checks, why not abort immediately at the beginning?
I've wasted so much time and got frustrated because of that...
Is there any way to intercept/customize this build process to do those checks at the beginning? I could ILSpy the editor code and try to figure out what the 'Build' button does (pretty sure I'll end up in a closed end/extern'ed code). But before I try that was wondering if there's a legitimate way to do it without resorting to hacks...
Thanks.
Answer by Syganek · Mar 02, 2018 at 05:17 PM
There is IPreprocessBuild interface.
It contains OnPreprocessBuild method that will be invoked.
I know it is old topic, but I think that answers should be given when somebody knows them and stumbles upon a question.
Yes, this was added some time in 2017.x, and we've moved all our custom builds to use it. It works very well. It had strangely little fanfare on its addition - I found it by mistake sometime after posting my answer in a blog (not on the official unity blog) by a Unity engineer called something like "10 things you didn't know about that weren't highlighted in the big feature release announcements of 2017.x".) Those 10 things turned out to be more interesting to me than most of the big ticket features.
Answer by Dave-Carlile · Jun 16, 2016 at 03:08 PM
The BuildPipeline class will let you have some control over the build process.
Thanks. Will look into that. I need to somehow access the options that show up in the inspector when you click the 'Player Options' button. Should be easy to find out with ILSpy
Answer by ferretnt · May 29, 2017 at 11:25 PM
As far as I know, there's still no "pre-build event", and custom scripting buildPipeline is more of a pain than it's ever worth, especially after you've tried to manage it so your script does what you want across multiple platforms, local dev builds, a continuous build machine, release process etc.
"Use the buildpipeline class" is similar to "use assetbundles instead of just loading a single level." It totally gives you that control, at the expense of breaking almost every advantage of simplicity and workflow that made you use Unity in the first place.
The closest we've every got is a manually invoked "set everything up" editor script, that sets values in PlayerSettings, so you can THEN run your regular build process with ctrl-b.
You can use post build events to fudge up your XCodeProj for stuff like version numbers after the build but there's not really any way to do anything useful on Android.
Unfortunately, exact requirements around build process are very project specific, and the Unity core team does an excellent job of ignoring problems with ambiguous requirements.
Your answer
Follow this Question
Related Questions
Build to Android with a Wireless connection? 1 Answer
Distribute terrain in zones 3 Answers
Is it possible to set android sdk path via script? 1 Answer
Change Plugin platforms by scripting 4 Answers