Hello,
I'm encountering an error in android when using MVisaQRParser-1.6.0.jar and one of the
class throws security exception and it only occurs in android 14, when parsing QR code data as JSON.
Any help is appreciated.
Solved! Go to Solution
Error Logs:
Fatal Exception: java.lang.SecurityException: Writable dex file '/data/user/0/com.aeoncredit.android.aeonpay_consumer/cache/. ' is not allowed.
at dalvik.system.DexFile.openDexFileNative(DexFile.java)
at dalvik.system.DexFile.openDexFile(DexFile.java:406)
at dalvik.system.DexFile.<init>(DexFile.java:171)
at dalvik.system.DexFile.loadDex(DexFile.java:231)
at dalvik.system.DexFile.loadDex(DexFile.java:198)
at com.visa.mvisa.tlvparser.a.If.<clinit>(:10925)
at com.visa.mvisa.tlvparser.QrCodeParser.parseQrData(:25)
at com.visa.mvisa.tlvparser.QrCodeParser.parseQrDataAsJson(:47)
at kh.com.aeon.android.aeonpay.fragment.ScanQRFragment.handleResult(ScanQRFragment.java:109)
at me.dm7.barcodescanner.zxing.ZXingScannerView$1.run(ZXingScannerView.java:164)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:222)
at android.os.Looper.loop(Looper.java:314)
at android.app.ActivityThread.main(ActivityThread.java:8680)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:565)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
Hey @mVisa01,
It looks like you are encountering a security exception when using the `MVisaQRParser-1.6.0.jar` library on Android 14. The issue arises when attempting to parse QR code data as JSON, resulting in a fatal exception related to writable dex files.
Error Analysis:
The error log indicates a `SecurityException` with the following message:
```
Fatal Exception: java.lang.SecurityException: Writable dex file '/data/user/0/com.aeoncredit.android.aeonpay_consumer/cache/. ' is not allowed.
```
This typically points to restrictions on writing dex files to the application's cache directory, which seems to be enforced more strictly in Android 14.
Potential Solutions:
1. Update the Library:
Ensure you are using the latest version of the `MVisaQRParser` library. There may have been updates or patches to address compatibility issues with newer Android versions.
2. Modify Dex File Handling:
If you have access to the source code of the `MVisaQRParser` library, you might need to modify how dex files are handled. Specifically, avoid writing dex files to locations that are restricted by Android 14.
3. Use a Different Cache Directory:
Consider using a different directory for caching dex files, such as `getCodeCacheDir()` instead of `getCacheDir()`. The `getCodeCacheDir()` is specifically intended for storing compiled code, and may not have the same restrictions.
Example Code Adjustment:
If you have access to the part of the code where dex files are being handled, here is a conceptual example of how you might adjust the directory:
```java
// START
Context context = getContext();
File codeCacheDir = context.getCodeCacheDir();
String dexOutputPath = codeCacheDir.getAbsolutePath();
// Load dex file from the new cache directory
DexFile dexFile = DexFile.loadDex(dexFilePath, dexOutputPath, 0);
// END
```
Contact Visa Developer Support:
If you do not have access to modify the library or the above solutions do not resolve your issue, it is recommended to email Visa Developer Support at developer@visa.com for assistance. They may provide a version of the library compatible with Android 14 or offer alternative solutions.
Next Steps:
1. Check for Library Updates: Ensure you are using the latest version of `MVisaQRParser`.
2. Modify Dex File Handling: If possible, adjust the code to use `getCodeCacheDir()` for dex file storage.
3. Contact Support: Reach out to Visa Developer Support for further assistance.
If you need further help or if these solutions do not resolve the issue, please provide additional details or contact Visa Developer Support directly.
Hey @mVisa01,
It appears that you are encountering a security exception when using the MVisaQRParser-1.6.0.jar library in an Android 14 environment to parse QR code data as JSON. This issue may be due to increased security measures implemented in Android 14.
To address this problem, consider the following steps:
1. Check Permissions: Ensure that your application has all the necessary permissions declared in the AndroidManifest.xml file. This includes permissions for internet access, camera usage, and any other relevant permissions required by the library.
2. Library Updates: Verify if there is an updated version of the MVisaQRParser library that is compatible with Android 14. Libraries are often updated to address compatibility issues with new Android versions.
3. ProGuard Configuration: If you are using ProGuard or R8 for code obfuscation and optimization, ensure that the necessary rules are added to prevent the MVisaQRParser classes from being obfuscated. This can help avoid security exceptions related to reflection.
4. Review Security Changes in Android 14: Android 14 may have introduced new security features or restrictions that affect how your app interacts with external libraries. Review the Android 14 release notes and developer documentation to understand any changes that might impact your app.
5. Exception Handling: Implement robust exception handling around the QR code parsing logic to capture and log detailed information about the security exception. This can help you identify the root cause and adjust your code accordingly.
If the issue persists after trying these steps, consider reaching out to the support team or community forums for the MVisaQRParser library for further assistance. They may have more specific guidance or updates regarding compatibility with Android 14.
Always ensure that you are following best practices for security and data handling when working with QR code data and third-party libraries.