-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] extractNativeLibs="true" by default (#5021
) Fixes: #4986 The [`//application/@android:extractNativeLibs`][0] attribute within `AndroidManifest.xml` has had a large-scale impact on `.apk`s: When `extractNativeLibs` is `true`, then (1) native libraries within the `.apk` are *compressed*, and (2) the native libraries within the `.apk` are extracted during installation time. This allows the `.apk` to be smaller, while resulting in a *larger* installation footprint, as two copies of the native libs -- one compressed, one uncompressed -- are present on the device. When `extractNativeLibs` is `false`, then (1) native libraries within the `.apk` are stored *uncompressed*, and (2) the native libraries within the `.apk` are *not* extracted during installation time, but *only* on API-23 and later devices. This makes for a larger `.apk`, but a *smaller* installation footprint. When *omitted* this value defaults to `true`. Commit 86737ca bumped `manifest-merger` from 26.5.0 to 27.0.0, which [altered `manifest-merger.jar` behavior][1] so that it started setting `//application/@android:extractNativeLibs`=false when `minSdkVersion` is 23 or higher, "as if" `Properties\AndroidManifest.xml` contained: <application android:extractNativeLibs="false"> In the case of Issue #4986, which is an application which uses Xamarin.Forms and sets `$(AotAssemblies)`=True, resulting in native libraries being produced and included for *every assembly*, this "minor" change to `extractNativeLibs` caused a 24MB `.apk` to balloon in size to 64MB, which was unexpected. This unexpected size increase was not caught by unit tests, as our tests which check for `.apk` size regressions don't use Xamarin.Forms, and it's AndroidX/Android Support -- used by Xamarin.Forms -- which causes `manifest-merger.jar` to be used. No `manifest-merger.jar`, no unexpected size increase. This `manifest-merger.jar` change is *also* the underlying cause of bf657e8 and 8828fef. To solve this, if not explicitly specified within apps' `Properties\AndroidManifest.xml`, we will now insert `android:extractNativeLibs="true"` by default. This way Xamarin.Android applications will have consistent behavior. Developers can set `extractNativeLibs="false"` if they prefer that behavior. This behavior also works fine on an API-19 emulator, since `extractNativeLibs="true"` is already the default and seems to be ignored. [0]: https://developer.android.com/guide/topics/manifest/application-element#extractNativeLibs [1]: https://android.googlesource.com/platform/tools/base/+/fd2ac00ab76dfdececce5a25cb7ad23b2b6f5d29%5E%21
- Loading branch information
1 parent
f5340fe
commit 416b489
Showing
5 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#### Application and library build and deployment | ||
|
||
* [GitHub Issue 4986](https://github.com/xamarin/xamarin-android/issues/4986): | ||
Updates to Android tooling (`manifest-merger`), caused | ||
`//application/@android:extractNativeLibs` to be set to `false` by | ||
default. This can cause an undesirable `.apk` file size increase | ||
that is more noticeable for Xamarin.Android applications using AOT. | ||
Xamarin.Android now sets `extractNativeLibs` to `true` by default. | ||
|
||
According to the [Android documentation][extractNativeLibs], | ||
`extractNativeLibs` affects `.apk` size and install size: | ||
|
||
> Whether or not the package installer extracts native libraries from | ||
> the APK to the filesystem. If set to false, then your native | ||
> libraries must be page aligned and stored uncompressed in the APK. | ||
> No code changes are required as the linker loads the libraries | ||
> directly from the APK at runtime. The default value is "true". | ||
This is a tradeoff that each developer should decide upon on a | ||
per-application basis. Is a smaller install size at the cost of a | ||
larger download size preferred? | ||
|
||
Since Xamarin.Android now emits `android:extractNativeLibs="true"` by | ||
default, you can get the opposite behavior with an | ||
`AndroidManifest.xml` such as: | ||
|
||
```xml | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.hello"> | ||
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="30" /> | ||
<application android:label="Hello" android:extractNativeLibs="false" /> | ||
</manifest> | ||
``` | ||
|
||
[extractNativeLibs]: https://developer.android.com/guide/topics/manifest/application-element |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters