square / in-app-payments-android-quickstart

In-App Payments Quick Start Sample Android App
Apache License 2.0
41 stars 41 forks source link

Duplicate class com.squareup.Pan found in modules jetified-card-42 (com.squareup.android:card:42) and jetified-reader-sdk-internals-1.5.1 (com.squareup.sdk.reader:reader-sdk-internals:1.5.1) #30

Open Abdulrehman53 opened 3 years ago

Abdulrehman53 commented 3 years ago

Getting "Duplicate class com.squareup.Pan found in modules jetified-card-42 (com.squareup.android:card:42) and jetified-reader-sdk-internals-1.5.1 (com.squareup.sdk.reader:reader-sdk-internals:1.5.1)" when using both in app payment and reader sdk in same project.

def inAppPaymentsSdkVersion = '1.5.2' implementation "com.squareup.sdk.in-app-payments:card-entry:$inAppPaymentsSdkVersion" implementation "com.squareup.sdk.in-app-payments:google-pay:$inAppPaymentsSdkVersion" def readerSdkVersion = "1.5.1" implementation "com.squareup.sdk.reader:reader-sdk-$SQUARE_READER_SDK_APPLICATION_ID:$readerSdkVersion" runtimeOnly "com.squareup.sdk.reader:reader-sdk-internals:$readerSdkVersion"

divyeshgohil85 commented 2 years ago

We are also facing the same issue, while trying to integrate GiftCard payments and Square Reader.

GiftCardPayment SDK : implementation 'com.squareup.sdk.in-app-payments:card-entry:1.5.2'

Square Reader SDK : runtimeOnly "com.squareup.sdk.reader:reader-sdk-internals:1.5.1"

Error: Duplicate class com.squareup.Pan found in modules jetified-card-42 (com.squareup.android:card:42) and jetified-reader-sdk-internals-1.5.1 (com.squareup.sdk.reader:reader-sdk-internals:1.5.1)

darkengine commented 2 years ago

Same here. We support Square in-app purchases and card readers. So there are two Square libraries in our project:

We can get through the build phase by excluding module for one of them:

implementation("com.squareup.sdk.in-app-payments:card-entry:1.5.0") { exclude group : 'com.squareup.android',module:'card' }

But it will crash when taking payment with Square in-app purchase.

Venkateswarlu-Android commented 2 years ago

We are also facing the same issue, Please fix it soon.

Due to this we are unable to use both dependencies in one project.

Duplicate class com.squareup.Pan found in modules jetified-card-42 (com.squareup.android:card:42) and jetified-reader-sdk-internals-1.5.6 (com.squareup.sdk.reader:reader-sdk-internals:1.5.6)

lrob7325 commented 1 year ago

I'm receiving this error too locally and on the expo build server as well. I've tried adding com.squareup.Pan to android.jetifier.ignorelist and still no luck.

Screen Shot 2022-10-01 at 11 14 14 AM

lrob7325 commented 1 year ago

I'm receiving this error too locally and on the expo build server as well. I've tried adding com.squareup.Pan to android.jetifier.ignorelist and still no luck.

Screen Shot 2022-10-01 at 11 14 14 AM

So I found a solution to resolving the build error. To avoid misleading other devs, and preventing thumbs down, again, this is for resolving the build error. I added the code below to my app/build.gradle and it built successfully with both In-App-Payments SDK and Reader SDK. I understand excluding an entire module will provide issues down the line. I'm currently building this on the Expo remote server to test the apk on a physical device.

Note: The difficulty was trying to exclude the module from "reader-sdk-internals." My ultimate goal was to directly reference the namespace in either of those 2 dependencies. Hopefully, Square will have a resolution.

configurations { all { exclude group: "com.squareup.android", module: "card" } }

lrob7325 commented 1 year ago

23 hours later, I found a solution and verified that it works on Android!! Well, from the In-App-Payments SDK perspective! Reason I say that is because I haven't started development for the Square Reader SDK yet, and will within the next 2 weeks.

Solution (TLDR): Add the Square-Reader-Sdk repository directly into your repo, and modified the "reader-sdk-internals-x.x.x.jar" to not include the "Pan.class" file.

Overview: You may have seen my message above where adding "configurations { all { exclude group: "com.squareup.android", module: "card" } }" to the app/build.gradle would help build, but the Card Entry screen will crash in your app. I realized that Card is an entire module that is critical to the In-App-Payments SDK and removing would of course make the sdk useless, while square-reader-internals may have shared libraries between In-App and Reader (ie Pan.class).

Since we're downloading the Square repo local, and build-time, I thought, "why not maintain this repo until Square figures it out?" At this moment, 1.7.1 is the latest version. I logged into "https://sdk.squareup.com/android" with the repo credentials used in the build.gradle, and made a folder called "square" (can be any name) in my "android" folder. There I added the directories that exist in the Square repo we just logged into. "com/squareup/sdk/reader." In the "reader" directory, you should see 3 other directories that house .aar, .pom, and .jar files. Create those directories, and download those files and place them in their respective directories.

