Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Preserve @(AndroidEnvironment) (#729)
Browse files Browse the repository at this point in the history
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=58673

The `@(AndroidEnvironment)` Build action is *supposed to be* usable on
Library projects. When used within a Library project, the
`@(AndroidEnvironment)` files are embedded into the assembly, and
during the App project build they are extracted and merged into the
`environment` file within the `.apk`.

Unfortunately, this behavior was potentially broken in commit
8688832, as if the Library assembly also contains the
`__AndroidLibraryProjects__.zip` embedded resource (e.g. the Library
project has a `@(AndroidResource)` Build action), the extraction of
the `__AndroidLibraryProjects__.zip` resource will inadvertently
remove the previously extracted `@(AndroidEnvironment)` files.

Oops.

Alter the paths provided to `Files.ExtractAll()` -- which was
directly responsible for deleting the environment files -- so that it
won't delete the environment files.

Update the `tests/locales` on-device unit tests to make use of a
Library-provided `@(AndroidEnvironment)`, and add a unit test which
reads the environment variable and asserts that the environment
variable has the expected value.
  • Loading branch information
jonpryor authored Aug 10, 2017
1 parent 028c51d commit ea6b9b4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ void Extract (
// temporarily extracted directory will look like:
// __library_projects__/[dllname]/[library_project_imports | jlibs]/bin
using (var zip = MonoAndroidHelper.ReadZipFile (finfo.FullName)) {
updated |= Files.ExtractAll (zip, outDirForDll, modifyCallback: (entryFullName) => {
return entryFullName.Replace ("library_project_imports", ImportsDirectory);
updated |= Files.ExtractAll (zip, importsDir, modifyCallback: (entryFullName) => {
return entryFullName.Replace ("library_project_imports/", "");
}, forceUpdate: false);
}

Expand Down
1 change: 1 addition & 0 deletions tests/locales/LibraryResources/Environment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
THIS_IS_MY_ENVIRONMENT=Well, hello there!
3 changes: 3 additions & 0 deletions tests/locales/LibraryResources/LibraryResources.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<ItemGroup>
<AndroidResource Include="Resources\values\Strings.xml" />
</ItemGroup>
<ItemGroup>
<AndroidEnvironment Include="Environment.txt" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<ItemGroup>
<EmbeddedResource Include="strings.de-DE.resx" />
Expand Down
19 changes: 19 additions & 0 deletions tests/locales/Xamarin.Android.Locale-Tests/EnvironmentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Reflection;

using NUnit.Framework;

namespace Xamarin.Android.LocaleTests
{
[TestFixture]
public class EnvironmentTests
{
[Test (Description="https://bugzilla.xamarin.com/show_bug.cgi?id=58673")]
public void EnvironmentVariablesFromLibraryProjectsAreMerged ()
{
var v = Environment.GetEnvironmentVariable ("THIS_IS_MY_ENVIRONMENT");
Assert.AreEqual (v, "Well, hello there!");
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Reference Include="Xamarin.Android.NUnitLite" />
</ItemGroup>
<ItemGroup>
<Compile Include="EnvironmentTests.cs" />
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

0 comments on commit ea6b9b4

Please sign in to comment.