Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release builds fail if imported AAR library contains a lint.jar file #4565

Closed
davidschreiber opened this issue Apr 16, 2020 · 10 comments · Fixed by #4982
Closed

Release builds fail if imported AAR library contains a lint.jar file #4565

davidschreiber opened this issue Apr 16, 2020 · 10 comments · Fixed by #4982
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@davidschreiber
Copy link

davidschreiber commented Apr 16, 2020

When building a Xamarin-Android app using an AAR library that contains a lint.jar file, release builds fail due to Xamarin-Android trying to process the lint.jar file using R8.

Steps to Reproduce

  1. Use a AAR library binding, where the original AAR file contains a lint.jar file. The possibility of having a lint.jar is described here: https://developer.android.com/studio/projects/android-library#aar-contents
  2. Perform a release build, so that the R8 task is executed.
  3. Observe error messages like this:
1>  AndroidSample -> ...\bin\Release\AndroidSample.dll
1>R8 : warning : Missing class: org.conscrypt.ConscryptHostnameVerifier
1>R8 : warning : Missing class: com.android.tools.lint.detector.api.Detector
1>R8 : warning : Missing class: com.android.tools.lint.detector.api.Detector$UastScanner
1>R8 : warning : Missing class: com.android.tools.lint.client.api.UElementHandler
1>R8 : warning : Missing class: com.android.tools.lint.detector.api.Detector$XmlScanner
1>R8 : warning : Missing class: com.android.tools.lint.client.api.IssueRegistry
1>R8 : error : Compilation can't be completed because some library classes are missing.

Expected Behavior

The release build should succeed without errors. The lint.jar file should be excluded from R8, as well as from any other build steps, as it is not meant to be included inside the app (it is only used by the IDE to provide linter warnings).

Actual Behavior

R8 fails to minify the project's classes, because it picks up the lint.jar file and tries to minimize it too.

I assume that this is the case, because all JAR files inside the AAR are used as library class files, and the lint.jar file is not properly filtered, for example here:

https://github.com/xamarin/xamarin-android/blob/7249199988f42dd2f8da1035cb2e7a334f0ad28a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs#L354-L358

Instead, the lint.jar file is only important for the IDE, and should not be included on the compile classpath or runtime classpath of the app.

Version Information

Microsoft Visual Studio Community 2019
Version 16.4.5
VisualStudio.16.Release/16.4.5+29806.167
Microsoft .NET Framework
Version 4.8.03752

Installed Version: Community

Visual C++ 2019 00435-60000-00000-AA767
Microsoft Visual C++ 2019

Microsoft Visual Studio VC Package 1.0
Mono Debugging for Visual Studio 16.5.24 (1fafd7e)
NuGet Package Manager 5.4.0

Xamarin 16.4.000.311 (d16-4@ddfd842)

Xamarin.Android SDK 10.1.4.0 (d16-4/e44d1ae)
Mono: fd9f379
Java.Interop: xamarin/java.interop/d16-4@c4e569f
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@46204c4
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-5@9f4ed4b

@davidschreiber davidschreiber added the Area: App+Library Build Issues when building Library projects or Application projects. label Apr 16, 2020
@grendello
Copy link
Contributor

Hi, this issue was fixed in #4385, the fix will be part of the next 16.6 preview/release.

@davidschreiber
Copy link
Author

Thanks for confirming!

@brendanzagaeski

This comment has been minimized.

@brendanzagaeski

This comment has been minimized.

@hadigityat
Copy link

hadigityat commented Jul 29, 2020

@brendanzagaeski I'm seeing this issue in Xamarin.Android 10.3.1.4 VS 2019 Version 8.6.8 (build 2)

R8: Warning: Missing class: org.conscrypt.ConscryptHostnameVerifier
R8: Warning: Missing class: com.android.tools.lint.detector.api.Detector
R8: Warning: Missing class: com.android.tools.lint.client.api.IssueRegistry

@brendanzagaeski
Copy link
Contributor

