Redth / ResizetizerNT

Add SVG's and PNG's to your shared Xamarin Project
MIT License
318 stars 31 forks source link

Not working in Android #23

Closed csk1nner closed 4 years ago

csk1nner commented 4 years ago

Hello there,

Thanks for sharing this tool. Running Xamarin.Forms (current bits on everything). When I compile against android target version 11.0 the appropriate directory gets created in the obj file (drawable-hdpi, drawable-mdpi, etc). The folders are populated with .png files as expected. When I run the app references to these created .png files are not displayed. Cleaned everything, rebuild, deleted bin and obj and rebuild. Not dice... Got anything that I can check? Works on iOS & UWP.

Thanks for the good work!

Caleb

acuntex commented 4 years ago

Can confirm. Yesterday it worked fine, today I made a Visual Studio Update and now it's not working any more.

acuntex commented 4 years ago

Update: If you use an image in a drawable xml, like a launch screen or if you use Resource.Drawable.someResource in Code it does not work any more.

acuntex commented 4 years ago

Could be related to https://github.com/xamarin/xamarin-android/pull/4190?

Redth commented 4 years ago

I'll have a look at this, it might be that build task ordering changed slightly.

dellis1972 commented 4 years ago

@acuntex so how have you set this up? I have tried the following

In my Resources\drawable folder I have a launcher.xml which contains the following.

<?xml version="1.0" encoding="UTF-8" ?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/icon" />

And in my application csproj I have

  <ItemGroup>
    <SharedImage Include="../../Assets/icon.svg" BaseSize="40,40" />
  </ItemGroup>

Which points to a shared svg which ResizetizerNT will generate the drawable/icon items from. I then used the launcher.xml as my app icon in the manifest. When deploying the app I see the icon being displayed.

I also checked the file packaged_resources to make sure that aapt2 put the required files in the package.

unzip -lv <path to project>/obj/Debug/android/bin/packaged_resources | grep icon
unzip -lv <path to project>/obj/Debug/android/bin/packaged_resources | grep launcher

I also have code in the C# part of the app to load the icon drawable, that seems to work as well. We are probably going to need some kind of repo project to figure out what is going on.

dellis1972 commented 4 years ago

Or some diagnostic build logs which show any build errors you are getting. They need to be diagnostic ones rather than just normal build logs since we need all the additional messages our system outputs to diagnose the issue. You can get these logs by doing the following

msbuild <app project.csproj> /bl /t:SignAndroidPackage 
acuntex commented 4 years ago

@dellis1972 The drawables get created, they are there. But the drawable-xxx folders are under obj/Debug/resizetizer. They not only get created during the build, they also get created once you load the project in the IDE.

My guess (completely without any proof) is that the new build process doesn't look for drawable-folders under obj/Debug/** but only in obj/Debug/res.

Will create a repo project

dellis1972 commented 4 years ago

@acuntex the new build process doesn't look in a single folder, it uses the AndroidResource and LibraryResourceDirectories ItemGroups to collect resources.

Now these is some additional processing which puts the main app resources files in obj/Debug/res , these are things link changing the casing of the files to match what android expects. However not all the resources end up in that one folder. There are multiple folders from the various Library projects which are referenced. These for example end up in obj/Debug/lp/**/res.

So the system is setup to look for resources in multiple places. Resizetizer.NT hooks into this process via the targets here https://github.com/Redth/ResizetizerNT/blob/master/Resizetizer.NT/Resizetizer.NT.targets#L193

These item groups are then processed by the _CompileResources target. You should be seeing output like this

Target "_CompileResources" in file "/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Aapt2.targets":
  Building target "_CompileResources" completely.
  Output file "obj/Debug/resizetizer/../flat/drawable-xhdpi_icon.png.flat" does not exist.
  Using "Aapt2Compile" task from assembly "/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Build.Tasks.dll".
  Task "Aapt2Compile"
    Executing compile -o obj/Debug/flat/ obj/Debug/resizetizer/drawable-xxhdpi/icon.png

The compiled flat file output is then packaged with the Aapt2Link task in the CreateBaseApkWithAapt2 target. The file that Aapt2Link produces is then used as a basis for the final apk.

acuntex commented 4 years ago

Ok, I tried to create a repro and the small repro worked.

I've looked at the files in obj/Debug and there was a difference: In the big project, the drawable files were missing in the files.cache file. R.txt and R.java weren't created yet as in the small project containing the drawables.

Through the BinaryLogs i was able to find out that it is related to the GoogleServicesJson. If you install Xamarin.Firebase.Analytics and add a google-services.json then it will fail.

msbuild.binlog.zip

dellis1972 commented 4 years ago

Ok I have repo'd the issue.

For some reason adding the GoogleServicesJson file is causing the LibraryResourceDirectories ItemGroup to loose ALL of the Resizetizer.NT data.

acuntex commented 4 years ago

Thank you!

dellis1972 commented 4 years ago

PR up for xamarin.android https://github.com/xamarin/xamarin-android/pull/5038

MagicAndre1981 commented 4 years ago

For me it also doesn't for Android, but works fine in UWP:

6>Output file "D:\foo.bar.App\obj\Debug\foo.bar.App.Android\AnyCPU\resizetizer.stamp" does not exist.
6>Set Property: ResizetizerIntermediateOutputPath=D:\foo.bar.App\obj\Debug\foo.bar.App.Android\AnyCPU\resizetize\r\
6>Using "ResizetizeSharedImages" task from assembly "D:\foo.bar.App\packages\Resizetizer.NT.0.2.0-preview1\build\Resizetizer.NT.dll".
6>Task "ResizetizeSharedImages"
6>  Task Parameter:PlatformType=android
6>  Task Parameter:IntermediateOutputPath=D:\foo.bar.App\obj\Debug\foo.bar.App.Android\AnyCPU\resizetize\r\
6>  Task Parameter:InputsFile=D:\foo.bar.App\obj\Debug\foo.bar.App.Android\AnyCPU\resizetizer.inputs
6>  Task Parameter:
6>      SharedImages=
6>          D:\foo.bar.App\foo.bar.App\Ffoo.bar.App\Resources\logo.png
6>                  BaseSize=327, 90
6>                  MSBuildSourceProjectFile=D:\foo.bar.App\foo.bar.App\foo.bar.App\foo.bar.App.csproj
6>                  MSBuildSourceTargetName=GetSharedImages
6>                  Name=foo.bar.App
6>                  OriginalItemSpec=..\foo.bar.App\foo.bar.App.csproj
6>                  OutputItemType=
6>                  Project={e38387f6-ce9b-42d5-9cd9-8750a31906dd}
6>                  ReferenceSourceTarget=ProjectReference
6>                  Targets=
6>D:\foo.bar\packages\Resizetizer.NT.0.2.0-preview1\build\Resizetizer.NT.targets(155,3): error : One or more errors occurred.
6>Done executing task "ResizetizeSharedImages" -- FAILED.
6>Done building target "ResizetizeImages" in project "foo.bar.App.Android.csproj" -- FAILED.

As you can see I change IntermediateOutputPath via Directory.Build.props to have 1 obj folder in root of sln with subfolders for each project to be able to delete obj folders easier. Is this an issue or my still used packages.config?

VS2017 15.9.26 Resizetizer.NT 0.2.0-preview1 Android API 28-Pie

MagicAndre1981 commented 4 years ago

For me it also doesn't for Android, but works fine in UWP:

VS2017 15.9.26 Resizetizer.NT 0.2.0-preview1 Android API 28-Pie

ok @Redth it works today, so it still works fine with VS2017 and packages.config 😊