Packaging with Plugin

Hi, I’m trying to make my project’s android packaging, with the yar3333 plugin (GitHub - yar3333/text-to-speech-ue4: Text-to-speech UE4 plugin for Windows (SAPI). Tested on UE 4.21)

The plugin works in editor, but during the packaging the error “FMRTTSLib.h file not found” appears

How can I solve it?

UATHelper: Packaging (Android (ASTC)):   PLATFORM_ANDROID_NDK_VERSION = 140200
UATHelper: Packaging (Android (ASTC)):   NDK toolchain: r14b, NDK version: 19, GccVersion: 4.9, ClangVersion: 3.8.275480
UATHelper: Packaging (Android (ASTC)):   Parsing headers for MyProject
UATHelper: Packaging (Android (ASTC)):     Running UnrealHeaderTool "C:\Users\Ippolito\Documents\Unreal Projects\MyProject\MyProject.uproject" "C:\Users\Ippolito\Documents\Unreal Projects\MyProject\Intermediate\Build\Android\MyProject\Development\MyProject.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error"
 -Unattended -WarningsAsErrors -installed
UATHelper: Packaging (Android (ASTC)):   Reflection code generated for MyProject in 5,9450368 seconds
UATHelper: Packaging (Android (ASTC)):   Compiling Native code with NDK API 'android-19'
UATHelper: Packaging (Android (ASTC)):   Writing manifest to C:\Users\Ippolito\Documents\Unreal Projects\MyProject\Intermediate\Build\Manifest.xml
UATHelper: Packaging (Android (ASTC)):   Building 9 actions with 8 processes...
UATHelper: Packaging (Android (ASTC)):     [1/9] SharedPCH.Engine.h [armv7-es2]
UATHelper: Packaging (Android (ASTC)):     [2/9] Module.TextToSpeech.cpp [armv7-es2]
UATHelper: Packaging (Android (ASTC)):     In file included from C:/Users/Ippolito/Documents/Unreal Projects/MyProject/Plugins/text-to-speech-ue4-master/Intermediate/Build/Android/UE4/Development/TextToSpeech/Module.TextToSpeech.cpp:4:
UATHelper: Packaging (Android (ASTC)):     C:/Users/Ippolito/Documents/Unreal Projects/MyProject/Plugins/text-to-speech-ue4-master/Source/TextToSpeechSoundWave.cpp(3,10):  fatal error: 'FMRTTSLib.h' file not found
UATHelper: Packaging (Android (ASTC)):     #include "FMRTTSLib.h"
UATHelper: Packaging (Android (ASTC)):              ^
UATHelper: Packaging (Android (ASTC)):     1 error generated.
PackagingResults: Error: 'FMRTTSLib.h' file not found
UATHelper: Packaging (Android (ASTC)):     [3/9] MyProject.init.gen.cpp [armv7-es2]
UATHelper: Packaging (Android (ASTC)):     [4/9] MyProjectGameModeBase.cpp [armv7-es2]
UATHelper: Packaging (Android (ASTC)):     [5/9] MyProject.cpp [armv7-es2]
UATHelper: Packaging (Android (ASTC)):     [6/9] MyProjectGameModeBase.gen.cpp [armv7-es2]
UATHelper: Packaging (Android (ASTC)):     [7/9] Module.TextToSpeech.gen.cpp [armv7-es2]
UATHelper: Packaging (Android (ASTC)): Took 29,0976005s to run UnrealBuildTool.exe, ExitCode=5
UATHelper: Packaging (Android (ASTC)): UnrealBuildTool failed. See log for more details. (C:\Users\Ippolito\AppData\Roaming\Unreal Engine\AutomationTool\Logs\A+Epic+Games+UE_4.23\UBT-MyProject-Android-Development.txt)
UATHelper: Packaging (Android (ASTC)): AutomationTool exiting with ExitCode=5 (5)
UATHelper: Packaging (Android (ASTC)): BUILD FAILED
PackagingResults: Error: Unknown Error

Hi there,

Got here from Reddit. At first glance this looks like an IWYU problem.
Please try to those and let me know how it goes:

  • Pack your project for window (x64 or x32) → if it succeeds the problem is FMRTTSLib doesn’t have an Android-specific lib compiled for that platform and since it’s a third party you need to either get a hold of their project and compile it or get the library compiled for your needed platform from them (you might get away with the source folder of the ThirdParty, but I am not sure those are enough). However, this should result in linking errors rather than what you have in your logs, anyway worth a shot.
  • Add the full include path inside the file: wherever you see #include “FMRTTSLib.h”, replace it with #include “ThirdParty/FMRTTSLib/include/FMRTTSLib.h” this is the full path relative to your project. This should solve it, if it’s an include path problem
  • Create a textToSpeech.Build.cs file in your plugin structure like here FileStrucutre and add your third party library in there.

Let me know what results you get from those so we can look into further possibilities.

Good luck,
Alex

Alex thanks a lot for the answer,
I did what you said, and the mistake has practically disappeared.
But now another one was born (however the packaging also fails for windows)

UATHelper: Packaging (Android (ASTC)):     C:/Users/Ippolito/Documents/Unreal Projects/MyProject/Plugins/text-to-speech-ue4-master/Source/TextToSpeechSoundWave.cpp(12,67):  error: cannot initialize a parameter of type 'const wchar_t *' with an rvalue of type 'const TCHAR *' (aka 'const char16_t *')
UATHelper: Packaging (Android (ASTC)):             uint8 *AudioBuffer = (uint8*)FMRTTSLib::FMRTTSLibMain::TextToWav(*VoiceRequiredAttributes, *VoiceOptionalAttributes, Rate, *Text, &BytesRead);
UATHelper: Packaging (Android (ASTC)):                                                                              ^~~~~~~~~~~~~~~~~~~~~~~~
UATHelper: Packaging (Android (ASTC)):     C:/Users/Ippolito/Documents/Unreal Projects/MyProject/Plugins/text-to-speech-ue4-master\ThirdParty/FMRTTSLib/include/FMRTTSLib.h(6,42):  note: passing argument to parameter 'voiceRequiredAttributes' here
UATHelper: Packaging (Android (ASTC)):                             static char* TextToWav(const wchar_t* voiceRequiredAttributes, const wchar_t* voiceOptionalAttributes, long Rate, const wchar_t* textToRender, unsigned long* bytesRead);
UATHelper: Packaging (Android (ASTC)):                                                                   ^
UATHelper: Packaging (Android (ASTC)):     1 error generated.
PackagingResults: Error: cannot initialize a parameter of type 'const wchar_t *' with an rvalue of type 'const TCHAR *' (aka 'const char16_t *')
UATHelper: Packaging (Android (ASTC)):     [2/4] Module.TextToSpeech.gen.cpp [arm64-es2]
UATHelper: Packaging (Android (ASTC)): Took 15,1367553s to run UnrealBuildTool.exe, ExitCode=5

Well, that’s great actually. New errors mean progress.
I will assume you didn’t change the source code much from the github link you added in your initial report. If you did, it would be cool if we could see the source code of your project and modified plugin as well. But let’s take some guesses first.

Looking at this log looks like you have 1 error left:

  • TextToSpeechSoundWave.cpp(12) → This is a standard const FString& to const wchar_t* cast
    This should be indeed done with the * operator in your case, but types can get mismatched.

What I would recommend here is to explicitly call the GetCharArray().GetData() function on your FString.

uint8 *AudioBuffer = (uint8*)FMRTTSLib::FMRTTSLibMain::TextToWav(*VoiceRequiredAttributes, *VoiceOptionalAttributes, Rate, *Text, &BytesRead); 

will transform into GetCharArray().GetData()

uint8 *AudioBuffer = (uint8*)FMRTTSLib::FMRTTSLibMain::TextToWav(VoiceRequiredAttributes.GetCharArray().GetData(), *VoiceOptionalAttributes, Rate, *Text, &BytesRead); 

So try to replace *VoiceRequiredAttributes with VoiceRequiredAttributes.GetCharArray().GetData()

However, relax, this is a small type error, we will be able to fix it and pack your project, maybe this won’t fix it, but we will get the cast right eventually.

You can find more info here about the cast itself, the GetCharArray is just the first thing that looks like doing what you need.

I would like to correct one thing. The correct way is to use GetCharArray().GetData()
Also, storing the string inside a temp variable before passing it into the function seems to fix the problem at least on some platforms. Give it a try!

const wchar_t* tempVariable = refString.GetCharArray().GetData();
uint8 *AudioBuffer = (uint8*)FMRTTSLib::FMRTTSLibMain::TextToWav(tempVariable, *VoiceOptionalAttributes, Rate, *Text, &BytesRead);

I’ve edited the comment above as well to add .GetData()

Then premising that I am still learning to program (in fact my project is in blueprint). I have to say that I’m learning a lot of things because of you.
I first tried replacing * VoiceRequiredAttributes with VoiceRequiredAttributes.GetCharArray (). GetData ()

and the result of the packaging is this:

UATHelper: Packaging (Android (ASTC)): [1/3] Module.TextToSpeech.cpp [arm64-es2]
UATHelper: Packaging (Android (ASTC)): In file included from C:/Users/Ippolito/Documents/Unreal Projects/MyProject/Plugins/text-to-speech-ue4-master/Intermediate/Build/Android/UE4/Development/TextToSpeech/Module.TextToSpeech.cpp:4:
UATHelper: Packaging (Android (ASTC)): C:/Users/Ippolito/Documents/Unreal Projects/MyProject/Plugins/text-to-speech-ue4-master/Source/TextToSpeechSoundWave.cpp(12,67): error: cannot initialize a parameter of type ‘const wchar_t *’ with an rvalue of type ‘const ElementType *’ (aka ‘const char16_t *’)
UATHelper: Packaging (Android (ASTC)): uint8 AudioBuffer = (uint8)FMRTTSLib::FMRTTSLibMain::TextToWav(VoiceRequiredAttributes.GetCharArray().GetData(), *VoiceOptionalAttributes, Rate, *Text, &BytesRead);
UATHelper: Packaging (Android (ASTC)): ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
UATHelper: Packaging (Android (ASTC)): C:/Users/Ippolito/Documents/Unreal Projects/MyProject/Plugins/text-to-speech-ue4-master\ThirdParty/FMRTTSLib/include/FMRTTSLib.h(6,42): note: passing argument to parameter ‘voiceRequiredAttributes’ here
UATHelper: Packaging (Android (ASTC)): static char* TextToWav(const wchar_t* voiceRequiredAttributes, const wchar_t* voiceOptionalAttributes, long Rate, const wchar_t* textToRender, unsigned long* bytesRead);
UATHelper: Packaging (Android (ASTC)): ^
UATHelper: Packaging (Android (ASTC)): 1 error generated.
PackagingResults: Error: cannot initialize a parameter of type ‘const wchar_t *’ with an rvalue of type ‘const ElementType *’ (aka ‘const char16_t *’)

then I tried with tempvariable

https://drive.google.com/file/d/1DlG5s0tPAOKKHlNA9NbmiqCphJ3xfv3n/view?usp=sharing

Hello, my bad, so in here:
const wchar_t* tempVariable = refString.GetCharArray().GetData();

the refString was supposed to be your referenced string, that being VoiceRequiredAttributes
so const wchar_t* tempVariable = VoiceRequiredAttributes.GetCharArray().GetData();

