Skip to content

Bindings from $(AndroidJavaSource) don't work with Intellisense #7692

Closed

Description

@jpobst

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

.NET 7, VS 2022 17.4. 17.5 P2

Description

.NET 7's $(AndroidJavaSource) is great for simplifying several binding tasks. However, while it compiles on a build, the .cs files it generates do not get added to the files used by IntelliSense, and thus trying to consume the bindings is difficult because they do not show up in IntelliSense dropdowns and show as errors in the editor.

image

Looking at a design time build, this appears to be because they are never added to @(Compile) which is used by <Csc>:
image

For comparison, it appears we add Resources.designer.cs to @(Compile) when $(ManagedDesignTimeBuild)' == 'True'.

https://github.com/xamarin/xamarin-android/blob/8c24b8ff0b32e198311b75e3bbce904989504f7c/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets#L1076

Steps to Reproduce

  1. dotnet new android
  2. Add a .java file to the project
  3. Attempt to consume the generated binding in the project

Minimal test case:
AndroidApp2.zip

Did you find any workaround?

No response

Relevant log output

No response

Activity

  1. added
    Area: App+Library BuildIssues when building Library projects or Application projects.
    needs-triageIssues that need to be assigned.
    on Jan 12, 2023
  2. dellis1972 commented on Jan 12, 2023

    @dellis1972
    Contributor

    My gut says that AddBindingsToCompile is not being called during a Design Time Build.

  3. dellis1972 commented on Jan 12, 2023

    @dellis1972
    Contributor

    Yup

    Target "AddBindingsToCompile" skipped, due to false condition; ( '$(_AndroidGenerateManagedBindings)' == 'true' ) was evaluated as ( '' == 'true' ).
    

    _AndroidGenerateManagedBindings is empty, probably because we are not evaluating it.
    I'm not sure we want to do a Java build in the DTB though....
    If its done already and the source has been generated the we should include it. But I'm not sure about doing a java compile at that time though.

  4. mohachouch commented on Mar 7, 2023

    @mohachouch

    Hi, we have the same problem in my company. it makes this feature totally unusable, don't wait for .net8. The release is scheduled for November it's too long for a bug fix. Thanks

  5. jonathanpeppers commented on Mar 7, 2023

    @jonathanpeppers
    Member

    @mohachouch as a workaround, I think you can just put the .java file in a separate class library? Did you try that?

    Then Intellisense should be able to use the compiled .dll on disk in that case.

  6. mohachouch commented on Mar 7, 2023

    @mohachouch

    @jonathanpeppers Thanks for tour Quick response. I tried to separate in a library but I had the same problem. I feel like it's more related to the new csproj format. I will try again tomorrow.

  7. jonathanpeppers commented on Mar 7, 2023

    @jonathanpeppers
    Member

    I hit similar issues working on:

    https://github.com/jonathanpeppers/spice/blob/main/src/Spice/Platforms/Android/Interop.java

    I spent a little time on it, but I didn't see an immediately, easy fix.

  8. mohachouch commented on Mar 8, 2023

    @mohachouch

    Hi @jonathanpeppers,

    I have the same bug with seperate class library : https://github.com/mohachouch/JavaBindingBug

    The compilation is ok but intelisense not working for both

    image

    Thanks

  9. mohachouch commented on Mar 9, 2023

    @mohachouch

    Hi @jonathanpeppers do you reproduce the bug?

  10. mohachouch commented on Mar 14, 2023

    @mohachouch

    Any news @jonathanpeppers ?

  11. jonathanpeppers commented on Mar 15, 2023

    @jonathanpeppers
    Member

    Please others upvote, if this impacts you. This helps us know how important it is.

    I'm currently working on MAUI issues that have a lot louder feedback. 👀

  12. mohachouch commented on Aug 15, 2023

    @mohachouch

    Hi @jonathanpeppers,

    Any News about this bug ? This bug is present since .net 6, so since 2 years.

    Thanks

  13. locked and limited conversation to collaborators on Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions