Launch with Command Line Argument on Android

Hi,

I am trying to launch my game on Android with some command line arguments. Specifically I would like to use either of the trace options in the Insights documentation. I cannot find any way to set command line arguments, either via Launch in editor, or packaging and installing a build using a bat file.

I have tried

  • modifying the UE4CommandLine.txt, and putting it in my game folder on the android device
  • modifying the UE4CommandLine.txt, and putting it in /mnt/sdcard/UE4Game/UE4Game/UE4CommandLine.txt, as with PushCommandLine.bat
  • using the editor preferences’ additional launch parameters for mobile

The game runs fine, but none of the command line arguments seem to be applied.
Any ideas? Thank you!
Patrick

Ok, I fixed the problem by upgrading to UE 4.24, and making sure to modify the existing UE4CommandLine in the device’s game folder. I can now create a tracefile, then copy it to my computer to view it in Insights.

For packaged builds, I run these commands in a bat file to run the game on Android:
%ANDROID_HOME%\platform-tools\adb.exe push UE4CommandLine.txt /mnt/sdcard/UE4Game/PROJECTNAME/UE4CommandLine.txt
%ANDROID_HOME%\platform-tools\adb.exe shell am start -n com.COMPANYNAME.EXENAME/com.epicgames.ue4.SplashActivity

I also found out you can run console commands via adb, such as: adb shell am broadcast -a android.intent.action.RUN -e cmd 'stat sceneRendering’

2 Likes

This is very helpful. Thank you

For UE5 in case anyone needs.

  1. Build your game in Development.
  2. Open the Android Studio project as indicated here Debugging Android Projects
  3. Open the file under app > assets > UECommandLine.txt
  4. You will see it contains something like …/…/…/YourGameName/YourGameName.uproject. Add the following so it looks like:
../../../YourGameName/YourGameName.uproject -tracefile=/storage/emulated/0/Android/data/com.YourCompanyName.YourGameName/files/UnrealGame/YourGameName/YourGameName/Saved/My_Trace.utrace -trace=counters,cpu,frame,bookmark,file,loadtime,gpu,rhicommands,rendercommands,object -statnamedevents
  1. Save the file and execute the game again as indicated in Debugging Android Projects
  2. The last step will install the game to your connected Android device with the modiffied UECommandLine.txt
  3. Just play your game to gatter the stats info you need and then exit the game
  4. Pull the traced file to your pc using
adb.exe pull /storage/emulated/0/Android/data/com.YourCompanyName.YourGameName/files/UnrealGame/YourGameName/YourGameName/Saved/My_Trace.utrace "C:\My_Trace.utrace"

NOTE: if you can not find the trace file in the path:

/storage/emulated/0/Android/data/com.YourCompanyName.YourGameName/files/UnrealGame/YourGameName/YourGameName/Saved/.

I’ll sugest you to use FAndroidMisc::GamePersistentDownloadDir() to find out what is a valid location to use for your trace to be written.
I added the following in my GameMode Tick function, then I built the game and ran it so I can see in the screen the debug msg with the path.

void MyGameMode::Tick(float DeltaTime)
{
        Super::Tick(DeltaTime);
#if PLATFORM_ANDROID
	UKismetSystemLibrary::PrintString(this, FString::Printf(TEXT("Write directory: %s"), FAndroidMisc::GamePersistentDownloadDir()));
#endif //PLATFORM_ANDROID
}
4 Likes