Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] allow two different r-classes.jar files
Browse files Browse the repository at this point in the history
Fixes: #5627

WIP as I am getting this error from d8:

    Unsupported class file major version 59
  • Loading branch information
jonathanpeppers committed Mar 1, 2021
1 parent dcd1cb7 commit 55c29ed
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace Xamarin.Android.Tasks
{
public class CheckDuplicateJavaLibraries : AndroidTask
{
readonly static string [] ExcludedFiles = new [] {
"classes.jar",
"r-classes.jar"
};

public override string TaskPrefix => "CDJ";

public ITaskItem [] JavaSourceFiles { get; set; }
Expand All @@ -26,7 +31,7 @@ public override bool RunTask ()

// Remove duplicate identical jars by name, size and content, and reject any jars that conflicts by name (i.e. different content).
var jars = MonoAndroidHelper.DistinctFilesByContent (jarFilePaths).ToArray ();
var dups = MonoAndroidHelper.GetDuplicateFileNames (jars, new string [] {"classes.jar"});
var dups = MonoAndroidHelper.GetDuplicateFileNames (jars, ExcludedFiles);
if (dups.Any ()) {
Log.LogCodedError ("XA1014", Properties.Resources.XA1014, String.Join (", ", dups.ToArray ()));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,5 +650,45 @@ public void LibraryProjectZipWithLint ()
"`lint.jar` should not be extracted!");
}
}

/// <summary>
/// Tests two .aar files with r-classes.jar
/// </summary>
[Test]
public void AarWithRClassesJar ()
{
var path = Path.Combine ("temp", TestName);
var lib1 = new XamarinAndroidBindingProject {
ProjectName = "Library1",
AndroidClassParser = "class-parse",
Jars = {
new AndroidItem.LibraryProjectZip ("Library1.aar") {
BinaryContent = () => ResourceData.Library1Aar
}
},
};
var lib2 = new XamarinAndroidBindingProject {
ProjectName = "Library2",
AndroidClassParser = "class-parse",
Jars = {
new AndroidItem.LibraryProjectZip ("Library2.aar") {
BinaryContent = () => ResourceData.Library2Aar
}
},
};
var app = new XamarinAndroidApplicationProject {
//TODO: The .aar files in this test are Java 14: `Unsupported class file major version 59`
DexTool = "dx",
};
app.AddReference (lib1);
app.AddReference (lib2);
using (var lib1Builder = CreateDllBuilder (Path.Combine (path, lib1.ProjectName)))
using (var lib2Builder = CreateDllBuilder (Path.Combine (path, lib2.ProjectName)))
using (var appBuilder = CreateApkBuilder (Path.Combine (path, app.ProjectName))) {
Assert.IsTrue (lib1Builder.Build (lib1), "Library1 build should have succeeded.");
Assert.IsTrue (lib2Builder.Build (lib2), "Library2 build should have succeeded.");
Assert.IsTrue (appBuilder.Build (app), "App build should have succeeded.");
}
}
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ static class ResourceData
static Lazy<byte[]> javaSourceJarTestJar = new Lazy<byte[]>(() => GetResourceData ("javasourcejartest.jar"));
static Lazy<byte[]> javaSourceJarTestSourcesJar = new Lazy<byte[]>(() => GetResourceData ("javasourcejartest-sources.jar"));
static Lazy<byte[]> javaSourceJarTestJavadocJar = new Lazy<byte[]>(() => GetResourceData ("javasourcejartest-javadoc.jar"));
static Lazy<byte []> library1Aar = new Lazy<byte []> (() => GetResourceData ("library1.aar"));
static Lazy<byte []> library2Aar = new Lazy<byte []> (() => GetResourceData ("library2.aar"));

public static byte[] JavaSourceJarTestJar => javaSourceJarTestJar.Value;
public static byte[] JavaSourceJarTestSourcesJar => javaSourceJarTestSourcesJar.Value;
public static byte[] JavaSourceJarTestJavadocJar => javaSourceJarTestJavadocJar.Value;
public static byte [] Library1Aar => library1Aar.Value;
public static byte [] Library2Aar => library2Aar.Value;

static byte[] GetResourceData (string name)
{
using var s = typeof (InlineData).Assembly.GetManifestResourceStream (name);
using var s = typeof (ResourceData).Assembly.GetManifestResourceStream (name);
using var m = new MemoryStream (checked ((int) s.Length));
s.CopyTo (m);
return m.ToArray ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,8 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\javasourcejartest.jar">
<LogicalName>javasourcejartest.jar</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Resources\javasourcejartest-sources.jar">
<LogicalName>javasourcejartest-sources.jar</LogicalName>
</EmbeddedResource>
<EmbeddedResource Include="Resources\javasourcejartest-javadoc.jar">
<LogicalName>javasourcejartest-javadoc.jar</LogicalName>
<EmbeddedResource Include="Resources\*">
<LogicalName>%(FileName)%(Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>

Expand Down

0 comments on commit 55c29ed

Please sign in to comment.