-
Notifications
You must be signed in to change notification settings - Fork 564
Description
Android framework version
net10.0-android (Preview)
Affected platform version
VS 2026 18.1.1, net10.0-android
Description
My Problem
I'm trying to create an Android binding around a native library I would like to use in my .net maui application. To start this process, I've created an Android Library (Android studio) and added the gradle dependencies I needed:
dependencies {
implementation("com.stripe:stripeterminal-taptopay:5.1.1")
implementation("com.stripe:stripeterminal-core:5.1.1")
}After that, I've created a java class consuming those dependencies. Here one of the problematic methods:
public static void initialize(@NonNull Application application,
@NonNull com.stripe.stripeterminal.external.callable.ConnectionTokenProvider tokenProvider,
@NonNull com.stripe.stripeterminal.external.callable.TerminalListener listener) throws TerminalException {
//My code using the native library
}The Android Library is building as expected.
The second step, is to open Visual Studio and create a Android Java Binding Library consuming the Android Library compiled in the first step. To do so, I add reference to build.gradle.kts in project file like:
<ItemGroup>
<AndroidGradleProject Include="../../native/StripeAndroidBinding/build.gradle.kts">
<ModuleName>dotnetbinding</ModuleName>
</AndroidGradleProject>
</ItemGroup>And add information to Metadata.xml:
<metadata>
<attr path="/api/package[@name='com.company.dotnetbinding']" name="managedName">StripeAndroidBinding</attr>
</metadata>Nothing else. At this point, the Android Java Binding Library is compiling.
The third step is consuming my Android Java Binding Library from my .net maui project. I can use most of the methods, but, the problem is that some methods (like initialize) are just missing from my Binding. By taking a look at (wiki), I have followed the steps to determine my problem:
- Search for my method
initializeinsideapi.xml.class-parse. Seems that the method is here:
<method
abstract="false"
deprecated="not deprecated"
final="false"
name="initialize"
native="false"
return="void"
jni-return="V"
static="true"
synchronized="false"
visibility="public"
bridge="false"
synthetic="false"
jni-signature="(Landroid/app/Application;Lcom/stripe/stripeterminal/external/callable/ConnectionTokenProvider;Lcom/stripe/stripeterminal/external/callable/TerminalListener;)V">
<parameter
name="application"
type="android.app.Application"
jni-type="Landroid/app/Application;"
not-null="true" />
<parameter
name="tokenProvider"
type="com.stripe.stripeterminal.external.callable.ConnectionTokenProvider"
jni-type="Lcom/stripe/stripeterminal/external/callable/ConnectionTokenProvider;"
not-null="true" />
<parameter
name="listener"
type="com.stripe.stripeterminal.external.callable.TerminalListener"
jni-type="Lcom/stripe/stripeterminal/external/callable/TerminalListener;"
not-null="true" />
<exception
name="com/stripe/stripeterminal/external/models/TerminalException"
type="com.stripe.stripeterminal.external.models.TerminalException"
type-generic-aware="com.stripe.stripeterminal.external.models.TerminalException" />
</method>-
Search for my method in
api.xml. Seems thatapi.xmldoes not contain the definition. So, following the wiki, I'm atApiXmlAdjuster. -
Since I'm at
ApiXmlAdjuster, the next step is to take a look at myjava-resolution-report.log. Following what @jpobst said here, I'm just looking at first cycle:
==== Cycle 1 ====
The method '[Method] void initialize(android.app.Application application, com.stripe.stripeterminal.external.callable.ConnectionTokenProvider tokenProvider, com.stripe.stripeterminal.external.callable.TerminalListener listener)' was removed because the Java parameter type 'com.stripe.stripeterminal.external.callable.ConnectionTokenProvider' could not be found.
The method '[Method] void initialize(android.app.Application application, com.stripe.stripeterminal.external.callable.ConnectionTokenProvider tokenProvider, com.stripe.stripeterminal.external.callable.TerminalListener listener)' was removed because the Java parameter type 'com.stripe.stripeterminal.external.callable.TerminalListener' could not be found.
The class '[Class] com.company.dotnetbinding.TapToPayImplementation.1' was removed because the Java implemented interface type 'com.stripe.stripeterminal.external.callable.DiscoveryListener' could not be found.- Just in case, by using a java decompiler on
stripeterminal-external-5.1.1.aar, I can seeTerminalListener,ConnectionTokenProviderandDiscoveryListenerexist as interfaces. For instance,TerminalListenerlooks like this:
package com.stripe.stripeterminal.external.callable;
import com.stripe.stripeterminal.external.models.ConnectionStatus;
import com.stripe.stripeterminal.external.models.PaymentStatus;
import kotlin.Metadata;
import kotlin.jvm.internal.Intrinsics;
import org.jetbrains.annotations.NotNull;
@Metadata(mv = {1, 9, 0}, k = 1, xi = 48, d1 = {"\000\034\n\002\030\002\n\002\020\000\n\000\n\002\020\002\n\000\n\002\030\002\n\000\n\002\030\002\n\000\bf\030\0002\0020\001J\020\020\002\032\0020\0032\006\020\004\032\0020\005H\026J\020\020\006\032\0020\0032\006\020\004\032\0020\007H\026\001\000\002\006\n\004\b!0\001\006\b\006\001"}, d2 = {"Lcom/stripe/stripeterminal/external/callable/TerminalListener;", "", "onConnectionStatusChange", "", "status", "Lcom/stripe/stripeterminal/external/models/ConnectionStatus;", "onPaymentStatusChange", "Lcom/stripe/stripeterminal/external/models/PaymentStatus;", "kmpcore_sdk_terminal-external-models_public"})
public interface TerminalListener {
default void onConnectionStatusChange(@NotNull ConnectionStatus status) {
Intrinsics.checkNotNullParameter(status, "status");
}
default void onPaymentStatusChange(@NotNull PaymentStatus status) {
Intrinsics.checkNotNullParameter(status, "status");
}
}- I have also used the java decompiler to check my .aar generated in first step and the
initializemethod is there.
What I've tried
- Changing
initializeparameters to abstract classes implementing the original interfaces. (Trick doesn't work) - Adding
com.stripe:stripeterminal-externaldependency into my Android Library projectbuild.gradle.kts. (The same result as before adding it) - Adding reference to
com.stripe.stripeterminal.external.aarinto my Android Java Binding Library project:
<ItemGroup>
<AndroidGradleProject Include="../../native/StripeAndroidBinding/build.gradle.kts">
<ModuleName>dotnetbinding</ModuleName>
</AndroidGradleProject>
<AndroidLibrary Include="../../../../stripeterminal-external-5.1.1.aar" Visible="true"/>
</ItemGroup>But this generates 30+ errors like:
...
error CS0738: 'TapToPayUxConfiguration.ITapZone.Right.Creator' does not implement interface member 'IParcelableCreator.CreateFromParcel(Parcel?)'. 'TapToPayUxConfiguration.ITapZone.Right.Creator.CreateFromParcel(Parcel)' cannot implement 'IParcelableCreator.CreateFromParcel(Parcel?)' because it does not have the matching return type of 'Object'.
error CS0738: 'TapToPayUxConfiguration.ITapZone.Right.Creator' does not implement interface member 'IParcelableCreator.NewArray(int)'. 'TapToPayUxConfiguration.ITapZone.Right.Creator.NewArray(int)' cannot implement 'IParcelableCreator.NewArray(int)' because it does not have the matching return type of 'Object[]'.
....Also is generating warnings like:
...
The "Com.Stripe.Stripeterminal.External.Models.TerminalErrorCode.Companion" has been omitted due to a duplicate nested type name. (Java type: "com.stripe.stripeterminal.external.models.TerminalErrorCode")
...And java-resolution-report doesn't look good:
I'm really stuck right now I would really appreciate some help here. I'm running out of ideas.
Steps to Reproduce
- Create Android Library project (Android studio) using the native library.
- Create Android Java Binding Library referencing this Android Library project.
- Create .net maui application referencing this Android Java Binding Library.
- I can compile and access all methods but a couple of them that request parameters of unresolved types from the native library.
Did you find any workaround?
No workaround found