How does UnrealBuildTool determine what files to compile

Questions

Did I do something wrong?

What is UnrealBuildTool doing?

Is there a standard way of having os specific folders (seems so looking at, say Launch in Unreal source code for example)?

Details

I have the following project directory setup in Visual Studio

 Engine
      \UE4
      ....
 Games
      \Project
          \Private
               \Android
               \General
          \Public
               \Android
               \General

With code that is Android specific in the \Android files. I then have in my build.cs file the following lines

    if (Target.Platform == UnrealTargetPlatform.Android)
    {
        PrivateIncludePaths.Add("Project/Private/Android/");
        PrivateIncludePaths.Add("Project/Public/Android/");
    }
    else
    {
        PrivateIncludePaths.Add("Project/Private/General/");
        PrivateIncludePaths.Add("Project/Public/General/");
    }
    .... other PrivateIncludePaths.AddRange(....)

However that was not working (it was importing running the General cpp file functions but yet had define statements from the Android .h file) and so I commented it out and have the following now

    /*
    if (Target.Platform == UnrealTargetPlatform.Android)
    {
        PrivateIncludePaths.Add("Project/Private/Android/");
        PrivateIncludePaths.Add("Project/Public/Android/");
    }
    else
    {
        PrivateIncludePaths.Add("Project/Private/General/");
        PrivateIncludePaths.Add("Project/Public/General/");
    }
    */

    PrivateIncludePaths.Add("Project/Private/Android/");
    PrivateIncludePaths.Add("Project/Public/Android/");

    .... other PrivateIncludePaths.AddRange(....)

I then included in the General cpp code that would error when compiled. I then went to Launch on the Unreal Editor and attempted to launch it on an Android tablet. Yet it did error complaining about an error in the code in \General\something.cpp. So I then removed it from the Visual Studio project and tried again. Still it tried to compile that file (even though it was removed from the project!).

Ok so I moved it out of the root directory for the project on the file system. So I no longer have the \General folders, just the \Android folders and tried to Launch, now it works (I put bad code in the Android files so if they did run it will complain and print the path).

So I then move the \General files back in and try to Launch again to confirm, and yep the BuildTool grabs on to the General files and tries to compile. The only mention of the \General paths in the build tool are the two lines above and they are both commented out.

Did I do something wrong? What is UnrealBuildTool doing? Is there a standard way of having os specific folders (seems so looking at, say Launch in Unreal source code for example)?

The Include paths are for finding headers, not for determining what files to compile. UBT will compile all source code in the module, except for files inside a Platform-named directory when you are not compiling for that platform.

So, everything in General will always be compiled, no matter what you do. The Visual Studio projects are not used for choosing files - the .vcxproj’s are simply convenience projects for opening files in Visual Studio. UBT will choose what to compile every time you build.

It is not expected that you would have source files that compile on every platform EXCEPT one. If you only care about Android and Windows, you could name General Windows and it would not compile on Android.

To complicate a little bit, we also have PlatformGroups, so Mac and IOS are in the Apple group, so they will compile source in directories called Apple, but no one else will.

If you wanted (and have all the source to UBT to recompile it), you could make groups for Mobile and Desktop, or something, and then rename General to Desktop, and Android/IOS wouldn’t compile files in there, but Windows/Mac would.

Maybe if you describe what you are trying to achieve with Android vs General, I could suggest the “Unreal Way” to do it :slight_smile:

I am trying to get the Android keyboard to popup and be usable for typing and display the text on the HUD using canvas. This uses the JNI, which is naturally not on anything but Android, but at this point just causes the application to crash after a couple seconds. Thanks for the information and yes I have changed the General folder to Windows, thanks. Thanks for the fast response.

FYI, if you make a SVirtualKeyboard Slate widget, then Android will pop up a dialog and let you type text in using native keyboard entry. (Actually this may not have made it in to 4.3, but will definitely be in 4.4)

Not sure if you have UI that needs text entered, but that’s something that you may want to look in to.

I do have text needing being entered into I’ll take a look at it (I wasn’t aware it was implemented on Android), thanks for the information.