简体   繁体   中英

package com.google.android.gms.samples.wallet does not exist import com.google.android.gms.samples.wallet.Constants

I'm new Android and more new to the payment part of it , i'm going through this link to implement the Gpay into my app

https://developers.google.com/pay/api/android/guides/tutorial#checkoutactivity.java

so i copy the code as is , the version i implemented is

    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.android.gms:play-services-wallet:18.1.2'
    implementation 'com.android.support:appcompat-v7:28.0.0'

but when i run i keep getting this error

package com.google.android.gms.samples.wallet does not exist import com.google.android.gms.samples.wallet.Constants

how can i resolve this error?

I had a similar problem with a reference to com.google.android.gms.samples.wallet.Constants.PAYMENTS_ENVIRONMENT appearing in the createPaymentsClient method in that tutorial. The code being referred to can be found at https://github.com/google-pay/android-quickstart/blob/master/java/app/src/main/java/com/google/android/gms/samples/wallet/Constants.java , so you can either refactor this into your codebase directly, and change the import statement in paymentsUtil.java to refer to your new location for this file, or you can simply copy following the key line over into paymentsUtil.java and remove the import altogether:

public static final int PAYMENTS_ENVIRONMENT = WalletConstants.ENVIRONMENT_TEST;

The second option is probably easier for when you want to move to a live production environment.

Let me know if this is helpful.

I fixed by using the Constants class in the sample application in here enter link description here . Just download as zip, open and copy the Constant class in your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM