How to change bundle identifier from code/cmd line?

Edit: I have to do it from code or command line (not in Unity Inspector).

I found this class: Unity - Scripting API: PlayerSettings and I tried changing the bundleIdentifier value (this script is in Assets/Editor):

void LoadSettings()
{
	PlayerSettings.bundleIdentifier = "com.mycompany.mygame";
}

But this doesn’t seem to change anything. How can I change the bundle identifier?

Ok, so my code was right but I just used it in wrong place. It works when called before creating a build:

class BuildGenerator
{
    static void BuildAndroid()
    {
        PlayerSettings.bundleIdentifier = "com.mycompany.mygame";
        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.Android);
        string [] scenes = { "Assets/Scenes/Gameplay/Gameplay.unity" };
        BuildPipeline.BuildPlayer(scenes, "Builds/Android/puzzle.apk",
            BuildTarget.Android, BuildOptions.None);
    }
}

It’s much simpler. You don’t have to use a Editor script. Just go to BuildSettings in your taskbar where you can choose the Plattform you are developing for. Then hit Player Settings and go to the plattform specific part in the inspector. Beyond “Other Settings” you got your Bundle Identifier.