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

Cannot use Java code generated from C#-written libraries in AndroidJavaSource files #9374

Open
aliyailina opened this issue Oct 5, 2024 · 4 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@aliyailina
Copy link

aliyailina commented Oct 5, 2024

Android framework version

net8.0-android

Affected platform version

.NET 8.0.303

Description

Issue inspired by #9334 recommended workaround. I tried to override specific method in Application (precisely, MvxAndroidApplication) class inheritor, which was not possible due to .NET bug, so I asked for workaround. The workaround was to use generated Java class of MvxAndroidApplication, which was impossible due to package crc6466d8e86b1ec8bfa8 does not exist error. I tried it with full bin/obj delete + clean + rebuild process, but then found that error happens and Java's MvxAndroidApplication is not even generated, so then tried to first successfully build project without my custom AndroidJavaSource file included, then include and build again. Nothing works.

Also tried with CommunityToolit.Maui's MauiApplication class, same error, so problem (I suppose) is not in MvvmCross.

Looks pretty similar #8191.

Here is sample and build log

Steps to Reproduce

Create new clear project, add MvvmCross library via NuGet, create .java file with this content:

package jcwusagesample;
public class BaseApplication extends crc6466d8e86b1ec8bfa8.MvxAndroidApplication {
 }

and try to build.

Also you can check sample attached in Description section.

Did you find any workaround?

Nope, but would be grateful for any workaround.

Relevant log output

No response

@aliyailina aliyailina added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Oct 5, 2024
@aliyailina aliyailina changed the title Cannot use Java code generated from C#-written libraries in AndroidJavaSource files Cannot use Java code generated from C#-written libraries from AndroidJavaSource files Oct 5, 2024
@aliyailina aliyailina changed the title Cannot use Java code generated from C#-written libraries from AndroidJavaSource files Cannot use Java code generated from C#-written libraries in AndroidJavaSource files Oct 5, 2024
@dellis1972
Copy link
Contributor

Your problem here is that the MvxAndroidApplication exists in MvvmCross.dll. So it is not a java type it is a C# type, so the type does not exist in any .jar file which is referenced by the project.

One of the limitations mentioned in the docs is that you can only use types which exist in .jar files (

).

Unfortuately any "java" code that might be generated won't be generated until after the Compile step of the main application has already been run. This is because AndroidJavaSource compilation happens before the Compile step, since its principal purpose is to bind java code. In this case though no java code exists.

@aliyailina
Copy link
Author

aliyailina commented Oct 6, 2024

@dellis1972 Yep, that is what I see either. I filed and issue because using MvvmCross in custom .java source was recommended by @jonpryor, so it is expected.to work.

So C# classes from C# written libraries are not supposed to be used in AndroidJavaSource files?

@dellis1972
Copy link
Contributor

dellis1972 commented Oct 6, 2024

So if you want to Bind the Java source then no, you cannot use the C# types because there is no java class files available at the time that runs.

If you don't want to bind it, then you probably can as the compilation of non-bindable .java files happens after _GenerateJavaStubs.

So if you add

    <ItemGroup>
      <AndroidJavaSource Update="BaseApplication.java" Bind="false" />
    </ItemGroup>

It will compile. You problem will be the java code you just compiled won't be available in C#.

@aliyailina
Copy link
Author

aliyailina commented Oct 6, 2024

@dellis1972 Thanks, that is what I thought. May I ask you then help with any workaround for #9334 (if there is any)?

Also, should I close issue as not planned?

@jpobst jpobst removed the needs-triage Issues that need to be assigned. label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
Development

No branches or pull requests

4 participants