@hadigityat, thanks for testing this! I can confirm that this behavior is indeed not fixed for the case where a bindings projects uses the LibraryProjectZip build action to embed a .aar file within the output bindings library project managed assembly.

The fix from #4385 only works when the .aar file is instead packaged alongside the managed assembly as a separate file in a NuGet package archive. Since that is not currently the default workflow for Xamarin.Android bindings projects, I am reopening this issue.

Steps to reproduce

Add the following test to src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs and run it:

[Test]
public void LibraryProjectZipWithLint ()
{
	var path = Path.Combine ("temp", TestName);
	var lib = new XamarinAndroidBindingProject () {
		ProjectName = "BindingsProject",
		AndroidClassParser = "class-parse",
		Jars = {
			new AndroidItem.LibraryProjectZip ("fragment-1.2.2.aar") {
				WebContent = "https://maven.google.com/androidx/fragment/fragment/1.2.2/fragment-1.2.2.aar"
			}
		},
		MetadataXml = @"<metadata><remove-node path=""/api/package[@name='androidx.fragment.app']/interface[@name='FragmentManager.OpGenerator']"" /></metadata>"
	};
	var app = new XamarinAndroidApplicationProject () {
		ProjectName = "App",
		IsRelease = true,
		LinkTool = "r8",
		References = { new BuildItem.ProjectReference ($"..\\{lib.ProjectName}\\{lib.ProjectName}.csproj", lib.ProjectName, lib.ProjectGuid) }
	};
	using (var libBuilder = CreateDllBuilder (Path.Combine (path, lib.ProjectName), cleanupAfterSuccessfulBuild: false))
	using (var appBuilder = CreateApkBuilder (Path.Combine (path, app.ProjectName))) {
		Assert.IsTrue (libBuilder.Build (lib), "Library build should have succeeded.");
		appBuilder.ThrowOnBuildFailure = false;
		appBuilder.Build (app);
		StringAssertEx.DoesNotContain ("warning : Missing class: com.android.tools.lint.detector.api.Detector", appBuilder.LastBuildOutput, "Build output should contain no warnings about com.android.tools.lint.detector.api.Detector");
		var libraryProjects = Path.Combine (Root, appBuilder.ProjectDirectory, app.IntermediateOutputPath, "lp");
		Assert.IsFalse (Directory.EnumerateFiles (libraryProjects, "lint.jar", SearchOption.AllDirectories).Any (),
			"`lint.jar` should not be extracted!");
	}
}

Expected behavior

The test should pass.

Actual behavior

The StringAssertEx.DoesNotContain() assertion fails. If that assertion is commented out, then the subsequent Assert.IsFalse() assertion fails. In other words, lint.jar is being extracted from the __AndroidLibraryProjects__.zip embedded resource in the bindings project managed assembly and being included in the Java build steps.

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Aug 5, 2020
Fixes: dotnet#4565
Context: dotnet#4565 (comment)

In f230b87, I fixed `lint.jar` from being included in apps from the
`@(AndroidAarLibrary)` item group. Unfortunately, this did not fix the
scenario for `@(LibraryProjectZip)` in binding projects!

I moved the `skipCallback` used in the
`<ResolveLibraryProjectImports/>` to a common place in the `Files`
class so it can also be used by the `<CreateLibraryResourceArchive/>`
MSBuild task.

I brought over Brendan's test that reproduces the bug as well.

Co-authored by: Brendan Zagaeski <brzaga@microsoft.com>
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Aug 6, 2020
Fixes: dotnet#4565
Context: dotnet#4565 (comment)

In f230b87, I fixed `lint.jar` from being included in apps from the
`@(AndroidAarLibrary)` item group. Unfortunately, this did not fix the
scenario for `@(LibraryProjectZip)` in binding projects!

I moved the `skipCallback` used in the
`<ResolveLibraryProjectImports/>` to a common place in the `Files`
class so it can also be used by the `<CreateLibraryResourceArchive/>`
MSBuild task. We need to use this for `.aar` files *only*, because
`.zip` files could be *any* format.

