我有一个现有的Google Play Android应用程序使用Google Billing Library,我想使用最近发布的实现兼容API的Amazon Appstore Billing Compatibility SDK.
他们的指南建议如下替换Java/Kotlin行,第一次使用时效果很好:
import com.android.billingclient.api.*
使用
import com.amazon.device.iap.billingclient.api.*
我已经使用Gradle flavor机制略微调整了构建(例如,不同的store 和应用程序支持URL),所以在理想情况下,我可以利用它.也就是说,我的app/build.gradle
档案里有这样一条:
flavorDimensions = ["appstore"]
productFlavors {
google {
dimension "appstore"
buildConfigField "String", "ENCRYPTED_GOOGLE_IAP_KEY", "<removed>"
}
amazon {
dimension "appstore"
buildConfigField "String", "ENCRYPTED_GOOGLE_IAP_KEY", "ignored"
}
}
并且我已经在相同的build.gradle
中配置了依赖项,以便只有适当的库可用:
dependencies {
...
googleImplementation 'com.android.billingclient:billing:6.1.0'
amazonImplementation files('libs/appstore-billing-compatibility-4.1.0.jar')
}
So, what I'd really like to be able to do is to conditionally import the appropriate dependency, i.e. 使用 a preprocessor, it would be something like this:
#if defined(amazon)
import com.android.billingclient.api.*
#endif
#if defined(google)
import com.amazon.device.iap.billingclient.api.*
#endif
当然,这不是一个Java/Kotlin兼容的方法. 我可以将现有的实现复制到两个文件夹中,并只调整导入行,即:
src/
|-- google/
| |-- java/
| |-- com/
| |-- example/
| |-- MyPurchaseCode.kt
|-- amazon/
| |-- java/
| |-- com/
| |-- example/
| |-- MyPurchaseCode.kt
但是代码除了这一行之外都是相同的,所以维护起来会很麻烦(and, after all, isn't the point of the Amazon compatibility library that I can keep my existing code:))
Any suggestions on how I might do this? I wondered about creating some sort of "wrapper" interface and then having 2 source files, located as above, that implement it. But they're big 使用 many classes and my understanding is that I'd have to clone the declarations.
也许我想得太多了,有一些简单的答案!(I admit my Java / Kotlin knowledge has faded …)
提前感谢!