I'm having an issue that I found the cause but I couldn't manage to resolve.
My cordova app crashes on android 8.0.0. I did a logcat which revealed that the app is trying to access contacts.
The weird thing is I have no plugin for contacts nor using contacts in my app.
On the logcat, I have this error:
12-11 17:29:42.094 E/AndroidRuntime( 5609): java.lang.RuntimeException: java.lang.RuntimeException: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{6155964 5609:com.pierrickmartelliere.UPHAIRR/u0a210} (pid=5609, uid=10210) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
I tried everything, added
<config-file parent="/manifest" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
</config-file>
to my config.xml
, it adds well on AndroidManifest.xml when building but I still got the error.
I tried both tags uses-permission
and uses-permission-sdk
as stated here but without luck.
My version of cordova-android is 6.2.3
I also tried the cordova-plugin-permission, as in deviceready listener:
var permissions = cordova.plugins.permissions;
permissions.requestPermission(
permissions.READ_CONTACTS,
function(success) {},
function(error) {}
);
permissions.requestPermission(
permissions.WRITE_CONTACTS,
function(success) {},
function(error) {}
);
But nothing changed. The app crashes before the "deviceready" event is fired so I can do nothing on runtime.
As stated here, if I change the targetSdkVersion to lower than 23 (even 25), the crash disappears, but Im' not able to upload it to google play anymore since play console doesn't accept targetSdkVersion < 26.
Also, if I manually authorize contact access from app setting and I force stop and relaunch the app, it works. This is driving me crazy.
Some help on this would be very appreciated.
Thanks to anyone who will take the time to read or answer.