Next, I located the "reader-sdk-internals-x.x.x.jar" in the "reader-sdk-internals/x.x.x" subdirectory of "com/squareup/sdk/reader." I opened the .jar in the 7zip file manager and deleted "Pan.class".

Now that the class is removed, we need to stop pointing to Square's repo, and point to our new location. I commented the maven reference to that the repo, added "maven { url(new File("$rootDir/app/square")) }" and under dependences, I added "implementation fileTree(dir: "$rootDir/app/square", include: ['.aar', '.pom'], exclude: [])" --Make sure the "com.squareup.sdk.reader" implementation is commented out.

I also added "maven { url(new File("$rootDir/app/square")) }" to the project build.gradle (not sure if it's necessary, but it was just for safety measures).

With these changes, I was able to successfully build the app, and use the card entry screen. I'm not sure what else is, or isn't working, as I'm still in the early stages of development, but my app isn't broken (as of now) for the In-App-Payment sdk.

This solution isn't the most scalable. Whenever there's a new version, I'll have to bring down the latest version and remove the Pan.class from the reader-sk-internals-x.x.x.jar and update my "android/square" location in my repo. Hopefully, Square sees this post and makes it so that both SDKs can exist in the same app at the same time.

See pics for reference!

Screen Shot 2022-10-02 at 5 37 24 PM Screen Shot 2022-10-02 at 5 52 01 PM Screen Shot 2022-10-02 at 5 52 18 PM

darkengine commented 1 year ago

@lrob7325 Thanks for sharing your solution.

We remove the in-app payment SDK and use the card reader SDK with manual card input entry to handle paying with inputting card number situation.

lrob7325 commented 2 months ago

23 hours later, I found a solution and verified that it works on Android!! Well, from the In-App-Payments SDK perspective! Reason I say that is because I haven't started development for the Square Reader SDK yet, and will within the next 2 weeks.

Solution (TLDR): Add the Square-Reader-Sdk repository directly into your repo, and modified the "reader-sdk-internals-x.x.x.jar" to not include the "Pan.class" file.

Overview: You may have seen my message above where adding "configurations { all { exclude group: "com.squareup.android", module: "card" } }" to the app/build.gradle would help build, but the Card Entry screen will crash in your app. I realized that Card is an entire module that is critical to the In-App-Payments SDK and removing would of course make the sdk useless, while square-reader-internals may have shared libraries between In-App and Reader (ie Pan.class).

Since we're downloading the Square repo local, and build-time, I thought, "why not maintain this repo until Square figures it out?" At this moment, 1.7.1 is the latest version. I logged into "https://sdk.squareup.com/android" with the repo credentials used in the build.gradle, and made a folder called "square" (can be any name) in my "android" folder. There I added the directories that exist in the Square repo we just logged into. "com/squareup/sdk/reader." In the "reader" directory, you should see 3 other directories that house .aar, .pom, and .jar files. Create those directories, and download those files and place them in their respective directories.

Next, I located the "reader-sdk-internals-x.x.x.jar" in the "reader-sdk-internals/x.x.x" subdirectory of "com/squareup/sdk/reader." I opened the .jar in the 7zip file manager and deleted "Pan.class".

Now that the class is removed, we need to stop pointing to Square's repo, and point to our new location. I commented the maven reference to that the repo, added "maven { url(new File("$rootDir/app/square")) }" and under dependences, I added "implementation fileTree(dir: "$rootDir/app/square", include: ['.aar', '.pom'], exclude: [])" --Make sure the "com.squareup.sdk.reader" implementation is commented out.

I also added "maven { url(new File("$rootDir/app/square")) }" to the project build.gradle (not sure if it's necessary, but it was just for safety measures).

With these changes, I was able to successfully build the app, and use the card entry screen. I'm not sure what else is, or isn't working, as I'm still in the early stages of development, but my app isn't broken (as of now) for the In-App-Payment sdk.

This solution isn't the most scalable. Whenever there's a new version, I'll have to bring down the latest version and remove the Pan.class from the reader-sk-internals-x.x.x.jar and update my "android/square" location in my repo. Hopefully, Square sees this post and makes it so that both SDKs can exist in the same app at the same time.

See pics for reference!

Screen Shot 2022-10-02 at 5 37 24 PM Screen Shot 2022-10-02 at 5 52 01 PM Screen Shot 2022-10-02 at 5 52 18 PM

Just coming back to say that as of 6/23/2024, this solution worked. I needed to go from 1.7.1 to 1.7.5 for SDK 34. I'm still able to have both the Square Reader and In-App SDKs in the app.