[FIXED] Little problem with Application title for Android

Found a bug? Post information about it here so we can fix it!

Moderator: Moderators

Post Reply
User avatar
Ats
Posts: 817
Joined: Fri Sep 28, 2012 10:05 am
Contact:

[FIXED] Little problem with Application title for Android

Post 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?
Last edited by Ats on Tue May 13, 2025 10:03 am, edited 2 times in total.
User avatar
VilleK
Site Admin
Posts: 2381
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Little problem with Application title for Android

Post 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?
User avatar
Ats
Posts: 817
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Little problem with Application title for Android

Post 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?
User avatar
VilleK
Site Admin
Posts: 2381
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Little problem with Application title for Android

Post by VilleK »

Please try this build.

[edit: removed incorrect build]
User avatar
Ats
Posts: 817
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Little problem with Application title for Android

Post 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?
User avatar
Ats
Posts: 817
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Little problem with Application title for Android

Post 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.
User avatar
VilleK
Site Admin
Posts: 2381
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Little problem with Application title for Android

Post by VilleK »

I had a feeling exename would not be correct but I wasn't sure :). Please try this new build.

[edit: removed build]
User avatar
Ats
Posts: 817
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Little problem with Application title for Android

Post 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:
User avatar
VilleK
Site Admin
Posts: 2381
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Little problem with Application title for Android

Post by VilleK »

New attempt.
Attachments
ZGameEditor_beta.zip
(4.75 MiB) Downloaded 11 times
User avatar
Ats
Posts: 817
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Little problem with Application title for Android

Post by Ats »

Perfect. Thanks!
Now I can continue with the fileDemo on Android :wink:
User avatar
Ats
Posts: 817
Joined: Fri Sep 28, 2012 10:05 am
Contact:

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

Post 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.
Post Reply