I brought over Brendan's test that reproduces the bug as well.

Co-authored by: Brendan Zagaeski <brzaga@microsoft.com>
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Aug 6, 2020
Fixes: dotnet#4565
Context: dotnet#4565 (comment)

In f230b87, I fixed `lint.jar` from being included in apps from the
`@(AndroidAarLibrary)` item group. Unfortunately, this did not fix the
scenario for `@(LibraryProjectZip)` in binding projects!

I moved the `skipCallback` used in the
`<ResolveLibraryProjectImports/>` to a common place in the `Files`
class so it can also be used by the `<CreateLibraryResourceArchive/>`
MSBuild task. We need to use this for `.aar` files *only*, because
`.zip` files could be *any* format.

I brought over Brendan's test that reproduces the bug as well.

Co-authored-by: Brendan Zagaeski <brzaga@microsoft.com>
jonathanpeppers added a commit that referenced this issue Aug 6, 2020
…p) (#4982)

Fixes: #4565
Context: #4565 (comment)

In f230b87, I fixed `lint.jar` from being included in apps from the
`@(AndroidAarLibrary)` item group. Unfortunately, this did not fix the
scenario for `@(LibraryProjectZip)` in binding projects!

I moved the `skipCallback` used in the
`<ResolveLibraryProjectImports/>` to a common place in the `Files`
class so it can also be used by the `<CreateLibraryResourceArchive/>`
MSBuild task. We need to use this for `.aar` files *only*, because
`.zip` files could be *any* format.

I brought over Brendan's test that reproduces the bug as well.

Co-authored-by: Brendan Zagaeski <brzaga@microsoft.com>
@hadigityat
Copy link

Thanks for fixing, can you also update this with a release status?As in which release will have the fix @brendanzagaeski

@brendanzagaeski
Copy link
Contributor

brendanzagaeski commented Aug 6, 2020

Thanks for the question!

So far, the new fix for this item is only present on the master development branch, so I will set the milestone to d16-9 for now to match the next xamarin-android development branch that will be created from master. By default, that branch will align with the Visual Studio 2019 version 16.9 and Visual Studio 2019 for Mac version 8.9 releases.

I'll watch to see if this fix is backported to another development branch, such as d16-8, and update the milestone again if it is.

The new Release status update comments will come later, when the fix is formally available in a published version of Visual Studio.

jonpryor pushed a commit that referenced this issue Aug 10, 2020
…p) (#4982)

Fixes: #4565
Context: #4565 (comment)

In f230b87, I fixed `lint.jar` from being included in apps from the
`@(AndroidAarLibrary)` item group. Unfortunately, this did not fix the
scenario for `@(LibraryProjectZip)` in binding projects!

I moved the `skipCallback` used in the
`<ResolveLibraryProjectImports/>` to a common place in the `Files`
class so it can also be used by the `<CreateLibraryResourceArchive/>`
MSBuild task. We need to use this for `.aar` files *only*, because
`.zip` files could be *any* format.

I brought over Brendan's test that reproduces the bug as well.

Co-authored-by: Brendan Zagaeski <brzaga@microsoft.com>
@brendanzagaeski
Copy link
Contributor

Release status update

A new Preview version of Xamarin.Android has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.

Fix included in Xamarin.Android SDK version 11.0.99.34.

Fix included on Windows in Visual Studio 2019 version 16.8 Preview 2. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.

Fix included on macOS in Visual Studio 2019 for Mac version 8.8 Preview 2. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

@brendanzagaeski
Copy link
Contributor

Release status update

A new Release version of Xamarin.Android has now been published that includes the fix for this item.

Fix included in Xamarin.Android SDK version 11.1.0.17.

Fix included on Windows in Visual Studio 2019 version 16.8. To get the new version that includes the fix, check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/.

Fix included on macOS in Visual Studio 2019 for Mac version 8.8. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
5 participants