Page 1 of 1

[FIXED] Little problem with Application title for Android

Posted: Mon May 12, 2025 8:20 am
by Ats
I was trying to build the FileDemo for Android but got this error:
BUILD FAILED
C:\Android\android-sdk-windows\tools\ant\build.xml:1135: The following error occurred while executing this line:
C:\Android\android-sdk-windows\tools\ant\build.xml:1147: Value for 'output' is not valid. It must resolve to a single path
Turns out it's the ":" in ApplicationTitle "ZGameEditor: FileDemo" that breaks the build because it uses the same name for the filename and the name of the application.

The file name is used in build.xml:
<project name="$title$" default="help">

While the application name is listed in AndroidManifest.xml:
android:label="$title$"

Is it possible to sanitize the filename for build.xml and have an untouched application name for AndroidManifest.xml?
From what I understand, we just need to add a line in frmEditor.pas:

Code: Select all

  try
    Lookups.Add('$sdkpath$', StringReplace(Self.AndroidSdkPath,'\','/',[rfReplaceAll]) );
    Lookups.Add('$sdkpath_normal$',Self.AndroidSdkPath);
    Lookups.Add('$package$', String(Self.ZApp.AndroidPackageName) );
    Lookups.Add('$title$', String(Self.ZApp.Caption) );
    Lookups.Add('$versionname$', String(Self.ZApp.AndroidVersionName) );
    Lookups.Add('$versionnumber$', IntToStr(Self.ZApp.AndroidVersionNumber) );
So we need a SanitizeFilename function somewhere:

Code: Select all

function SanitizeFilename(const S: string): string;
const
  InvalidChars: set of Char = ['\', '/', ':', '*', '?', '"', '<', '>', '|'];
var
  C: Char;
begin
  Result := '';
  for C in S do
  begin
    if C in InvalidChars then
      Result := Result + '_'  // Replace with underscore
    else
      Result := Result + C;
  end;
end;
Add that line at 5351 in frmEditor.pas:
Lookups.Add('$filename$', SanitizeFilename(String(Self.ZApp.Caption)));

And modify build.xml:
<project name="$filename$" default="help">

Finaly, maybe it could be used for the exe build?
Currently, the name of the exe is the name of the zgeproj file, not the (sanitized) caption name.

Or maybe we could simply use the zgeproj name for the $filename$ for android?
What do you think would be the best?

Re: Little problem with Application title for Android

Posted: Mon May 12, 2025 9:02 am
by VilleK
Ats wrote: Mon May 12, 2025 8:20 am Or maybe we could simply use the zgeproj name for the $filename$ for android?
This seems appears to me as the simplest solution. Can you please make a pull request with this?

Re: Little problem with Application title for Android

Posted: Mon May 12, 2025 4:12 pm
by Ats
I've made the pull request.
It's just frmEditor.pas:
Lookups.Add('$filename$', Application.exename );
and build.xml:
<project name="$filename$" default="help">

can you build a new ZGameEditor.zip?

Re: Little problem with Application title for Android

Posted: Mon May 12, 2025 4:26 pm
by VilleK
Please try this build.

[edit: removed incorrect build]

Re: Little problem with Application title for Android

Posted: Mon May 12, 2025 4:54 pm
by Ats
It wasn't Application.exename :lol:

Now I get
<project name="C:\Users\Ats\Desktop\ZGameEditor\ZGameEditor.exe" default="help">

Might be CurrentFileName, then?

Re: Little problem with Application title for Android

Posted: Mon May 12, 2025 7:59 pm
by Ats
You wrote this in frmEditor.pas:
Section := 'Project: ' + ExtractFileName(CurrentFileName);

so I guess CurrentFileName is the complete path and it should be
Lookups.Add('$filename$', ExtractFileName(CurrentFileName) );
instead of
Lookups.Add('$filename$', CurrentFileName );
??

I tried to reinstall embarcadero delphi in order to try, but didn't get anywhere.

Re: Little problem with Application title for Android

Posted: Tue May 13, 2025 7:30 am
by VilleK
I had a feeling exename would not be correct but I wasn't sure :). Please try this new build.

[edit: removed build]

Re: Little problem with Application title for Android

Posted: Tue May 13, 2025 8:59 am
by Ats
Almost. Now it exports the project name + the file extension:

<project name="FileDemo.zgeproj" default="help">

So I think it should be:
Lookups.Add('$filename$', ChangeFileExt(ExtractFileName(CurrentFileName), '') );

I hope it will suppress the whole .zproj extension, and not leave a point with no extension at the end.
The whole suppress things is rather complicated, instead of simply adding path and extension if needed :lol:

Re: Little problem with Application title for Android

Posted: Tue May 13, 2025 9:24 am
by VilleK
New attempt.

Re: Little problem with Application title for Android

Posted: Tue May 13, 2025 10:02 am
by Ats
Perfect. Thanks!
Now I can continue with the fileDemo on Android :wink:

Re: [FIXED] Little problem with Application title for Android

Posted: Tue May 13, 2025 4:44 pm
by Ats
There's still one little problem, as building the APK (debug) from ZGameEditor also creates run.bat, but with the $title$ name on the first line, instead of the $filename$:
"C:\Android\android-sdk-windows\platform-tools\adb" install -r "C:\Dropbox\System\ZGameEditor\Projects\FileDemo\com.mydomain.filedemo\bin\ZGameEditor: FileDemo-debug.apk"

in zgameeditor-master\tools\ZDesigner\exe\Android\Template\base, run.bat is looking like this:
"$sdkpath_normal$\platform-tools\adb" install -r "$apkpath$"

Which comes from frmEditor.pas line 5368:
ApkFileName := ProjectPath + 'bin\' + String(Self.ZApp.Caption);

It should be replaced by:
ApkFileName := ProjectPath + 'bin\' + ChangeFileExt(ExtractFileName(CurrentFileName), '');

I made a git pull.