Closed justin-caldicott closed 3 months ago
Have you added the following NuGet packages to your project?
Thanks @jpobst, yes I added the new packages and followed the errors in Rider to make sure all implicit dependencies are included too. There are no C# errors now, just these java ones.
I admit I'm not sure how the java side of the bindings work. The java files with errors are in e.g. obj/Debug/android/<guid>/SomeFragment.java
. The lines it's complaining about are:
public class SomeFragment
extends androidx.fragment.app.Fragment <<<<<< javac cannot find androidx.fragment.app
implements
mono.android.IGCUserPeer
I saw in the installed packages there's an aar
folder with e.g. androidx.fragment.fragment.aar
inside. Presumably this is where it should be finding the package from?
One unusual thing here is we restore packages with -ExcludeVersion
to a packages folder within the repo root. Assembly resolution is OK with this due to hint paths, e.g.
<Reference Include="Xamarin.AndroidX.Fragment">
<HintPath>..\packages\Xamarin.AndroidX.Fragment\lib\monoandroid12.0\Xamarin.AndroidX.Fragment.dll</HintPath>
</Reference>
Maybe this causes problems for java package resolution somehow? It didn't have this behaviour on previous versions, but then we're jumping a lot of versions in one go as the app wasn't updated for a couple of years.
I suspect using <Reference>
is the issue. These .dll
s do not contain the .aar
embedded in them for build performance reasons.
When you reference it as a <PackageReference>
the MSBuild system will run any .targets
files in the NuGet package when you build your project.
If you look in the NuGet you'll see build\monoandroid12.0\Xamarin.AndroidX.Fragment.targets
.
This contains this MSBuild which adds the .aar
to your project:
<ItemGroup>
<AndroidAarLibrary Include="$(MSBuildThisFileDirectory)..\..\aar\androidx.fragment.fragment.aar">
<AndroidXSkipAndroidXMigration>true</AndroidXSkipAndroidXMigration>
</AndroidAarLibrary>
</ItemGroup>
By using a <Reference>
instead of a <PackageReference>
this never gets executed and the .aar
never gets added to your application.
Many thanks @jpobst, all set!
I'm not in a position to switch to <PackageReference>
just yet. But what you explained let me realise I could just add the android library references to the project file directly. They probably would have been added if I'd installed the package properly, rather than just installing them to a folder. Really do need to update our build scripts!
So I have a bunch of additional lines like:
<AndroidAarLibrary Include="$(ProjectDir)..\packages\Xamarin.AndroidX.Fragment\aar\androidx.fragment.fragment.aar"/>
There were already a couple there for Kotlin.StdLib and Kotlin.StdLib.Common.
Sorry, not really an issue in the product then, just support.. but much appreciated. Closing.
Android application type
Classic Xamarin.Android (MonoAndroid12.0, etc.)
Affected platform version
Rider 2023.3.3 on MacOS 14.3.1 with Apple Chip
Description
Attempting to upgrade an old Xamarin.Android app, not using Xamarin.Forms, to a recent targetVersion - trying v13.0, 33. On swapping all
Xamarin.Android.Support
usages forXamarin.AndroidX
, I don't seem to be able to get past some strange java compilation errors.The C# code appears to compile fine, but getting lots of java errors like the following:
Any guidance appreciated - I've exhausted pretty much every angle I can think of. At the least this feels like a documentation issue somewhere.
Steps to Reproduce
Not clarified - working with an existing project
Did you find any workaround?
No response
Relevant log output
No response