-
Notifications
You must be signed in to change notification settings - Fork 691
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
AndroidX.JetBrains.Annotations – Package namespace conflict when binding native kotlin libraries #1176
Comments
Thanks for the feedback. So, let me see if I understand this correctly. This is kotlin stdlib pom.xml https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/1.5.0/kotlin-stdlib-1.5.0.pom
Removing nuget dependency There are 2 workaround that could work:
|
closing this one. |
Sorry, missed the earlier message, Fully qualified namespaces don't work because the The 'fix' would be to use the Then you'd include the org.jetbrains.annotations jar and not expose it through C# so you don't get any namespace conflicts. The alternative would be to re-namespace the |
That is to say, change the import here: https://github.com/xamarin/XamarinComponents/blob/589b5fb2befe500e1497e106e66a555fbf0eaf3a/Android/Kotlin/source/Xamarin.Jetbrains.Annotations/Transforms/Metadata.xml
To:
@moljac sorry not sure if Github will notify you with this now being closed. |
If you check my work - I try to use This is because of several reasons:
Seems I'll have to add these to readme.
When we bind dependencies and transitive deps, we usually do not know whether API will be used from managed code (C#) or not. In most cases I am not API expert, so "the best bet" is to bind it with C# API surfaced and this is also due to the fact that we have no assurance that JetBrains will release their library like in this case. Bottom line: will discuss it and see what can we/I do. |
Unfortunately, changing the namespace will break every application and NuGet package that currently uses these annotations, as .NET does not have a way to type forward to a different namespace. If we just use the JetBrains version of namespace JetBrains.Annotations
{
[Register("org/jetbrains/annotations/Contract", "", "JetBrains.Annotations.IContractInvoker")]
public interface IContract : IAnnotation, IJavaObject, IDisposable, IJavaPeerable
{
[Register("pure", "()Z", "GetPureHandler:JetBrains.Annotations.IContractInvoker, Xamarin.Jetbrains.Annotations")]
bool Pure();
[Register("value", "()Ljava/lang/String;", "GetValueHandler:JetBrains.Annotations.IContractInvoker, Xamarin.Jetbrains.Annotations")]
string Value();
}
} The only "safe" way to "rename" the namespace I can think of would be to create a second |
Ah of course that makes sense, the Jetbrains.Annotations package isn't a java binding.
Just saw you posted twice, guess the options are pretty limited, I don't imagine a breaking change like this would be that bad to users. They'd need to replace the |
If it was simply an issue of a compile time error then it wouldn't be too big of an issue. The bigger issue is already compiled libraries. That is, any already published NuGet referencing the existing library types would contain type references to ex: |
This is what the C# namespace alias qualifier is for. You can use namespace JetBrains.Annotations {
class AnotherExample {}
}
namespace Xamarin.JetBrains.Annotations {
class Example {}
class App {
public static void Main ()
{
// CS0234 if `global::` isn't present on following line
global::JetBrains.Annotations.AnotherExample e = null;
}
}
} |
Hey @jonpryor |
That is what the C# namespace alias qualifier alongside extern aliases is for. In your C# source code, you could do: // At global scope
extern alias JetBrains; Within your <ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="…" Aliases="JetBrains" />
</ItemGroup>
extern alias JetBrains;
partial class Example {
JetBrains::JetBrains.Annotations.NotNull notNull = null;
} Note that when using |
I ran into this problem when I upgraded <Target Name="HideXamarinJetBrains" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Xamarin.Jetbrains.Annotations'">
<Aliases>DoNotUse</Aliases>
</ReferencePath>
</ItemGroup>
</Target> |
@gtbuchanan Thanks! This solved the issue for me (using Xamarin Forms) whilst building the Android project. |
In our specific use case, the namespace/type conflict was causing downstream issues. So the fix was to add This won't fix the issue in the base project, but any project that references it will be unaffected. <ItemGroup>
- <PackageReference Include="Xamarin.AndroidX.Window" Version="1.2.0.1" />
+ <PackageReference Include="Xamarin.AndroidX.Window" Version="1.2.0.1" PrivateAssets="compile" />
</ItemGroup> |
When including the Kotlin standard library (jdk 7 version 1.5.0.1) I have a namespace conflict with JetBrains.Annotations which we leverage heavily.
For the time being I've worked around it with a target but would it be possible to remove this dependency?
The text was updated successfully, but these errors were encountered: