我的 flutter 应用程序无法在发行版 apk 中的 PayHere 支付网关中继续进行支付。在 Debug模式下并在 Release模式下运行应用程序工作正常。但只有在构建和运行发布 apk 时才会出错。
最佳答案
这很可能是 Android 在 Release 版本上的代码压缩问题。建议的解决方案是通过添加适当的 ProGuard 规则来尝试防止 PayHere 代码在 Release 版本中被剥离。
添加 ProGuard 规则
-keep class lk.payhere.** { *; }
指示 Android 使用 ProGuard 文件minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
“build.gradle”文件中的最终结果应该是这样的:android {
compileSdkVersion 29
// ...
buildTypes {
release {
signingConfig signingConfigs.debug
// the code we added...
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
最后,做一个干净的构建,看看你的问题是否得到解决。
如果问题仍然存在,请尝试在 PayHere Flutter SDK 的错误处理程序中添加一个 Alert 弹出窗口,以查看是否返回了可读错误。
就像是:
PayHere.startPayment(
paymentObject,
(paymentId) {
print("One Time Payment Success. Payment Id: $paymentId");
},
(error) {
print("One Time Payment Failed. Error: $error");
// add alert code here
},
() {
print("One Time Payment Dismissed");
}
);
最后的手段是联系 PayHere 自己寻求支持。如果是这种情况,您可以发送邮件至 techsupport@payhere.lk请注意,根据 documentation,ProGuard 规则也适用于 Android 的 R8 代码缩减。 .
When building the release version of your app, by default, R8 automatically performs the compile-time tasks described above for you. However, you can disable certain tasks or customize R8’s behavior through ProGuard rules files. In fact, R8 works with all of your existing ProGuard rules files, so updating the Android Gradle plugin to use R8 should not require you to change your existing rules.
关于Flutter 发布 apk 无法在 PayHere 中进行付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65084473/