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.
lint.jar file. The possibility of having a lint.jar is described here: https://developer.android.com/studio/projects/android-library#aar-contents1> 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.
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).
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:
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.
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/master@905836d
SQLite: xamarin/sqlite/3.28.0@46204c4
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-5@9f4ed4b
Hi, this issue was fixed in https://github.com/xamarin/xamarin-android/pull/4385, the fix will be part of the next 16.6 preview/release.
Thanks for confirming!
Release status update
In fact, a Preview has already 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 10.3.0.33
Fix included on Windows in Visual Studio 2019 version 16.6 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.6 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.
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 10.3.1.0.
Fix included on Windows in Visual Studio 2019 version 16.6. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.
Fix included on macOS in Visual Studio 2019 for Mac version 8.6. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.
@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
@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 https://github.com/xamarin/xamarin-android/pull/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.
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!");
}
}
The test should pass.
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.
Thanks for fixing, can you also update this with a release status?As in which release will have the fix @brendanzagaeski
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.
_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.
_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.