UE 4.8 ignoring PLATFORM_ANDROID in generated.1 files

After upgrading the UE4 4.8 I’m running into an Android compile error with the generated code.

I have a field defined that checks for the android platform symbol in the actor header.

#if PLATFORM_ANDROID
	tv_ouya_console_api_content_OuyaMod::OuyaMod _ouyaMod;
#endif

The implementation file also has an android platform check.

AOuyaMod::AOuyaMod(const class FObjectInitializer& PCIP)
: Super(PCIP)
#if PLATFORM_ANDROID
, _ouyaMod(0)
#endif

Yet the Engine.generated2.cpp code is acting like it ignored the android platform check.

Error	3	error : constructor for 'AOuyaMod' must explicitly initialize the member '_ouyaMod' which does not have a default constructor	C:\Public\OUYA_UnrealEngine-4_8\Engine\Intermediate\Build\Android\UE4Client\Inc\Engine\Engine.generated.2.cpp	4530	31	UE4

Maybe generate project files missed setting a symbol in the project? This is something that worked fine in 4.7 and broke after the 4.8 upgrade.

Here is the working branch:
https://github.com/tgraupmann/UnrealEngine/tree/4.7-OUYA

And I’m upgrading to 4.8 in the new branch.
https://github.com/tgraupmann/UnrealEngine/tree/4.8-OUYA

Here a link to the valid header on 4.7.
https://github.com/tgraupmann/UnrealEngine/blob/4.7-OUYA/Engine/Source/Runtime/Engine/Classes/OuyaSDK/OuyaMod.h#L222

Here a link to the valid implementation on 4.7.
https://github.com/tgraupmann/UnrealEngine/blob/4.7-OUYA/Engine/Source/Runtime/Engine/Private/OuyaSDK/OuyaMod.cpp#L59

I usually define the PLATFORM_ANDROID symbol in the Android make file.

Defining the PLATFORM_ANDROID symbol was not previously required:
https://github.com/tgraupmann/UnrealEngine/blob/4.7-OUYA/Engine/Build/Android/Java/jni/Android.mk

Update:

I’ve added explicit Android platform checks:
https://github.com/tgraupmann/UnrealEngine/commit/f61847ddfdfb505cd12507ef6181296485a9ff1b

Development Editor - Win64 builds successfully.

Development Client - Android fails to build with a few errors like a project is missing the PLATFORM_ANDROID symbol when the source is generated…

I’m down to three odd errors…

Error	3	error : constructor for 'AOuyaModEditor' must explicitly initialize the member '_ouyaModEditor' which does not have a default constructor	C:\Public\OUYA_UnrealEngine-4_8\Engine\Intermediate\Build\Android\UE4Client\Inc\Engine\Engine.generated.2.cpp	4892	31	UE4
AOuyaModEditor::AOuyaModEditor(const class FObjectInitializer& PCIP)
: Super(PCIP)
#if PLATFORM_ANDROID
, _ouyaMod(0)
, _ouyaModEditor(0)
, _callbacksContentSave(0)
#endif
{
}

https://github.com/tgraupmann/UnrealEngine/blob/4.8-OUYA/Engine/Source/Runtime/Engine/Private/OuyaSDK/OuyaModEditor.cpp#L56

Error	4	error : constructor for 'AOuyaModScreenshot' must explicitly initialize the member '_ouyaModScreenshot' which does not have a default constructor	C:\Public\OUYA_UnrealEngine-4_8\Engine\Intermediate\Build\Android\UE4Client\Inc\Engine\Engine.generated.2.cpp	4973	31	UE4
AOuyaModScreenshot::AOuyaModScreenshot(const class FObjectInitializer& PCIP)
: Super(PCIP)
#if PLATFORM_ANDROID
, _ouyaModScreenshot(0)
#endif
{
}

https://github.com/tgraupmann/UnrealEngine/blob/4.8-OUYA/Engine/Source/Runtime/Engine/Private/OuyaSDK/OuyaModScreenshot.cpp#L23

Error	5	error : constructor for 'AOuyaContent' must explicitly initialize the member '_ouyaContent' which does not have a default constructor	C:\Public\OUYA_UnrealEngine-4_8\Engine\Intermediate\Build\Android\UE4Client\Inc\Engine\Engine.generated.1.cpp	52445	31	UE4
AOuyaContent::AOuyaContent(const class FObjectInitializer& PCIP)
: Super(PCIP)
#if PLATFORM_ANDROID
, _ouyaContent(0)
#endif
{
}

https://github.com/tgraupmann/UnrealEngine/blob/4.8-OUYA/Engine/Source/Runtime/Engine/Private/OuyaSDK/OuyaContent.cpp#L59

LOCAL_CFLAGS := -DPLATFORM_ANDROID -DANDROID -DECLIPSE

should be

LOCAL_CFLAGS := -DPLATFORM_ANDROID=1 -DANDROID=1 -DECLIPSE

Take a look at Engine/Source/Programs/UnrealBuildTool/Android/UEBuildAndroid.cs in SetUpEnvironment() for how we set the definitions.

I see:

InBuildTarget.GlobalCompileEnvironment.Config.Definitions.Add("PLATFORM_ANDROID=1");

So that looks right. It’s just some generated code process isn’t checking against this define when it included or skipped including:

AOuyaMod::AOuyaMod(const class FObjectInitializer& PCIP)
: Super(PCIP)
#if PLATFORM_ANDROID
, _ouyaMod(0)
#endif

#if PLATFORM_ANDROID isn’t the same as #ifdef PLATFORM_ANDROID. You need to set a value, in this case 1 as I said above.

Gotcha I was just checking for non-zero. I’ll try checking with… #ifdef PLATFORM_ANDROID

No, just use -DANDROID=1 instead of -DANDROID.

Am I missing something? The line says:

InBuildTarget.GlobalCompileEnvironment.Config.Definitions.Add("PLATFORM_ANDROID=1");
InBuildTarget.GlobalCompileEnvironment.Config.Definitions.Add("ANDROID=1");

It would make sense if I had something to add if it was:

InBuildTarget.GlobalCompileEnvironment.Config.Definitions.Add("PLATFORM_ANDROID");
InBuildTarget.GlobalCompileEnvironment.Config.Definitions.Add("ANDROID");

???

I was talking about your Android.mk.

Gotcha.
C:\UnrealEngine\UnrealEngine_4_8\Engine\Build\Android\Java\jni\Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := UE4
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libUE4.so
include $(PREBUILT_SHARED_LIBRARY)
LOCAL_CFLAGS := -DPLATFORM_ANDROID=1 -DANDROID=1 -DECLIPSE

I’m still getting the three errors.

25>C:\UnrealEngine\UnrealEngine_4_8\Engine\Intermediate\Build\Android\UE4Client\Inc\Engine\Engine.generated.2.cpp(4892,31): error : constructor for 'AOuyaModEditor' must explicitly initialize the member '_ouyaModEditor' which does not have a default constructor
25>          DEFINE_VTABLE_PTR_HELPER_CTOR(AOuyaModEditor);
25>                                        ^
25>  C:\UnrealEngine\UnrealEngine_4_8\Engine\Source\Runtime\CoreUObject\Public\UObject\ObjectBase.h(1254,10) :  note: expanded from macro 'DEFINE_VTABLE_PTR_HELPER_CTOR'
25>                  TClass::TClass(FVTableHelper& Helper) : Super(Helper) {};
25>                          ^
25>  C:\UnrealEngine\UnrealEngine_4_8\Engine\Source\Runtime\Engine\Classes\OuyaSDK\OuyaModEditor.h(112,58) :  note: member is declared here
25>          tv_ouya_console_api_content_OuyaModEditor::OuyaModEditor _ouyaModEditor;
25>                                                                   ^
25>  C:\UnrealEngine\UnrealEngine_4_8\Engine\Source\Runtime\Launch\Private\Android\OuyaSDK_OuyaModEditor.h(31,7) :  note: 'tv_ouya_console_api_content_OuyaModEditor::OuyaModEditor' declared here
25>          class OuyaModEditor
25>                ^
25>C:\UnrealEngine\UnrealEngine_4_8\Engine\Intermediate\Build\Android\UE4Client\Inc\Engine\Engine.generated.2.cpp(4973,31): error : constructor for 'AOuyaModScreenshot' must explicitly initialize the member '_ouyaModScreenshot' which does not have a default constructor
25>          DEFINE_VTABLE_PTR_HELPER_CTOR(AOuyaModScreenshot);
25>                                        ^
25>  C:\UnrealEngine\UnrealEngine_4_8\Engine\Source\Runtime\CoreUObject\Public\UObject\ObjectBase.h(1254,10) :  note: expanded from macro 'DEFINE_VTABLE_PTR_HELPER_CTOR'
25>                  TClass::TClass(FVTableHelper& Helper) : Super(Helper) {};
25>                          ^
25>

