Unreal Engine 4:编译打包Android应用问题汇总

 本文对编译打包Android应用遇到的问题进行汇总。使用的环境:

android-ndk-r12b
-std=c++14
STL=gnu-libstdc++


目录

1、error: undefined reference to 'typeinfo for ACharacter'

2、error: exception handling was disabled in PCH file but is currently enabled

3、编译时总是报waring C4668

4、warning: '__GLIBC__' is not defined, evaluates to 0 [-Wundef]

5、编译时报"变量重定义"

6、warning: declaration shadows a field of 'BaseAndExponent' [-Wshadow],>

7、error: #pragma once in main file [-Werror,-Wpragma-once-outside-header]

8、gettid() not found

9、error: 'auto_ptr' is deprecated [-Werror,-Wdeprecated-declarations]

10、error: no member named 'to_string' in namespace 'std'

11、Unable to start program UE4.exe error

12、error: illegal character encoding in string literal

13、error: no member named 'stoi' in namespace 'std'

14、Cook failed

15、error: initializer on function does not look like a pure-specifier

16、 error: declaration of 'MODE' shadows template parameter

17、error: explicit specialization of 'getTypeName' in class scope

18、/cryptopp/include/misc.h(1849,9) :  error: use of undeclared identifier 'bswap_16'

19、error: lambda capture 'LocalMapLayoutForCapture' is not used [-Werror,-Wunused-lambda-capture]

20、如何屏蔽屏幕上的 joysticks

21、touch事件触发了两次

22、XXX has an inappropriate outermost, it was probably saved with a deprecated outer


 

1、error: undefined reference to 'typeinfo for ACharacter'

UATHelper: Packaging (Android (ETC1)):   AndroidProject/Module.AndroidProject.cpp-armv7-es2.o:D:/projects/AndroidProject/Intermediate/Build/Android/AndroidProject/Development/AndroidProject/Module.AndroidProject.cpp:typeinfo for AAndroidProjectCharacter: error: undefined reference to 'typeinfo for ACharacter'

UE4引擎中的代码都是禁用exception和RTTI功能的,如果在使用了UObject的代码中打开了RTTI,编译时会报上述错误。

如果代码中要使用throw、typeid()、dynamic_cast()等这些exception和RTII功能应该办?
(1).将这一部分代码编译成第三方动态库,编译时打开exception和RTII功能,并且这些第三方提供给外部调用的接口头文件中不要有使用了exception和RTII功能的代码。
(2).将这一部分代码用单独的Module封装,在这个Module不要使用任何用到UObject及其相关子类的代码。这个Module中单独打开exception和RTII功能进行编译。

PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
// 开启RTTI,支持typeid()
bUseRTTI = true;
// 开启后支持throw exception
bEnableExceptions = true;

2、error: exception handling was disabled in PCH file but is currently enabled

 这个问题是由于在生成编译命令时生成了一个-include "C:/Epic Games/UE_4.18/Engine/Intermediate/Build/Android/UE4/Development/Engine/SharedPCH.Engine.RTTI-armv7-es2.h"
而SharedPCH.Engine.RTTI-armv7-es2.h这个文件不存在,所以就报错了。但报错信息自身又不对,所以一开始很难找到原因。
暂时的修改方式是不让UBT生成这条指令:
在C:\Epic Games\UE_4.18\Engine\Source\Programs\UnrealBuildTool\Platform\Android\AndroidToolChain.cs文件中
注释掉如下代码行:

PCHArguments += string.Format(" -include \"{0}\"", InlineArchName(BasePCHName, Arch, GPUArchitecture)); 

3、编译时总是报waring C4668

在C:\Epic Games\UE_4.18\Engine\Source\Programs\UnrealBuildTool\Platform\Windows\VCToolChain.cs中找到

Arguments.Add("/w44668");

将其改成

Arguments.Add("/wd4668");

4、warning: '__GLIBC__' is not defined, evaluates to 0 [-Wundef]

在如下文件中
C:\Epic Games\UE_4.18\Engine\Source\Programs\UnrealBuildTool\Platform\Android\AndroidToolChain.cs
注释掉

Result += " -Wundef" + (CompileEnvironment.bUndefinedIdentifierWarningsAsErrors ? "" : " -Wno-error=undef");

5、编译时报"变量重定义"

在*.Build.cs文件中添加如下属性:

// 如果不设置成true,则编译时会将32个源文件作为一批全成一个源码文件进行编译,容易出现"变量重定义"等许多问题
bFasterWithoutUnity = true;

另外,UBT中提供MinSourceFilesForUnityBuildOverride这个参数可以设置一批有多少个源文件可以合并,但试过后发现没起作用。

6、warning: declaration shadows a field of 'BaseAndExponent<T, E>' [-Wshadow]

在*.Build.cs文件中添加如下属性:

bEnableShadowVariableWarnings = false;

7、error: #pragma once in main file [-Werror,-Wpragma-once-outside-header]

将*.cpp文件中的#pragma once去掉

8、gettid() not found

将如下文件
C:\Epic Games\UE_4.18\Engine\Source\Runtime\Core\Public\Android\AndroidTLS.h中的

        return static_cast<uint32>(gettid());
//      return pthread_self();

修改成

//  return static_cast<uint32>(gettid());
    return pthread_self();

9、error: 'auto_ptr<msgpack::v1::zone>' is deprecated [-Werror,-Wdeprecated-declarations]

这个错是说auto_ptr已经弃用了,如果使用了已弃用的API,就会报这个错。
解决方法,添加

Result += " -Wno-deprecated"; 

到如下文件:
C:\Epic Games\UE_4.18\Engine\Source\Programs\UnrealBuildTool\Platform\Android\AndroidToolChain.cs的如下方法中

string GetCLArguments_Global(CppCompileEnvironment CompileEnvironment, string Architecture)

10、error: no member named 'to_string' in namespace 'std'

Android NDK中默认使用gnu-libstdc++,而其中的<string>中不包含to_string方法。可能使用std::stringstream替代:

#include <string>
#include <sstream>

class CharTools {
public:
    template<typename T>
    static std::string to_string(T val) {
        std::stringstream ss;
        ss << val;
        return ss.str();
    };
};

11、Unable to start program UE4.exe error

To fix the issue, you have to right click the game solution from your solution explorer and select the option "Set as StartUp Project" and that should highlight the game solution. Cntrl-F5 will then work.

https://answers.unrealengine.com/questions/218266/unable-to-start-program-ue4exe-error.html

12、error: illegal character encoding in string literal

当TEXT()方法中包含中文字符串时会报这个错。将代码源文件格式调整为UTF-8

13、error: no member named 'stoi' in namespace 'std'

<string>中不包含std::stoi, std::stol, std::stoll, std::stof, std::stod, std::stold
使用如下库中的函数替代
<cstdlib>
atoi, atol, atoll, atof

std::stoi        atoi
std::stol        atol
std::stoll        atoll
std::stof        atof
std::stod        atof
std::stold        atof

14、Cook failed

[2019.01.16-08.18.14:329][147]UATHelper: Packaging (Android (ETC1)): Took 79.729s to run UE4Editor-Cmd.exe, ExitCode=1
[2019.01.16-08.18.14:330][147]UATHelper: Packaging (Android (ETC1)): Cook failed. Deleting cooked data.
[2019.01.16-08.18.14:992][148]UATHelper: Packaging (Android (ETC1)): ERROR: Cook failed.

将<ProjectName>/Saved下的内容全部删除
将<ProjectName>/Intermediate下除ProjectFiles目录外的其它的内容全部删除
然后重新编译

15、error: initializer on function does not look like a pure-specifier

纯虚函数的默认方法体要分别写在头文件和定义文件中,clang++不支持将它们都写在头文件中

// ValueBoxType.h
class ValueBoxType {
    public:
        virtual ~ValueBoxType() = 0 {};
};

改成:

// ValueBoxType.h
class ValueBoxType {
    public:
        virtual ~ValueBoxType() = 0;
};

// ValueBoxType.cpp
ValueBoxType::~ValueBoxType() {
};

16、 error: declaration of 'MODE' shadows template parameter

类模板和类中的方法模板使用了相同的模板变量名时

17、error: explicit specialization of 'getTypeName' in class scope

函数特化时要在.h文件中声明,要在.cpp文件中定义

18、/cryptopp/include/misc.h(1849,9) :  error: use of undeclared identifier 'bswap_16'

如果使用了第三方库cryptopp,则会报上面的错。修改方式为注释掉misc.h中的一行:

#if defined(__GNUC__) && defined(__linux__)
//#define CRYPTOPP_BYTESWAP_AVAILABLE
#include <byteswap.h>
#endif

19、error: lambda capture 'LocalMapLayoutForCapture' is not used [-Werror,-Wunused-lambda-capture]

在如下文件中
C:\Epic Games\UE_4.18\Engine\Source\Programs\UnrealBuildTool\Platform\Android\AndroidToolChain.cs
将如下代码行

Result += " -Wno-unused-lambda-capture";  

注释掉。

20、如何屏蔽屏幕上的 joysticks

Project Settings:
Engine     -> Input        -> Moblie                 ->  Default Touch Interface (clear)


21、touch事件触发了两次

Project Settings:
Engine     -> Input        -> Mouse Properties       ->  Use Mouse for touch   (Disable)
Engine     -> Input        -> Moblie                 ->  Always show touch interface (Disable)

22、XXX has an inappropriate outermost, it was probably saved with a deprecated outer

具体错误信息如下:

LogLinker: Error: HOTRELOADED_SceneGameMode_0 has an inappropriate outermost, it was probably saved with a deprecated outer (file: /Projects/Content/Widget/W_Error.uasset) 

这个问题是由于W_Error.uasset中使用的SceneGameMode发生改动造成的。解决方式:删除W_Error中所有用到的SceneGameMode,然后重新创建SceneGameMode即可。

 

  • 6
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值