Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Fix up library project java classes (do…
Browse files Browse the repository at this point in the history
…tnet#1718)

Fixes: dotnet#1711

Commit a50e00b removed one of the calls to the
`<ConvertResourcesCases/>` task.  This was responsible for the
library project layouts not being updated with the md5 generated java
class names.

However rather than adding the call back in we can expand the call in
the `_GenerateJavaStubs` target to include the library projects.
This makes more sense because that is the target in which we generate
the stubs in the first place.
  • Loading branch information
dellis1972 authored and jonpryor committed May 23, 2018
1 parent 6e8c117 commit bea6d21
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,51 @@ public void Check9PatchFilesAreProcessed ([Values(false, true)] bool explicitCru
public void CheckXmlResourcesFilesAreProcessed ([Values(false, true)] bool isRelease)
{
var projectPath = String.Format ("temp/CheckXmlResourcesFilesAreProcessed_{0}", isRelease);
var proj = new XamarinAndroidApplicationProject () { IsRelease = isRelease };

var lib = new XamarinAndroidLibraryProject () {
IsRelease = isRelease,
ProjectName = "Classlibrary1",
};
lib.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\layout\\custom_text.xml") {
TextContent = () => @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<LinearLayout xmlns:android=""http://schemas.android.com/apk/res/android""
android:orientation = ""vertical""
android:layout_width = ""fill_parent""
android:layout_height = ""fill_parent"">
<classlibrary1.CustomTextView
android:id = ""@+id/myText1""
android:layout_width = ""fill_parent""
android:layout_height = ""wrap_content""
android:text = ""namespace_lower"" />
<ClassLibrary1.CustomTextView
android:id = ""@+id/myText2""
android:layout_width = ""fill_parent""
android:layout_height = ""wrap_content""
android:text = ""namespace_proper"" />
</LinearLayout>"
});
lib.Sources.Add (new BuildItem.Source ("CustomTextView.cs") {
TextContent = () => @"using Android.Widget;
using Android.Content;
using Android.Util;
namespace ClassLibrary1
{
public class CustomTextView : TextView
{
public CustomTextView(Context context, IAttributeSet attributes) : base(context, attributes)
{
}
}
}"
});

var proj = new XamarinAndroidApplicationProject () {
IsRelease = isRelease,
OtherBuildItems = {
new BuildItem.ProjectReference (@"..\Classlibrary1\Classlibrary1.csproj", "Classlibrary1", lib.ProjectGuid) {
},
}
};

proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\drawable\\UPPER_image.png") {
BinaryContent = () => XamarinAndroidCommonProject.icon_binary_mdpi
Expand Down Expand Up @@ -383,12 +427,23 @@ protected override void OnClick()
proj.SetProperty ("TargetFrameworkVersion", "v5.0");
proj.SetProperty (proj.DebugProperties, "JavaMaximumHeapSize", "1G");
proj.SetProperty (proj.ReleaseProperties, "JavaMaximumHeapSize", "1G");
using (var b = CreateApkBuilder (Path.Combine (projectPath))) {
using (var libb = CreateDllBuilder (Path.Combine (projectPath, lib.ProjectName)))
using (var b = CreateApkBuilder (Path.Combine (projectPath, proj.ProjectName))) {
b.Verbosity = LoggerVerbosity.Diagnostic;
Assert.IsTrue (libb.Build (lib), "Library Build should have succeeded.");
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
var preferencesPath = Path.Combine (Root, projectPath, proj.IntermediateOutputPath, "res","xml","preferences.xml");
var customViewPath = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "lp", "0", "jl", "res", "layout", "custom_text.xml");
Assert.IsTrue (File.Exists (customViewPath), $"custom_text.xml should exist at {customViewPath}");
var doc = XDocument.Load (customViewPath);
Assert.IsNotNull (doc.Element ("LinearLayout"), "PreferenceScreen should be present in preferences.xml");
Assert.IsNull (doc.Element ("LinearLayout").Element ("Classlibrary1.CustomTextView"),
"Classlibrary1.CustomTextView should have been replaced with an $(MD5Hash).CustomTextView");
Assert.IsNull (doc.Element ("LinearLayout").Element ("classlibrary1.CustomTextView"),
"classlibrary1.CustomTextView should have been replaced with an $(MD5Hash).CustomTextView");

var preferencesPath = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "res","xml","preferences.xml");
Assert.IsTrue (File.Exists (preferencesPath), "Preferences.xml should have been renamed to preferences.xml");
var doc = XDocument.Load (preferencesPath);
doc = XDocument.Load (preferencesPath);
Assert.IsNotNull (doc.Element ("PreferenceScreen"), "PreferenceScreen should be present in preferences.xml");
Assert.IsNull (doc.Element ("PreferenceScreen").Element ("UnnamedProject.CustomPreference"),
"UnamedProject.CustomPreference should have been replaced with an $(MD5Hash).CustomPreference");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@ because xbuild doesn't support framework reference assemblies.
AcwMapFile="$(_AcwMapFile)">
</GenerateJavaStubs>
<ConvertResourcesCases
ResourceDirectories="$(MonoAndroidResDirIntermediate)"
ResourceDirectories="$(MonoAndroidResDirIntermediate);@(LibraryResourceDirectories)"
AcwMapFile="$(_AcwMapFile)" />
</Target>

Expand Down

0 comments on commit bea6d21

Please sign in to comment.