четвер, 9 липня 2020 р.

Optimize, AndroidLinkMode, big project and fast deployment

1. Set Optimize = false for Debug
otherwise I have
run-as: package not debuggable

If you have a large project and [INSTALL_FAILED_CONTAINER_ERROR]

2. Copy assemblies (dlls) to .__override__ if you need AndroidLinkMode = SdkOnly.
3. Alternatively to SdkOnly we may set AndroidUseAapt2 = true



I have a project where

DebugSymbols = true
DebugType = full
Optimize = false
AndroidLinkMode = None

and it doesn't work - I have Failure [INSTALL_FAILED_CONTAINER_ERROR] on Android 4.4 (and on an Android R emulator).

On the other hand the "Release" installs normally...
but to use the "fast deployment" I need "Debug"... Here is a solution:

In this case the project is large - its size approximately 100Mb. Probably something wrong with it, maybe with dex. I can't say does it create the multi-dex by default and I can't try the multi-dex at the moment because I can't find how to set those options at the moment.

I can make it smaller using AndroidLinkMode. But the fast deployment doesn't work, app. crashes, when Optimize = false and AndroidLinkMode = SdkOnly
(and Optimize = true disables .__override__ folder)

To fix the app. crash I need to push some assemblies (dlls) to the .__override__ folder.

For a small modern project - netstandard.dll (from xamarin folder) works.

~/Android/Sdk/platform-tools$ ./adb push /usr/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v1.0/Facades/netstandard.dll /data/local/tmp

./adb shell run-as com.companyname.app5 cp /data/local/tmp/netstandard.dll /data/data/com.companyname.app5/files/.__override__


But for old PCL project - I need to copy a lot of dlls from the "Facades" folder.

adb logcat shows a lot of errors; we need to fetch all errors one by one running our app. many times...

The following assembly referenced from /data/user/0/com.myapplication/files/.__override__/MyApp.dll could not be loaded:
     Assembly:   System.Diagnostics.Debug    (assemblyref_index=6)
     Version:    4.0.0.0
     Public Key: b03f5f7f11d50a3a
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable,
or in the location of the executing assembly (/data/user/0/com.myapplication/files/.__override__/).
Failed to load assembly MyApp...

System.Globalization.dll
System.Threading.Tasks.dll
System.Runtime.dll
System.ObjectModel.dll
System.Collections.dll
System.Runtime.Extensions.dll
System.Reflection.dll
System.Resources.ResourceManager.dll
System.Threading.dll
System.ComponentModel.dll
System.Xml.ReaderWriter.dll
System.Linq.Expressions.dll
System.Linq.dll
System.Diagnostics.Debug.dll

Could not load signature of ... due to: Could not load file or assembly 'System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.

System.ValueTuple.dll

Thank God! ... now the fast deployments works for me (in emulator, Android R; at least).

P.S. I've also have found that setting AndroidUseAapt2 = true helps to make the large projects "smaller". So I can use AndroidLinkMode = None


One of my newest projects (03.2020) have these settings in PropertyGroup:

<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>

Немає коментарів:

Дописати коментар