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

Net7-android binding has ClassNotFoundException when trying to consume #8308

Closed
svaldetero opened this issue Aug 28, 2023 · 15 comments
Closed
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned.

Comments

@svaldetero
Copy link

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

VS 17.6.3, net7.0-android

Description

I have a net7.0-android binding project created here: https://github.com/Envoc/envoc-stripe-binding/blob/android-2.19.0/src/StripeTerminal/Envoc.Stripe.Terminal.Android/Envoc.Stripe.Terminal.Android.csproj
With a nuget package here: https://www.nuget.org/packages/Envoc.Stripe.Terminal.Android.

Adding that nuget package and trying to consume the library via the line Com.Stripe.Stripeterminal.Terminal.IsInitialized; from a File -> New Maui Project app causes the exception java.lang.ClassNotFoundException: Didn't find class "com.stripe.jvmcore.logging.terminal.log.Log"

It looks like that class is in com.stripe_stripeterminal-internal-common.aar under the libs folder.

Android binding troubleshooting says to add a missing jar file, but this is a lib of an included aar. Is this a packaging issue?

Steps to Reproduce

  1. Create new Maui app
  2. Add nuget reference to Envoc.Stripe.Terminal.Android
  3. In the click me button add a call to the nuget like Com.Stripe.Stripeterminal.Terminal.IsInitialized;

Did you find any workaround?

No

Relevant log output

No response

@svaldetero svaldetero added the needs-triage Issues that need to be assigned. label Aug 28, 2023
@jpobst
Copy link
Contributor

jpobst commented Aug 28, 2023

This feels more like a packaging issue than a binding issue, so I'm gonna pass it to Peppers/Dean first.

https://nuget.info/packages/Envoc.Stripe.Terminal.Android/2.19.0

@jpobst jpobst assigned dellis1972 and jonathanpeppers and unassigned jpobst Aug 28, 2023
@jpobst jpobst added the Area: App+Library Build Issues when building Library projects or Application projects. label Aug 28, 2023
@jonathanpeppers
Copy link
Member

@svaldetero
Copy link
Author

I don't think I need those in the public API and they required so much more fixing in the Metadata.xml. I'll add the pack=true and see if that fixes it.

AndroidMavenLibrary is from XamPrototype.Android.MavenBinding.Tasks nuget package. Github

@jonathanpeppers
Copy link
Member

I found the repo now:

https://github.com/jpobst/Prototype.Android.MavenBindings/blob/main/src/Microsoft.Android.MavenBinding.Tasks/XamPrototype.Android.MavenBinding.Tasks.targets

It looks like nothing sets Pack="true" for you, but if you set yourself it should get passed along.

@jpobst
Copy link
Contributor

jpobst commented Aug 30, 2023

I assumed this would pick up the AndroidLibrary defaults for Pack and Bind, but perhaps not?

<AndroidLibrary Include="@(_ResolvedAndroidMavenLibraries)" />

@jpobst
Copy link
Contributor

jpobst commented Aug 31, 2023

Doing a local test with:

<ItemGroup>
    <AndroidMavenLibrary Include="com.stripe:stripeterminal-internal-models" Version="2.18.1" Bind="False" />
    <AndroidMavenLibrary Include="org.jetbrains.kotlin:kotlin-parcelize-runtime" Version="1.7.20" Bind="False" />
    <AndroidMavenLibrary Include="org.jetbrains.kotlin:kotlin-android-extensions-runtime" Version="1.7.20" />
    <AndroidMavenLibrary Include="com.squareup.wire:wire-runtime" Version="4.4.3" />
</ItemGroup>

It would appear that it does pick up the Pack and Bind defaults for AndroidLibrary:

image

@jonathanpeppers
Copy link
Member

@jpobst and they don't make it to the .nupkg? Can you share a .binlog of dotnet pack -bl?

@jpobst
Copy link
Contributor

jpobst commented Aug 31, 2023

For my test case, the 3 .jar files end up in prototype-bind-test.aar which is included in the .nupkg as expected. However the com.stripe_stripeterminal-internal-models.aar file doesn't appear in the bin folder or the .nupkg.

image

msbuild.zip

(.NET: 7.0.307)

@jpobst
Copy link
Contributor

jpobst commented Aug 31, 2023

Actually, this may be a .NET 7 bug that is fixed in .NET 8. If I switch to net8.0-android then it works as expected:

image

(.NET: 8.0.100-preview.7.23376.3)

@jpobst
Copy link
Contributor

jpobst commented Aug 31, 2023

In fact, it does not work in .NET 8 P6, but it does work in P7, so I suspect it is probably this fix?

#8193.

@jonathanpeppers
Copy link
Member

Yeah, I initially was going to service this fix to .NET 7, but it caused other issues, ended up being two fixes:

If we don't find any further issues with these, maybe we could take them both back to .NET 7?

For now as a workaround, you could do something like adding a <None/> entry mentioned here: #8190 (comment)

And also set Pack="true" PackagePath="lib/net7.0-android33.0" to get the file in the right location in the .nupkg file.

@svaldetero
Copy link
Author

Can confirm that using the two workarounds allowed the additional .aars to be included in the nuget:

<AndroidMavenLibrary Include="com.stripe:stripeterminal-internal-common" Version="$(StripeVersion)" Bind="False" />
<AndroidMavenLibrary Include="com.stripe:stripeterminal-internal-models" Version="$(StripeVersion)" Bind="False" />

<None Include="$(LocalAppData)/MavenCacheDirectory/central/com.stripe/stripeterminal-internal-common/$(StripeVersion)/com.stripe_stripeterminal-internal-common.aar"
	Pack="True" CopyToOutputDirectory="PreserveNewest" PackagePath="lib/net7.0-android33.0"  />

<None Include="$(LocalAppData)/MavenCacheDirectory/central/com.stripe/stripeterminal-internal-models/$(StripeVersion)/com.stripe_stripeterminal-internal-models.aar"
	Pack="True" CopyToOutputDirectory="PreserveNewest" PackagePath="lib/net7.0-android33.0"  />

@jonathanpeppers
Copy link
Member

For now, I think we can close, as we have the two PRs that should fix this in .NET 8:

We'll consider backporting to .NET 7, so anyone upvote or comment if you run into this. It will help us know how important it is to backport these. Thanks!

@ggbtvs
Copy link

ggbtvs commented Jan 19, 2024

@svaldetero Hi, I wonder if you can help me with creating Stripe Terminal bindings for Xamarin Android (not Maui). I am having issues and would appreciate any tips / advice on hoe to get it working. I've created iOS version without any issues. I'm not as familiar with binding projects for Android though. Thanks in advance, if you can.

@svaldetero
Copy link
Author

svaldetero commented Jan 22, 2024

@svaldetero Hi, I wonder if you can help me with creating Stripe Terminal bindings for Xamarin Android (not Maui). I am having issues and would appreciate any tips / advice on hoe to get it working. I've created iOS version without any issues. I'm not as familiar with binding projects for Android though. Thanks in advance, if you can.

@ggbtvs If you need the old framework bindings, I would check out this github: https://github.com/Square-Six/Xamarin.Stripe.Terminal.Android. I referenced it a lot when making mine.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned.
Projects
None yet
Development

No branches or pull requests

5 participants