Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Add directBootAware if needed.
Browse files Browse the repository at this point in the history
Fixes dotnet#2081

If a user needs to use the `directBootAware` attribute on
an `application`, `activity` or `service` we also need
to include it on the `MonoRuntimeProvider` so that
native libraries can be resolved correctly. Not doing
so results in the following

	java.lang.UnsatisfiedLinkError: No implementation found for void mono.android.Runtime.register

This commit looks to see if any elements in the manifest
contain `directBootAware`. If there are , then we also
include it in the `provider`.
  • Loading branch information
dellis1972 committed Jan 15, 2019
1 parent f4f3990 commit 3ea7ed2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ public void DirectBootAwareAttribute ()
Assert.IsNotNull (le, "no activity element found");
Assert.IsTrue (doc.XPathSelectElements ("//activity[@android:directBootAware='true']", nsResolver).Any (),
"'activity' element is not generated as expected.");
Assert.IsTrue (doc.XPathSelectElements ("//provider[@android:name='mono.MonoRuntimeProvider' and @android:directBootAware='true']", nsResolver).Any (),
"'provider' element is not generated as expected.");
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ XElement CreateMonoRuntimeProvider (string name, string processName, int initOrd
new XAttribute (androidNs + "name", name),
new XAttribute (androidNs + "exported", "false"),
new XAttribute (androidNs + "initOrder", initOrder),
new XAttribute (androidNs + "directBootAware", DirectBootAware () ? "true" : "false"),
processName == null ? null : new XAttribute (androidNs + "process", processName),
new XAttribute (androidNs + "authorities", PackageName + "." + name + ".__mono_init__"));
}
Expand All @@ -658,6 +659,22 @@ public bool ExtractNativeLibraries ()
return true;
}

/// <summary>
/// Returns the value of //application/@android:directBootAware.
/// </summary>
public bool DirectBootAware ()
{
var processAttrName = androidNs.GetName ("directBootAware");
foreach (XElement el in app.Elements ()) {
var proc = el.Attribute (processAttrName);
if (proc != null)
return true;
}

// If android:directBootAware is omitted, returns false.
return false;
}

XElement ActivityFromTypeDefinition (TypeDefinition type, string name, int targetSdkVersion)
{
if (name.StartsWith ("_"))
Expand Down

0 comments on commit 3ea7ed2

Please sign in to comment.