Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I disable HotReload for Release builds? #115

Closed
LuoyeAn opened this issue Aug 19, 2019 · 20 comments
Closed

How do I disable HotReload for Release builds? #115

LuoyeAn opened this issue Aug 19, 2019 · 20 comments
Assignees
Labels
question Further information is requested reloader

Comments

@LuoyeAn
Copy link

LuoyeAn commented Aug 19, 2019

I am happy to use HotReload for my Project. But it makes bigger size for android apk.

After unzipping the apk, I see Xamarin.Forms.HotReload.Reloader.dll ,Microsoft.CodeAnalysis.CSharp.dll and Microsoft.CodeAnalysis.dll in assemblies folder.

Any way to remove them? Thanks!

@AndreiMisiukevich
Copy link
Owner

Hi) Yeas, of course it's possible)

@AndreiMisiukevich
Copy link
Owner

can you share csproj file with me?

@AndreiMisiukevich AndreiMisiukevich added question Further information is requested reloader labels Aug 19, 2019
@AndreiMisiukevich AndreiMisiukevich self-assigned this Aug 19, 2019
@AndreiMisiukevich
Copy link
Owner

Well, it looks like:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>pdbonly</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="4.1.0.555618" />
    <PackageReference Include="Xamarin.HotReload" Version="1.4.19" />
  </ItemGroup>

</Project>

You need to put HotReload to Debug ItemGroup section (create new one) like:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>pdbonly</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="4.1.0.555618" />
  </ItemGroup>

  <ItemGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <PackageReference Include="Xamarin.HotReload" Version="1.4.19" />
  </ItemGroup>

</Project>

@AndreiMisiukevich
Copy link
Owner

Does it help?)

@LuoyeAn
Copy link
Author

LuoyeAn commented Aug 20, 2019

I thought it should work. But unfortunately, it did not disable the HotReload. I still saw Xamarin.Forms.HotReload.Reloader.dll ,Microsoft.CodeAnalysis.CSharp.dll and Microsoft.CodeAnalysis.dll in assemblies folder.

I just added Xamarin.HotReload nuget to my portable project and did the changes.

<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
  <PackageReference Include="Xamarin.HotReload" Version="1.4.19" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Pro_Debug|AnyCPU'">
  <PackageReference Include="Xamarin.HotReload" Version="1.4.19" />
</ItemGroup>
<ItemGroup>
  <PackageReference Include="Acr.UserDialogs" Version="7.0.4" />
  <PackageReference Include="CarouselView.FormsPlugin" Version="5.2.0" />
  <PackageReference Include="dotMorten.Xamarin.Forms.AutoSuggestBox" Version="0.7.0" />
  <PackageReference Include="Flurl.Http" Version="2.4.2" />
<ItemGroup>

After that, I built a new apk by Visual Studio App Center and the apk still contains Xamarin.HotReload.

Any idea? @AndreiMisiukevich

@AndreiMisiukevich
Copy link
Owner

@TingtingAn try to remove bin/obj and remove HotReload from platform projects (leave it only in portable), then try to build again

@LuoyeAn
Copy link
Author

LuoyeAn commented Aug 21, 2019

@AndreiMisiukevich Yea, I just kept Xamarin.HotReload in portable project and removed the bin/obj folders. Still not work.

I created a demo project. Could you try to build the apk?

@AndreiMisiukevich
Copy link
Owner

@TingtingAn sure, it will take a look
thanks

@AndreiMisiukevich
Copy link
Owner

@TingtingAn , try ItemGroup Condition="'$(Configuration)' != 'Release'"

Full:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>pdbonly</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <ItemGroup Condition="'$(Configuration)' != 'Release'"> 
    <PackageReference Include="Xamarin.HotReload" Version="1.4.15" />
  </ItemGroup> 

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="4.1.0.555618" />
    <PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
  </ItemGroup>
</Project>

@AndreiMisiukevich
Copy link
Owner

Hm, have you got any ideas how to work around it?

@AndreiMisiukevich AndreiMisiukevich added the help wanted Extra attention is needed label Aug 22, 2019
@AndreiMisiukevich
Copy link
Owner

Then try it.

And remember.

  1. You change build target (e.g. from Debug to Release)
  2. You must force to restore packages by right click on solution -> Restore packages
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>pdbonly</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <Choose>
    <When Condition="'$(Configuration)' == 'Debug'">
      <ItemGroup> 
        <PackageReference Include="Xamarin.HotReload" Version="1.4.15" />
      </ItemGroup> 
    </When>
  </Choose>

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="4.1.0.555618" />
    <PackageReference Include="Xamarin.Essentials" Version="1.1.0" />
  </ItemGroup>
</Project>

@LuoyeAn
Copy link
Author

LuoyeAn commented Aug 23, 2019

@AndreiMisiukevich It does not work. And I got the info here.

https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#adding-a-packagereference-condition

You can use a condition to control whether a package is included, where conditions can use any MSBuild variable or a variable defined in the targets or props file. However, at presently, only the TargetFramework variable is supported.

@AndreiMisiukevich
Copy link
Owner

@TingtingAn agrh.. So, it's problem.

Okay, you for now you may comment this line in csproj and build the apk.. need to investigate

@simix-felipebaltazar
Copy link

simix-felipebaltazar commented Aug 23, 2019

linking assemblies doesn't solve this?

https://docs.microsoft.com/en-us/xamarin/android/deploy-test/linker

@rudyspano
Copy link

rudyspano commented Aug 24, 2019

   ...
    <PackageReference Include="Xamarin.Forms" Version="4.2.0.709249" />
  </ItemGroup>
  
  <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
	  <PackageReference Include="Xamarin.HotReload" Version="1.4.19" />
  </ItemGroup>

This solution seems to work on my side.
It is very important because of Microsoft.CodeAnalysis.* dependencies that adds 20Mo on our production apk (aot activated , 2 ABI).

@AndreiMisiukevich
Copy link
Owner

   ...
    <PackageReference Include="Xamarin.Forms" Version="4.2.0.709249" />
  </ItemGroup>
  
  <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
	  <PackageReference Include="Xamarin.HotReload" Version="1.4.19" />
  </ItemGroup>

This solution seems to work on my side.
It is very important because of Microsoft.CodeAnalysis.* dependencies that adds 20Mo on our production apk (aot activated , 2 ABI).

so you don't see useless DLLs in your apk?

@rudyspano
Copy link

rudyspano commented Aug 26, 2019

@AndreiMisiukevich Yes. No more libaot-Microsoft.CodeAnalysis.CSharp.dll.so.
@TingtingAn, is it ok on your side?

@LuoyeAn
Copy link
Author

LuoyeAn commented Aug 26, 2019

@rudyspano In fact, commenting HotReload PackageReference is my only soultion.

https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#adding-a-packagereference-condition

According to the Microsoft documentation, we know only the TargetFramework variable is supported for packagereference condition.

So I think your solution will not work. I've tried it before and it really doesn't work.
And I am using Visual Studio App Center to build the apk and SDK version is Xamarin.Android 6.4

What is your build environment? Could you try to build the apk by Visual Studio App Center?

@rudyspano
Copy link

rudyspano commented Aug 26, 2019

@TingtingAn It is working on Visual Studio for Mac "Archive For Publishing" feature (do not forget to manually delete obj and bin folders). And also in our on Premise CI Environment (Jenkins, MSBuild on Mac). In order to view the APK Package content, we use Android Studio.
The condition is set on ItemGroup and not on PackageReference as mentioned...

@LuoyeAn
Copy link
Author

LuoyeAn commented Aug 27, 2019

Yes, it is working for Archive feature on my local Visual Studio. So the issue is from Visual Studio App Center.
Let's close this.
Thanks very much! @rudyspano @AndreiMisiukevich

@LuoyeAn LuoyeAn closed this as completed Aug 27, 2019
@AndreiMisiukevich AndreiMisiukevich removed the help wanted Extra attention is needed label Aug 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested reloader
Projects
None yet
Development

No branches or pull requests

4 participants