Ionic 3- Android, cordova_not_available

Hello!
I’m having problems with the native camera plugin in an android device (in iOS devices is working fine). When trying to open the Camera or the PhotoLibrary, I received the following error:

[18:09:05] console.warn: Native: tried calling Camera.getPicture, but Cordova is not available. Make sure to include
cordova.js or run in a device/simulator
[18:09:05] console.error: error con la imagen: cordova_not_available
[18:09:11] console.warn: Native: tried calling Camera.getPicture, but Cordova is not available. Make sure to include
cordova.js or run in a device/simulator
[18:09:11] console.error: error con la imagen: cordova_not_available

I have tested in both device and emulator with the same result.

Here is my plugin list and ionic environment.

ionic cordova plugin

cordova plugin ls
cordova-plugin-camera 4.0.2 “Camera”
cordova-plugin-device 2.0.1 “Device”
cordova-plugin-file 6.0.1 “File”
cordova-plugin-file-transfer 1.7.1 “File Transfer”
cordova-plugin-filepath 1.0.2 “FilePath”
cordova-plugin-ionic-keyboard 2.0.5 “cordova-plugin-ionic-keyboard”
cordova-plugin-ionic-webview 1.1.16 “cordova-plugin-ionic-webview”
cordova-plugin-splashscreen 5.0.2 “Splashscreen”
cordova-plugin-statusbar 2.4.1 “StatusBar”
cordova-plugin-whitelist 1.3.3 “Whitelist”
cordova-sqlite-storage 2.3.0 “Cordova sqlite storage plugin”

ionic info

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 8.0.0 

local packages:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : android 7.0.0 browser 5.0.3 ios 4.5.4
Ionic Framework    : ionic-angular 3.9.2

System:

Android SDK Tools : 26.1.1
ios-deploy        : 1.9.2 
Node              : v6.11.5
npm               : 5.6.0 
OS                : macOS High Sierra
Xcode             : Xcode 9.2 Build version 9C40b 

I’ve tried uninstalling the plugins, the platform and reinstalling all over again.

Any suggestions, please?

In the console tab of the devtools, type cordova and/or window.cordova and/or navigator.camera. Does this return something? Does it include all the plugins as expected, including the Camera one?

Is cordova.js included in the source code of index.html in the dev tools Elements tab? Are the plugins you expect there (the ones you have installed)?

Hi,
here you have the results when running with the following command:

ionic cordova run browser --consolelogs -l --info --debug

cordova:

cordova
{define: ƒ, require: ƒ, version: “5.0.3”, platformVersion: “5.0.3”, platformId: “browser”, …}

window.cordova:

{define: ƒ, require: ƒ, version: “5.0.3”, platformVersion: “5.0.3”, platformId: “browser”, …}
addConstructor
:
ƒ (func)
addDocumentEventHandler
:
ƒ (event)
addStickyDocumentEventHandler
:
ƒ (event)
addWindowEventHandler
:
ƒ (event)
callbackError
:
ƒ (callbackId, args)
callbackFromNative
:
ƒ (callbackId, isSuccess, status, args, keepCallback)
callbackId
:
1149496489
callbackStatus
:
{NO_RESULT: 0, OK: 1, CLASS_NOT_FOUND_EXCEPTION: 2, ILLEGAL_ACCESS_EXCEPTION: 3, INSTANTIATION_EXCEPTION: 4, …}
callbackSuccess
:
ƒ (callbackId, args)
callbacks
:
{}
commandProxy
:
{add: ƒ, remove: ƒ, get: ƒ}
define
:
ƒ (id, factory)
exec
:
ƒ (success, fail, service, action, args)
file
:
{applicationDirectory: “http://localhost:8000/”, applicationStorageDirectory: null, dataDirectory: “filesystem:file:///persistent/”, cacheDirectory: “filesystem:file:///temporary/”, externalApplicationStorageDirectory: null, …}
fireDocumentEvent
:
ƒ (type, data, bNoDetach)
fireWindowEvent
:
ƒ (type, data)
getOriginalHandlers
:
ƒ ()
platformId
:
“browser”
platformVersion
:
“5.0.3”
removeDocumentEventHandler
:
ƒ (event)
removeWindowEventHandler
:
ƒ (event)
require
:
ƒ (id)
version
:
“5.0.3”
proto
:
Object

navigator.camera:

navigator.camera
{DestinationType: {…}, EncodingType: {…}, MediaType: {…}, PictureSourceType: {…}, PopoverArrowDirection: {…}, …}DestinationType: {DATA_URL: 0, FILE_URI: 1, NATIVE_URI: 2}Direction: {BACK: 0, FRONT: 1}EncodingType: {JPEG: 0, PNG: 1}MediaType: {PICTURE: 0, VIDEO: 1, ALLMEDIA: 2}PictureSourceType: {PHOTOLIBRARY: 0, CAMERA: 1, SAVEDPHOTOALBUM: 2}PopoverArrowDirection: {ARROW_UP: 1, ARROW_DOWN: 2, ARROW_LEFT: 4, ARROW_RIGHT: 8, ARROW_ANY: 15}cleanup: ƒ (successCallback, errorCallback)getPicture: ƒ (successCallback, errorCallback, options)proto: Object

It’s weird since the plugin is working fine when deploying or testing in an iOS device/simulator but it’s not working at all on any type of Android.

Thanks

Hi,

browsing other related topics it seems it is a problem when using the --livereload feature on Android. I’ve tried running the app without this flag and the cordova.js library is injected.

Thanks

1 Like

Yeah, what happens for the browser platform is pretty irrelevant to Android anyway.

I (falsely) assumed you knew how to remote debug when running on the device, sorry.
For next time: Remote Debug your Ionic App · ionic.zone