dansiegel / Mobile.BuildTools

The Mobile.BuildTools makes it easier to develop code bases in a clean, consistent, secure, and configurable way. Determine at Build which environment your app needs to run on, and what Client Secrets it should have. Plus many more amazing features!
http://mobilebuildtools.com
MIT License
228 stars 29 forks source link

Watermark Image - V2.0.245 #285

Closed emanalzoaubi closed 2 years ago

emanalzoaubi commented 3 years ago

Description

I'm trying to add a watermark on the application icon. I added a beta-version.png image as described in the documentation. However, I got the error "Invalid file name: It must contain only [^a-zA-Z0-9_.]+. C:\Users\User\source\repos\App1\App1\App1.Android\obj\Debug\110\Resources\drawable-hdpi\beta-version.png". After that, I tried to downgrade Mobile.BuildTools library to version 1.4.0.638 and the error is gone. Also, I changed the watermark image to be betaversion, the error of Invalid name is gone but I got a new error "Unhandled error while executing ImageResizerTask"

Environment

Reproduction App

  1. Install Mobile.Buildtools V2.0.245
  2. Create the Images folder and Debug subfolder in the solution directory.
  3. Edit buildtools.json file, adding { "$schema": "https://mobilebuildtools.com/schemas/v2/buildtools.schema.json", "images": { "directories": ["Images"], "conditionalDirectories": { "Debug": ["Images\Debug"] } } }
  4. add beta-version.png into Debug folder and icon.png to Images folder.
  5. build the app
  6. edit beta-version.json to be { "$schema": "http://mobilebuildtools.com/schemas/v2/resourceDefinition.schema.json", "ignore": true }
  7. edit icon.json to be { "$schema": "http://mobilebuildtools.com/schemas/v2/resourceDefinition.schema.json", "watermark": { "sourceFile": "beta-version" } }
  8. copy icon.json to Debug folder.
  9. build the application and get the error Unhandled error while executing ImageResizerTask
bijington commented 3 years ago

@emanalzoaubi At an initial glance from your error it looks like you didn't set the beta-version.png image to be ignored by the Build Tools. It should be documented here: https://mobilebuildtools.com/images/configuring-images/#watermarking-images There is a section that details how to ignore the files and why in there.

Basically Android refuses to accept - characters in image names which is why you see the error being reported. On top of that you don't actually want this watermark image to be included in your app as a separate resource which is why you need to mark it as ignored in its JSON file

emanalzoaubi commented 3 years ago

@bijington, Ok great! I've followed the documentation but I've got the below error "Unhandled error while executing ImageResizerTask". You can find "icon.json, beta-version.json & buildtools.json" in the attached. WatermarkTest.zip

bijington commented 3 years ago

@emanalzoaubi I think there may be a mistake in the documentation. I believe you need to include the file extension when specifying a sourceFile. Could you try changing the following parts from your json files:

Images/icon.json

change:

{
  "$schema": "http://mobilebuildtools.com/schemas/v2/resourceDefinition.schema.json",
  "watermark": {
    "sourceFile": "beta-version"
  }
}

to:

{
  "$schema": "http://mobilebuildtools.com/schemas/v2/resourceDefinition.schema.json",
  "watermark": {
    "sourceFile": "beta-version.png"
  }
}

You will also need to do the same for the Images/Debug/icon.json file.

emanalzoaubi commented 3 years ago

@bijington unfortunately, the same error occurs😫 Are there any constraints about the images size or their padding? I tried to add the used images in the sample but no chance 😓 The output image that appears in the output window is: { "InputFile":"C:\Users\User\source\repos\WatermarkTest\Images\icon.png", "OutputFile":"obj\Debug\110\Resources\drawable-ldpi\icon.png", "OutputLink":"Resources\drawable-ldpi\icon.png","BuildAction":null,"Height":0, "Width":0,"Scale":0.1875,"RequiresBackgroundColor":false,"ShouldBeVisible":true, "BackgroundColor":"","PaddingFactor":0.0,"PaddingColor":"", "Watermark":{"sourceFile":"beta-version.png","opacity":0.95} } Does the build action is the reason for this error?

bijington commented 3 years ago

I can confirm that I can see the same issue using your files. I have attached a full solution that shows the problem.

I will aim to take a look at why this is failing at some point

MBT.zip

bijington commented 2 years ago

I have finally managed to get around to investigating this (sorry for the delay). It looks like the watermark sourceFile path needs to be fully qualified at the moment. This is still a bug but if you were to fully qualify it for now then you could likely work around the issue. Or better yet if you are only wanting to render a banner then you could make use of the Drawn Watermarks feature.

TL-DR; definitely a bug and I am currently working on a fix

bijington commented 2 years ago

This was fixed by PR #292. Do we leave this open until release or can we close it?