Skip to content

Commit bc63326

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] @(LibraryResourceDirectories)+R.java (#744)
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=58721 The initial problem seems to stem from the fact that for the support library components now directly include the resources. As a result the `_GenerateJavaResourcesForComponent` target was not running. This was because it was only running if `$(_AdditonalAndroidResourceCachePaths)` was not empty. In this scenario it was always empty. As a result none of the files like `R.java` files were generated for the support libraries. The means the final `.class` files did not have references for the `R$drawable.foo` identifiers. This results in a crash: Java.Lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/appcompat/R$drawable; Fix the problem by looking at `@(LibraryResourceDirectories)` to see if we have any `AndroidManifest.xml` files. We should then process these directories to ensure that the `R.java` files are created and included compiled into the final applications.
1 parent e1c0436 commit bc63326

File tree

3 files changed

+89
-4
lines changed

3 files changed

+89
-4
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using Xamarin.ProjectTools;
33
using NUnit.Framework;
44
using System.Linq;
@@ -110,6 +110,29 @@ public void DesignTimeBuild ([Values(false, true)] bool isRelease)
110110
}
111111
}
112112

113+
[Test]
114+
public void CheckEmbeddedSupportLibraryResources ()
115+
{
116+
var proj = new XamarinAndroidApplicationProject () {
117+
IsRelease = true,
118+
Packages = {
119+
KnownPackages.SupportMediaCompat_25_4_0_1,
120+
KnownPackages.SupportFragment_25_4_0_1,
121+
KnownPackages.SupportCoreUtils_25_4_0_1,
122+
KnownPackages.SupportCoreUI_25_4_0_1,
123+
KnownPackages.SupportCompat_25_4_0_1,
124+
KnownPackages.AndroidSupportV4_25_4_0_1,
125+
KnownPackages.SupportV7AppCompat_25_4_0_1,
126+
},
127+
TargetFrameworkVersion = "v7.1",
128+
};
129+
using (var b = CreateApkBuilder ("temp/CheckEmbeddedSupportLibraryResources")) {
130+
Assert.IsTrue (b.Build (proj), "First build should have succeeded.");
131+
var Rdrawable = b.Output.GetIntermediaryPath (Path.Combine ("android", "bin", "classes", "android", "support", "v7", "appcompat", "R$drawable.class"));
132+
Assert.IsTrue (File.Exists (Rdrawable), $"{Rdrawable} should exist");
133+
}
134+
}
135+
113136
[Test]
114137
public void MoveResource ()
115138
{

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownPackages.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ public static class KnownPackages
4040
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v4.23.1.1.0\\lib\\MonoAndroid403\\Xamarin.Android.Support.v4.dll" }
4141
}
4242
};
43+
public static Package AndroidSupportV4_25_4_0_1 = new Package () {
44+
Id = "Xamarin.Android.Support.v4",
45+
Version = "25.4.0.1",
46+
TargetFramework = "MonoAndroid70",
47+
References = {
48+
new BuildItem.Reference ("Xamarin.Android.Support.v4") {
49+
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v4.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.v4.dll" }
50+
}
51+
};
4352
public static Package AndroidSupportV4Beta = new Package () {
4453
Id = "Xamarin.Android.Support.v4",
4554
Version = "21.0.0.0-beta1",
@@ -139,6 +148,60 @@ public static class KnownPackages
139148
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.AppCompat.23.1.1.0\\lib\\MonoAndroid403\\Xamarin.Android.Support.v7.AppCompat.dll" }
140149
}
141150
};
151+
public static Package SupportV7AppCompat_25_4_0_1 = new Package {
152+
Id = "Xamarin.Android.Support.v7.AppCompat",
153+
Version = "25.4.0.1",
154+
TargetFramework = "MonoAndroid70",
155+
References = {
156+
new BuildItem.Reference ("Xamarin.Android.Support.v7.AppCompat") {
157+
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.AppCompat.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.v7.AppCompat.dll" }
158+
}
159+
};
160+
public static Package SupportCompat_25_4_0_1 = new Package {
161+
Id = "Xamarin.Android.Support.Compat",
162+
Version = "25.4.0.1",
163+
TargetFramework = "MonoAndroid70",
164+
References = {
165+
new BuildItem.Reference ("Xamarin.Android.Support.Compat") {
166+
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Compat.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.Compat.dll" }
167+
}
168+
};
169+
public static Package SupportCoreUI_25_4_0_1 = new Package {
170+
Id = "Xamarin.Android.Support.Core.UI",
171+
Version = "25.4.0.1",
172+
TargetFramework = "MonoAndroid70",
173+
References = {
174+
new BuildItem.Reference ("Xamarin.Android.Support.Core.UI") {
175+
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Core.UI.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.Core.UI.dll" }
176+
}
177+
};
178+
public static Package SupportCoreUtils_25_4_0_1 = new Package {
179+
Id = "Xamarin.Android.Support.Core.Utils",
180+
Version = "25.4.0.1",
181+
TargetFramework = "MonoAndroid70",
182+
References = {
183+
new BuildItem.Reference ("Xamarin.Android.Support.Core.Utils") {
184+
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Core.Utils.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.Core.Utils.dll" }
185+
}
186+
};
187+
public static Package SupportFragment_25_4_0_1 = new Package {
188+
Id = "Xamarin.Android.Support.Fragment",
189+
Version = "25.4.0.1",
190+
TargetFramework = "MonoAndroid70",
191+
References = {
192+
new BuildItem.Reference ("Xamarin.Android.Support.Fragment") {
193+
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Fragment.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.Fragment.dll" }
194+
}
195+
};
196+
public static Package SupportMediaCompat_25_4_0_1 = new Package {
197+
Id = "Xamarin.Android.Support.Media.Compat",
198+
Version = "25.4.0.1",
199+
TargetFramework = "MonoAndroid70",
200+
References = {
201+
new BuildItem.Reference ("Xamarin.Android.Support.Media.Compat") {
202+
MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Media.Compat.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.Media.Compat.dll" }
203+
}
204+
};
142205
public static Package SupportV7MediaRouter_21_0_3_0 = new Package {
143206
Id = "Xamarin.Android.Support.v7.MediaRouter",
144207
Version = "21.0.3.0",

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,8 +1211,7 @@ because xbuild doesn't support framework reference assemblies.
12111211
</PropertyGroup>
12121212

12131213
<Target Name="_GenerateJavaDesignerForComponent"
1214-
Condition="'@(_AdditonalAndroidResourceCachePaths)' != ''"
1215-
Inputs="@(_AdditonalAndroidResourceCacheFiles)"
1214+
Inputs="@(_AdditonalAndroidResourceCacheFiles);@(_LibraryResourceDirectoryStamps)"
12161215
Outputs="$(_AndroidComponentResgenFlagFile)"
12171216
DependsOnTargets="$(_GenerateJavaDesignerForComponentDependsOnTargets)">
12181217

@@ -1221,7 +1220,7 @@ because xbuild doesn't support framework reference assemblies.
12211220
ImportsDirectory="$(_LibraryProjectImportsDirectoryName)"
12221221
OutputImportDirectory="$(_AndroidLibrayProjectIntermediatePath)"
12231222
UseShortFileNames="$(UseShortFileNames)"
1224-
ManifestFiles="@(_AdditonalAndroidResourceCachePaths->'%(Identity)\AndroidManifest.xml')"
1223+
ManifestFiles="@(_AdditonalAndroidResourceCachePaths->'%(Identity)\AndroidManifest.xml');@(LibraryResourceDirectories->'%(Identity)\..\AndroidManifest.xml')"
12251224
ApplicationName="$(_AndroidPackage)"
12261225
JavaPlatformJarPath="$(JavaPlatformJarPath)"
12271226
NonConstantId="true"

0 commit comments

Comments
 (0)