Today, I upgraded Cordova-CLI from version 3.5 to version 4.0. After this, I updated a project's platform support to the latest version of Android (since they get updated separately now).
Ever since then, I get this error showing up whenever I run cordova run android
, I get the following error:
Uncaught TypeError: Cannot set property connection of # which has only a getter at file:///android_asset/www/cordova.js:512
As a result, a lot of events in the app don't get run, causing that app to not work.
I started getting this after updating Cordova but only on very old Android phones. As a workaround I put a try/catch block around the contents of the function generating the error (clobber) in cordova.js :
function clobber(obj, key, value) { try { exports.replaceHookForTesting(obj, key); obj[key] = value; // Getters can only be overridden by getters. if (obj[key] !== value) { utils.defineGetter(obj, key, function() { return value; }); } } catch (e){ console.error('clobber error '+e+', obj='+JSON.stringify(obj)+', key='+JSON.stringify(key)+', value='+JSON.stringify(value)); } }
This obviously isn't the best fix but at least it lets the initialization complete and seems to not be affecting my app.
I met the same problem with Android cordova 3.6.4 got via CLI 4.1.2. I tried to merge two fixing of the issue:CB-7868. The first fixing can be saw with the link CB-7868,https://github.com/apache/cordova-js/pull/88. The second fixing is on the comment on CB-7868.
See *************
function clobber(obj, key, value) {
exports.replaceHookForTesting(obj, key);
obj[key] = value;
var needsProperty = false;
try { obj[key] = value; }
catch (e) { needsProperty = true; }
// Getters can only be overridden by getters.
if (obj[key] !== value) {
if (needsProperty || obj[key] !== value) {
utils.defineGetter(obj, key, function() { return value; }
);
With those two fixing. There is no error reported on Android API14(4.0) and API15(4.0.3). But, I didn't try if the related plugins can work not. It means I don't know if the fixing is right or not.
Also, I got cordova 3.7.0 via CLI 4.1.2 for IOS platform. I can see the fixing, https://github.com/apache/cordova-js/pull/88, has been applied on 3.7.0 JS. But, the function ,clobber, still haven't above fixing. Also, there is no available 3.7.0 for Android cordova. It is still 3.6.4 for Android platform.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With