I have to think the build process or some preprocessor macro is not checking for the android platform.

Nether check for the constructor implementation is working.

#ifdef PLATFORM_ANDROID

#if PLATFORM_ANDROID

Why are you building client? You should be building Development.

I used development client successfully on both 4.6 and 4.7. I’ll try development with 4.8.

Building development has the same issue.

I suspect you’ll just have to try it. It’s an easy repro since everything is checked in and there are no manual steps.

Clone special:
https://github.com/tgraupmann/UnrealEngine/

Specifically grabbing the 4.8-OUYA branch.

Run setup.cmd.

Build the project files.

Build the editor.

And then try to build the android development.

You’ll run into the generated errors.

*** The odd thing is this is code that worked in 4,7 but not in 4.,8.

I’ll try isolating the issue. Start with an EpicGames/4.8 checkout.

Drop the repo files into:

Engine\Source\Runtime\Engine\Classes\Tests\TestAndroidConstructor.h

#pragma once

#include "GameFramework/Actor.h"

#include "TestAndroidConstructor.generated.h"

/**
* Test Android Platform Specific Constructor Logic
*/
UCLASS()
class ATestAndroidConstructor : public AActor
{
	GENERATED_UCLASS_BODY()

#if PLATFORM_ANDROID
	int _testField;
#endif
};

Engine\Source\Runtime\Engine\Private\Tests\TestAndroidConstructor.cpp

#include "EnginePrivate.h"

#include "Tests/TestAndroidConstructor.h"

ATestAndroidConstructor::ATestAndroidConstructor(const class FObjectInitializer& PCIP)
: Super(PCIP)
#if PLATFORM_ANDROID
, _testField(0)
#endif
{
}

And then rerun GenerateProjectFiles.bat.

It’s odd can’t attach .h and .cpp files. Here’s links instead.

http://tagenigma.com/unreal/TestAndroidConstructor.h

http://tagenigma.com/unreal/TestAndroidConstructor.cpp

Okay and that builds successfully…

I created a small repro project that reproduces the issue.

https://github.com/tgraupmann/UnrealEngine/commit/0c1cc82617b6901eaad327fb352d5a087994086e

The issue is that if a class is defined on the Android platform that has a copy constructor, that class cannot be used by an actor class.

This was something that worked on 4.7, but not on 4.8.

I just needed the following files to reproduce the issue.

Engine/Source/Runtime/Engine/Classes/Tests/TestAndroidConstructor.h

Engine/Source/Runtime/Engine/Private/Tests/TestAndroidConstructor.cpp

Engine/Source/Runtime/Launch/Private/Android/TestAndroidClass.h

Engine/Source/Runtime/Launch/Private/Android/TestAndroidClass.cpp

I worked around the issue by avoiding using the copy constructor in the Android platform code.

Here is the fix.
https://github.com/tgraupmann/UnrealEngine/commit/dbb5d292371c92401aede394ad52bac144ec5db9

I’m now upgraded to UE 4.9.

It was probably this change, not #if PLATFORM_ANDROID causing the problem:

GitHub commit