Contents · Forum Home · StreamSec Tools 4.1.5.365 documentation

Deploy a FireMonkey application with StreamSec to Android and iOS

Deploy a FireMonkey app and a small text file to an Android phone or an iPhone. On startup the app uses StreamSec to hash the installed file. The form displays StreamSec asset verified when the bytes match.

Create the app and the asset

  1. In Delphi 13 choose File > New > Multi-Device Application - Delphi and select Blank Application. Save the project. On the form place a TLabel named ResultLabel and set its Align to Client.
  2. In Project > Options > Delphi Compiler, set the search path for both mobile targets. With the source edition, add the StreamSec Source directory. For the Delphi 13 DCU trial, use Source\D13\android64\dcu for Android 64-bit and Source\D13\ios64\dcu for iOS Device 64-bit. See Add the library to a Delphi project.
  3. Create streamsec-mobile-check.txt beside the project. Save the single line StreamSec mobile in ASCII with one Windows line ending (CR LF). The expected digest includes that line ending.
  4. Add a unit named TaskMobile to the project. Declare MobileAssetStatus in its interface and put the following uses clause and implementation after implementation.
uses
  System.SysUtils, System.IOUtils,
  stDERUtils, stSecUtils, stSHA256;
function MobileAssetStatus(const aDocumentsPath: string): string;
const
  cExpected = '9c863d1968501817b1abc75ba20a532c11259139fca75bfa03ccf6f9432cef87';
var
  lFileName, lHash: string;
begin
  lFileName := TPath.Combine(aDocumentsPath, 'streamsec-mobile-check.txt');
  if not TFile.Exists(lFileName) then
    Exit('Asset missing');
  lHash := OSToHex(DigestFile(haSHA256, lFileName), True);
  if SameText(lHash, cExpected) then
    Result := 'StreamSec asset verified'
  else
    Result := 'Asset contents differ';
end;

The stSHA256 unit registers the digest used by DigestFile. Add System.IOUtils and TaskMobile to the form unit's implementation uses clause. In the Object Inspector, create the form's OnCreate handler and give it the body shown below. The example's form class is TMobileForm. Keep the wizard's System.StartUpCopy unit in the project source so the data file is copied to the app's private storage on launch.

procedure TMobileForm.FormCreate(Sender: TObject);
begin
  ResultLabel.Text := MobileAssetStatus(TPath.GetDocumentsPath);
end;

Run on an Android device

  1. Install the Android 64-bit target and configure its SDK, NDK and JDK in RAD Studio. Enable USB debugging on the phone, connect it to the development PC and accept the phone's debugging authorization prompt.
  2. In Project Manager activate Android 64-bit and choose the connected phone under Target. Select the Debug build configuration and Development platform configuration.
  3. Open Project > Deployment for that configuration. Add streamsec-mobile-check.txt, set its Remote Path to assets\internal\ and keep the file enabled.
  4. Choose Run > Run Without Debugging. The app reads the deployed asset from its internal files directory through TPath.GetDocumentsPath. Check that the label displays StreamSec asset verified.

For device detection and SDK selection, see Running an Android application on a device.

Run on an iPhone

  1. On the Mac, configure Xcode and the development signing identity. Connect the iPhone, enable Developer Mode if required, and run the Platform Assistant (PAServer) for your RAD Studio version.
  2. In RAD Studio configure the Mac connection profile and import the iOS device SDK from it. Activate iOS Device - 64 bit, choose the Development platform configuration and select the connected iPhone. Use a bundle identifier and development provisioning profile that cover this app and device.
  3. Open Project > Deployment for the iOS device and the Debug build configuration. Add the same file and set its Remote Path to StartUp\Documents\.
  4. Choose Run > Run Without Debugging. On launch the file is copied into the app's Documents directory. Look for the same StreamSec asset verified message on the iPhone.

For signing and profile selection, see Provisioning an iOS application.

Check a different result

Asset missing means the app could not find the file at the expected path. Check the file name, remote path and enabled deployment entry for the platform and configuration you actually ran. Asset contents differ means a file was present and its digest differed. Check the exact text, line ending and absence of a byte-order mark. Startup copying preserves an existing file in the app's Documents directory. To check a corrected asset, deploy to a fresh installation of this sample on a test device. Deployment entries apply to the selected configuration. When switching to Release, check the file's entry for that configuration too. See Adding files in the Deployment Manager.

Reference

stSecUtils · stSHA256 · stDERUtils

Related tasks