-
Notifications
You must be signed in to change notification settings - Fork 564
[Xamarin.Android.Build.Tasks] support Embedded DSOs #2579
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,49 @@ | ||
| # Installation of Native Libraries | ||
|
|
||
| An Android `.apk` file can contain native libraries for one or more | ||
| architectures. Historically, all native libraries for the target | ||
| device are extracted at `.apk` installation time. This would result | ||
| in *two* copies of native libraries on the target device: a set of | ||
| native libraries which are stored compressed within the `.apk`, and | ||
| a separate set of native libraries on the Android target filesystem. | ||
|
|
||
| Starting with Android v6.0 (API-23), Android added an ability for | ||
| native libraries to be stored *uncompressed* within the `.apk` along | ||
| with the ability to load those native libraries *from* the `.apk` | ||
| without requiring a separate filesystem copy of the native libraries. | ||
|
|
||
| Android Things *requires* this new mechanism; `.apk` files installed | ||
| on Android Things will no longer have *any* native libraries extracted. | ||
|
|
||
| As a result, the `.apk` will be *larger*, because the native | ||
| libraries are stored uncompressed within the `.apk`, but the | ||
| install size will be *smaller*, because there isn't a second "copy" | ||
| of the native libraries (one compressed in the `.apk`, one outside | ||
| of the `.apk`). | ||
|
|
||
| On Android versions older than Android v6.0, the native libraries | ||
| will continue to be extracted during `.apk` installation. | ||
|
|
||
| In order to indicate to Android v6.0 and later that native libraries | ||
| do not need to be extracted, the | ||
| [`//application/@android:extractNativeLibs`][extractNativeLibs] | ||
| attribute within `AndroidManifest.xml` must be set to `false.` | ||
|
|
||
| [extractNativeLibs]: https://developer.android.com/guide/topics/manifest/application-element#extractNativeLibs | ||
|
|
||
| ## OSS Implementation Details | ||
|
|
||
| When `AndroidManifest.xml` contains an XML attribute matching | ||
| `//application[@android:extractNativeLibs='false']`, the | ||
| Xamarin.Android build system will do the following: | ||
|
|
||
| 1. The `$(AndroidStoreUncompressedFileExtensions)` MSBuild property | ||
| will be automatically updated to contain the `.so` file | ||
| extension, causing native libraries to be stored uncompressed | ||
| within the `.apk`. | ||
|
|
||
| 2. The `__XA_DSO_IN_APK` environment variable will be set within the | ||
| created `.apk` file with the value of `1`, indicating to | ||
| the app that native libraries should be loaded from the `.apk` | ||
| itself instead of from the filesystem. | ||
|
|
This file contains hidden or 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
28 changes: 28 additions & 0 deletions
28
src/Xamarin.Android.Build.Tasks/Tasks/ReadJavaStubsCache.cs
This file contains hidden or 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,28 @@ | ||
| using Microsoft.Build.Framework; | ||
| using Microsoft.Build.Utilities; | ||
| using System.IO; | ||
| using System.Xml.Linq; | ||
|
|
||
| namespace Xamarin.Android.Tasks | ||
| { | ||
| public class ReadJavaStubsCache : Task | ||
| { | ||
| [Required] | ||
| public string CacheFile { get; set; } | ||
|
|
||
| [Output] | ||
| public bool EmbeddedDSOsEnabled { get; set; } | ||
|
|
||
| public override bool Execute () | ||
| { | ||
| if (File.Exists (CacheFile)) { | ||
| var doc = XDocument.Load (CacheFile); | ||
| string text = doc.Element ("Properties")?.Element (nameof (EmbeddedDSOsEnabled))?.Value; | ||
| if (bool.TryParse (text, out bool value)) | ||
| EmbeddedDSOsEnabled = value; | ||
| } | ||
|
|
||
| return !Log.HasLoggedErrors; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
1 change: 1 addition & 0 deletions
1
tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/Jars/.gitignore
This file contains hidden or 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 @@ | ||
| *.jar |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,4 +2,3 @@ debug.mono.debug=1 | |
| MONO_LOG_LEVEL=debug | ||
| MONO_LOG_MASK=asm | ||
| MONO_XDEBUG=1 | ||
| __XA_DSO_IN_APK=1 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.