简体   繁体   中英

Visual Studio 2015 Xamarin freezing

I have an Android app on Visual Studio 2015 with Xamarin and it is freezing frequently.

The only scenario I can reproduce every time is right after deploy. VS freezes right after the app is deployed on emulator or device. The app works fine, but the VS stands frozen for several seconds. It also freezes in other scenarios too.

VS doesn't show the "not responding" message no matter what I do. It seems like it's doing some background work and it's not really frozen, but I can't figure out what the problem is.

I recreated my project from scratch and the problem started to happen again when I added my resources and installed some NuGet packages (appcompat v7 and firebase cloud messaging).

I'm guessing it's somehow related to VS not recognizing some attributes in some layout files, like

如图所示 .

1 - Any help on the freezing problem?

2 - What can I do to VS recognize those attributes?

3 - Can I configure the resources.cs to be regenerated only on build?

Update

Found this , but didn't worked for me!

Update 2

Ok, now I'm 100% sure the problem is with the generation of android resources. The aapt.exe is the villain of this history, but I still can't make it stop executing and freezing Visual Studio every time. Is there some setting to ignore xml errors on layout files or something like that?

I am the guy who created the bugzilla post you are referencing.

Are you sure you have the <AndroidResgenExtraArgs>--no-crunch </AndroidResgenExtraArgs> on the right place? It must be inside the configuration you are using, ie the .csproj must be like this if you are deploying in Debug | AnyCPU Debug | AnyCPU configuration:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<AndroidResgenExtraArgs>--no-crunch </AndroidResgenExtraArgs>

(also notice the trailing space after --no-crunch )

BTW I also have trouble with aapt.exe when installing Nugets and --no-crunch does not help with this. What helps is temporarily renaming aapt.exe to aapt2.exe - Visual Studio does not run the aapt process, because it can't find the exe file and Nuget installations are fast. But this would probably not work for build and deploy, I think it throws an error.

Well, after trying a lot of stuff I made a lucky guess and it worked.

I was looking to my csproj and noticed some weird things, like:

<ItemGroup>
    <AndroidResource Include="Resources\layout\onefile.axml" />
</ItemGroup>
<ItemGroup>
    <AndroidResource Include="Resources\layout\anotherfile.axml" />
</ItemGroup>
<ItemGroup>
    <AndroidResource Include="Resources\layout\onemorefile.axml">
        <SomeOtherAttributes />
    </AndroidResource>
</ItemGroup>

So I imagined that organizing the ItemGroups would worth a try and put all ItemGroups (class, layout, image, string, etc) together like:

<ItemGroup>
    <AndroidResource Include="Resources\layout\onefile.axml" />
    <AndroidResource Include="Resources\layout\anotherfile.axml" />
    <AndroidResource Include="Resources\layout\onemorefile.axml" />
</ItemGroup>

And it worked beyond what I expected. Not only fixed my freezing problems... it made VS faster than before of my freezing problems... REALLY faster!

I don't know if reorganizing the csproj file can cause any kind of problems, but I'll do the same with other projects and see what happen.

I did a quick research about csproj and ItemGroup and found nothing relevant... I believe it's kind a bug!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM