Raj*_*nga 5 payment-gateway flutter
我的 flutter 应用程序无法在发布 apk 中的 PayHere 支付网关中继续付款。在调试模式下并在发布模式下运行应用程序工作正常。但只有在构建和运行release apk时才会出现错误。
该问题是由 Flutter\xe2\x80\x99s R8 代码收缩引起的,在发布版本中默认打开该代码收缩,如此处所述。从 Android Gradle 版本 3.4.0 开始,R8 不再使用 Proguard,如此处所述。然而,R8 仍然使用确切格式的混淆器规则文件,以排除仅在明确提供的情况下被混淆/删除的类。否则,未使用的代码将从最终产品中删除。
\n据了解,Flutter 和 Dart 内部用于链接 PayHere Android SDK 和 PayHere Flutter Dart 组件的 MethodChannel 受到了此代码混淆过程的影响。
\n有两种解决方案可以解决该问题。如果开发人员扩展现有的代码库,第一个可以提供更大的灵活性。第二种解决方案是快速 \xe2\x80\x9chotfix\xe2\x80\x9d,它禁用代码混淆以方便应用。
\n注意:在执行下文提到的解决方案之前,请保留现有代码库的备份。即使您启用了版本控制,也建议执行此步骤,因为 .gitignore 定义可能不会跟踪携带敏感信息的文件的更改。
\n如果您愿意手动创建 Pro-guard 规则文件或者您已经配置了 Pro-guard 规则,则首选此解决方案。下面提到了所需的步骤。
\n在您喜欢的 IDE 中打开您的 Flutter 项目。
\n在 \xe2\x80\x9c/android/app\xe2\x80\x9d 文件夹中创建一个名为 \xe2\x80\x9cproguard-rules.pro\xe2\x80\x9d 的新文件。
\n\n在上面步骤 2 中创建的 \xe2\x80\x9cproguard-rules.pro\xe2\x80\x9d 文件中添加以下代码行。
\n#Flutter Wrapper\n-keep class io.flutter.app.** { *; } \n-keep class io.flutter.plugin.** { *; } \n-keep class io.flutter.util.** { *; } \n-keep class io.flutter.view.** { *; } \n-keep class io.flutter.** { *; }\n-keep class io.flutter.plugins.** { *; } \n\n#the required rule\n-keep class lk.payhere.** { *; }\n
Run Code Online (Sandbox Code Playgroud)\n上面的代码排除了所有默认的 Flutter 库和 PayHere Android SDK 类。确保没有重叠的规则。如果您已有 \xe2\x80\x9cproguard-rules.pro\xe2\x80\x9d 文件,则只需添加最后一行。
\nNote that if you have already set up Proguard previously, you might be able to skip this step.
\nandroid {\n compileSdkVersion 29\n sourceSets {\n main.java.srcDirs += \'src/main/kotlin\'\n }\n lintOptions {\n disable \'InvalidPackage\'\n }\n defaultConfig {\n // Android configurations are usually here\n }\n // Signing Configurations are usually here\n buildTypes {\n release {\n signingConfig signingConfigs.debug\n\n // add these code lines\n minifyEnabled true\n useProguard true\n proguardFiles getDefaultProguardFile(\'proguard-android.txt\'), \'proguard-rules.pro\'\n } \n }\n}\n
Run Code Online (Sandbox Code Playgroud)\nIf you do not require code obfuscation or minification in your Release APK, you can simply disable this feature altogether for the Android code. The required steps are mentioned below.
\nOpen up your Flutter Project in your preferred IDE
\nOpen the \xe2\x80\x9cbuild.gradle\xe2\x80\x9d file in the \xe2\x80\x9c/android/app\xe2\x80\x9d folder.
\nFind the \xe2\x80\x9candroid\xe2\x80\x9d block, within it locate the \xe2\x80\x9cbuildTypes\xe2\x80\x9d and \xe2\x80\x9crelease\xe2\x80\x9d blocks.
\nAdd the following mentioned code to disable code modification.
\nandroid {\n compileSdkVersion 29\n sourceSets {\n main.java.srcDirs += \'src/main/kotlin\'\n }\n\n lintOptions {\n disable \'InvalidPackage\'\n }\n\n defaultConfig {\n // Android configurations are usually here\n }\n // Signing Configurations are usually here\n buildTypes {\n release {\n signingConfig signingConfigs.debug\n\n // add these code lines\n minifyEnabled false\n shrinkResources false\n } \n }\n}\n
Run Code Online (Sandbox Code Playgroud)\nPerform a Flutter clean task and build your Release APK. Your issue should be resolved now.
\nHappy coding :D
\n 归档时间: |
|
查看次数: |
733 次 |
最近记录: |