also you’ve placed the ‘;’ between ‘()’ according to the logs, looks like this: refString.GetCharArray().GetData(:wink:

Give it a try like this:

const wchar_t* tempVariable = VoiceRequiredAttributes.GetCharArray().GetData();

Also in the other log you can see the problem ended up to be casting: ‘const wchar_t *’ to ‘const char16_t *’ which should be pretty easy, since wchar is char32 or char64 depending on platform. So we are on the right track

is it possible that android has been excluded in the build.cs?

UATHelper: Packaging (Android (ASTC)):     [1/3] Module.TextToSpeech.cpp [arm64-es2]
UATHelper: Packaging (Android (ASTC)):     In file included from C:/Users/Ippolito/Documents/Unreal Projects/MyProject/Plugins/text-to-speech-ue4-master/Intermediate/Build/Android/UE4/Development/TextToSpeech/Module.TextToSpeech.cpp:4:
UATHelper: Packaging (Android (ASTC)):     C:/Users/Ippolito/Documents/Unreal Projects/MyProject/Plugins/text-to-speech-ue4-master/Source/TextToSpeechSoundWave.cpp(12,17):  error: cannot initialize a variable of type 'const wchar_t *' with an rvalue of type 'const ElementType *' (aka 'const char16_t *')
UATHelper: Packaging (Android (ASTC)):             const wchar_t* tempVariable = VoiceRequiredAttributes.GetCharArray().GetData();
PackagingResults: Error: cannot initialize a variable of type 'const wchar_t *' with an rvalue of type 'const ElementType *' (aka 'const char16_t *')
UATHelper: Packaging (Android (ASTC)):                            ^              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
UATHelper: Packaging (Android (ASTC)):     1 error generated.
UATHelper: Packaging (Android (ASTC)): Took 11,7936348s to run UnrealBuildTool.exe, ExitCode=5

Hi there,

Nope, that’s not possible, the .Build.cs is a file that allows you to include other Unreal-Modules inside the current module, it has nothing to do with this problem.

If you really want to know what is happening here, I will explain this brief:
To support multiple platforms, Unreal uses type aliases, this means they are going to have a type, for instance, TChar which you can find inside GenericPlatform\GenericPlatform.h then for each platform, they will typedef the corresponding type, for instance TCHAR is basically wchar_t, that’s why your code is compiling on windows, however on Android it looks like TChar is defined to be char16_t , so you will require a cast to make them compatible. You can read all about it here

Now back to the solution:
I will give you the quick dirty work, you can find the explanation here

include those:

#include <iostream>
#include <locale>
#include <memory>
#include <codecvt>
#include <string>

Change your code to this:

    int cSize = VoiceRequiredAttributes.Len();
    const char16_t* blah = VoiceRequiredAttributes.GetCharArray().GetData();

    std::wstring_convert<std::codecvt_utf16<wchar_t, 0x10ffff, std::little_endian>, wchar_t> conv;

    std::wstring result = conv.from_bytes(
        reinterpret_cast<const char*> (&blah[0]),
        reinterpret_cast<const char*> (&blah[0] + cSize));

    const wchar_t* tempVariable = result.c_str();

Just a warning, this should fail the compilation on windows now. consider using #if PLATFORM_ANDROID info here

Hi, sorry if I ask you (my ignorance). Where should I add this code?

The first block (the one with includes) should be added after your other #include’s
The second block should replace your const wchar_t* tempVariable = VoiceRequiredAttributes.GetCharArray().GetData();

https://drive.google.com/file/d/1zZbNngyWB-R4XjJxRGQKt3nbSyKkaVNw/view?usp=sharing

UATHelper: Packaging (Android (ASTC)):   Building 3 actions with 8 processes...
UATHelper: Packaging (Android (ASTC)):     [1/3] Module.TextToSpeech.cpp [arm64-es2]
UATHelper: Packaging (Android (ASTC)):     In file included from C:/Users/Ippolito/Documents/Unreal Projects/MyProject/Plugins/text-to-speech-ue4-master/Intermediate/Build/Android/UE4/Development/TextToSpeech/Module.TextToSpeech.cpp:4:
UATHelper: Packaging (Android (ASTC)):     C:/Users/Ippolito/Documents/Unreal Projects/MyProject/Plugins/text-to-speech-ue4-master/Source/TextToSpeechSoundWave.cpp(7,10):  fatal error: 'codecvt' file not found
UATHelper: Packaging (Android (ASTC)):     #include <codecvt>
UATHelper: Packaging (Android (ASTC)):              ^
UATHelper: Packaging (Android (ASTC)):     1 error generated.
PackagingResults: Error: 'codecvt' file not found
UATHelper: Packaging (Android (ASTC)): Took 9,1324697s to run UnrealBuildTool.exe, ExitCode=5

If the header is not supported by Unreal’s Android configuration you can find similar functionality in other libraries such as boost
Or any other with that support, you can even write your own

I tried to use boost, but I don’t think I succeeded, do you know an easy way to include it?
(sorry for bad English)

Sure thing! Take a look at this
However, I would still do the conversion myself, there are plenty of materials on the web for conversion from u16 to wC (L32)

Hi there, did you manage to finish this?