phonegap app crashes after installing plugin - ios

After the fix i found for my previous issue: phonegap-cordova-3-4-clean-build-gets-apple-mach-linker-error
So now, if I make a blank project
$ cordova create hello com.example.hello HelloWorld
$ cordova platform add ios
$ cordova build ios
Now I need to do follow these instructions previous question
After that everything works fine.
BUT now I'm gonna install an plugin (doesn't matter what plugin).
For now i choose the logger (org.apache.cordova.console)
$ cordova plugin add org.apache.cordova.console
Now if i build and run the app. It crashes on startup.
see: screenshot
I enabled on Zombie Objects in xcode.
Even if I install previous versions of phonegap(cordova). I still need to do all these steps. Before I just create, add platform, build and run and it was done.
Nothing is working anymore, please helpe me out here. It's really annoying.
EDIT: If i comment the line console.log('Received Event: ' + id); in js/index.js the app will start, but if I call console.log it crashes.

objc_msgSend causes EXC_BAD_ACCESS with plugins on arm64
So i found why this happened:
I needed to replace in the fie ios/CordovaLib/Classes/CDVCommandQueue.m
objc_msgSend(obj, normalSelector, command);
in
((void (*)(id, SEL, id))objc_msgSend)(obj, normalSelector, command);
now everything works fine again.
source

I found something. If I build for ios. the js (console-via-logger.js) is doing the id wrong
screenshot
If I change
cordova.define("org.apache.cordova.console.console", function(require, exports, module) { /*
to
cordova.define("org.apache.cordova.console", function(require, exports, module) { /*
it works.
Has this something todo with me or cordova?
cordova -v: 3.4.0-0.1.3
npm -v: 1.4.5

Related

ionic Cordova platform add iOS fails

I'm trying to run the command
ionic cordova platform add ios#6.2.0
everything is updated, my versions are:
ionic - 6.17.1
npm - 7.21.1
node - 16.9.1
pod - 1.11.2
I have the last version of Xcode (13) just released 2 days ago. When running that command I get:
--save flag or autosave detected
Saving ios#~6.2.0 into config.xml file ...
Update IOS build setting SWIFT_OBJC_BRIDGING_HEADER to: "$(PROJECT_DIR)/$(PROJECT_NAME)/Bridging-Header.h" for build configuration Debug
Update IOS build setting SWIFT_OBJC_BRIDGING_HEADER to: "$(PROJECT_DIR)/$(PROJECT_NAME)/Bridging-Header.h" for build configuration Release
Update IOS build setting ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to: YES for build configuration Debug
Use Swift language version 5
Update IOS build setting SWIFT_OPTIMIZATION_LEVEL to: -Onone for build configuration Debug
Update IOS build setting ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to: YES for build configuration Release
Use Swift language version 5
[ERROR] An error occurred while running subprocess cordova.
cordova platform add ios#6.2.0 exited with exit code 1.
After reading every post I found, I included on my config.xml:
<preference name="UseSwiftLanguageVersion" value="5" />
Thinking I might had a non-supported Xcode version, I downgraded Xcode to v12.5.1, selected it on Xcode -> Preferences -> Locations, then restarted all terminals and processes, restarted the Mac, but still not working.
I tried to update CocoaPods with the commands:
pod install
pod setup
And still nothing was working so I decided to run the command
ionic cordova prepare ios
to see if I could go on anyway but got this error:
[error] Error: Cannot find module '#ionic/angular-toolkit/package.json'
Require stack:
- /usr/local/lib/node_modules/#angular/cli/node_modules/#angular-devkit/architect/node/node-modules-architect-host.js
- /usr/local/lib/node_modules/#angular/cli/node_modules/#angular-devkit/architect/node/index.js
- /usr/local/lib/node_modules/#angular/cli/models/architect-command.js
- /usr/local/lib/node_modules/#angular/cli/commands/run-impl.js
- /usr/local/lib/node_modules/#angular/cli/node_modules/#angular-devkit/schematics/tools/export-ref.js
- /usr/local/lib/node_modules/#angular/cli/node_modules/#angular-devkit/schematics/tools/index.js
- /usr/local/lib/node_modules/#angular/cli/utilities/json-schema.js
- /usr/local/lib/node_modules/#angular/cli/models/command-runner.js
- /usr/local/lib/node_modules/#angular/cli/lib/cli/index.js
- /usr/local/lib/node_modules/#angular/cli/lib/init.js
- /usr/local/lib/node_modules/#angular/cli/bin/ng
And yes, if you are wondering every time I updated or ran a command I did also deleted the platforms, plugins, node_modules and www folder, but anything is happening.
Coincidentally today I had to migrate a Cordova project to iOS 6.2 due to Apple's usual annoyance in updating hours before and leaving everything obsolete (the best in backward compatibility, it should be noted).
I'll share with you the short commands that work with cordova without digging too much:
0-) sudo npm install cordova-ios#latest
1-) sudo ionic cordova platform remove ios
2-) sudo ionic cordova platform add ios#latest // don't specify version, the last one already assumes this
3-) sudo chmod -R 777 platforms/ios // usually, I must enable read and write permissions, things on my computer but with that I ensure full permission.
4-) sudo ionic cordova build ios
5-) You open XCode again in the generated project and voila, you can compile it.
If step #1 fails you, run it 2 times (for some reason I always have to run it 2 times to get it done).
Best regards.
Well, at the end, after 15h of work and a lot of searching, it was all fixed by downgrading my Node version from 16.9.1 to 14.17.5.
I didn't know that this new Node version is not supported by Angular jet, but I found out, and you can too by just running the command
ng -v
which says at the end
Warning: The current version of Node (16.9.1) is not supported by Angular.
to downgrade your Node version you can follow the instructions on this post:
How to downgrade Node version
You can also see all the Node versions available here:
https://nodejs.org/es/about/releases/
Since Angular is a step behind of Node I suggest to download an Active version and not a current one.

ionic 2 error cordova not available

I am trying to use the cordova GooglePlus plugin in a new ionic 2 project (latest ionic2 version) but I always run into errors regarding cordova.
The plugin is properly installed and shows up in the plugin folder.
One approach I tried is this:
import { GooglePlus } from "ionic-native";
and then
GooglePlus.login().then(...)
The login method executes but always throws an error saying "cordova_not_available"
I want to test the app with ionic serve on my windows system first before deploying it to my android phone.
How can I make cordova available in the localhost server? From searching I understand that cordova.js is generated and always included in the deploy package for the device.
Another approach I tried is using
window.plugins.googleplus.login(...)
But this approach does not go through the typescript compiler who does not know anything about a plugins property on the windows object.
How can I fix this?
If you want the plugin to work for the browser you should add platform browser and run it:
ionic cordova platform add browser
and run it:
ionic cordova run browser
instead of ionic serve.
This error usually occurs when you're running the app in chrome using ionic serve which is normal as in the browser cordova native components are not there but also occur on emulator and devices when an ionic native plugin that you're using was nod added, even if you have added the ionic plugin for it.
For instance if you are using native Toast
then you need to add proper ionic dependencies:
ionic plugin add cordova-plugin-x-toast --save
but you also need to add cordova dependencies:
cordova plugin add cordova-plugin-x-toast --save
If you forget to add the later cordova plugin you'll get an error like:
Runtime Error Uncaught(in promise): cordova_not_available
Which can be tricky to find the cause.
Once you have added ionic and cordova dependencies you should be able to use it.
Make sure you import it:
import { Toast } from 'ionic-native';
inject Platform in constructor:
constructor(public navCtrl: NavController, private platform: Platform) {...
then use the native item:
this.platform.ready().then(() =>
Toast.show("Successfull", '5000', 'center')
.subscribe(
toast => {
console.log(toast);
}
));
Using ionic serve disables all the cordova plugins, because it is not running on a device.
Rather use ionic cordova run android
This will start an android emulator that should allow all the cordova plugins to function
I have also come across the second approach, but the syntax then has to be windows['plugins'].googleplus.login(...)
Sometimes using ionic cordova run browser is not the best option, since it takes a long time for it to compile your changes.
In my case, what was causing the issue was the FCM plugin. It cannot run on the browser, if I use ionic serve. Since my code was inside app.component.ts, it was easy for me to get around the problem. I simply used the following line:
if (platform.is('cordova'))
{ this.fcmx.onTokenRefresh().subscribe(token => {
this.pushNoti.storeNewToken(token); }); }
Using platform.is('cordova'), you can prevent the code causing trouble to run on the browser.
Simply Run after attaching android device
ionic cordova run android
make sure you correct google map key

Phonegap Facebook plugin not responding

I'm trying to get the Phonegap Facebook plugin to work, but no errors occur and the plugin's login() function just doesn't do anything (it's being called, but doesn't do anything).
Whenever I try to install the plugin in the Cordova CLI, I get a Plugin already installed notice. I've added the plugin files manually, by adding FacebookConnectPlugin.h and FacebookConnectPlugin.m in the plugins folder. I've added the FacebookSDK.framework to the frameworks folder. However, when I open my app and tap on the login button (which correctly calls the function), nothing happens. The activity console in Xcode doesn't show any errors and no action is performed.
My JS code looks like this:
var login = function () {
if (!window.cordova) {
var appId = prompt("<MyAppId>", "");
facebookConnectPlugin.browserInit(appId);
}
facebookConnectPlugin.login( ["email"],
function (response) { alert(JSON.stringify(response)) },
function (response) { alert(JSON.stringify(response)) });
}
$('.login-btn').click(function() {
login();
});
What step am I missing to make this work? The plugin can be found here.
Also, when I start the app the activity console shows the following info:
2015-10-20 19:58:38.586 MyApp[5143:2355309] Apache Cordova native platform version 3.8.0 is starting.
2015-10-20 19:58:38.590 MyApp[5143:2355309] Multi-tasking -> Device: YES, App: YES
2015-10-20 19:58:38.595 MyApp[5143:2355309] Unlimited access to network resources
2015-10-20 19:58:39.033 MyApp[5143:2355309] Resetting plugins due to page load.
2015-10-20 19:58:39.711 MyApp[5143:2355309] Finished load of: file:///var/mobile/Containers/Bundle/Application/365E079A-56F7-4874-9914-182A57D6DFED/Qwest.app/www/index.html
Adding plugins manually in cordova usually leads to bad things, especially in the future if you ever want to update. For now I would try removing and adding the plugin:
cordova plugin rm phonegap-facebook-plugin
cordova plugin -d add -d plugin add /path/to/cloned/phonegap-facebook-plugin --variable APP_ID="123456789" --variable APP_NAME="myApplication"
(You did follow the instructions at https://github.com/Wizcorp/phonegap-facebook-plugin/blob/master/platforms/ios/README.md on how to install the plugin and cloned it to a different directory) See if that works, if not go with the more nuclear option of adding and removing the platform.
cordova platform rm ios
cordova platform add ios
This is sometimes required, but should only be performed if you have made no changes to the XCode project.
Also the plugin has been forked and https://github.com/jeduan/cordova-plugin-facebook4 which uses the Facebook4 SDK rather than Facebook3 SDK, as well it requires less fiddling to get the IOS plugin to work. It is api compatible so it should just work.

Cordova not recognizing plugins after updating them

I updated all the plugins I was using in cordova using the remove and add method.
cordova plugin rm org.apache.cordova.device
cordova plugin add org.apache.cordova.device
....
I then prepare and build
cordova prepare ios
cordova build ios
I test the app on the simulator and I get:
ERROR: Plugin 'Device' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml
Why is this happening? I was under the impression that the command line was going to update everything automatically, what am I missing?
Before the rm and add everything was working fine.
Thank you for your time.
If anyone stumbles on this, I found the solution.
After updating, adding or removing plugins, you should always do this:
cordova platform rm ios
cordova platform add ios
That will fix any issue.

Phonegap 3.3.0 cannot add any plugin

I am trying to add barcodescanner plugin to an Phonegap 3.3.0 project.
Steps to reproduce:
$ cordova create app de.app.name "app-name"
$ cd app
$ cordova platform add ios
$ cordova plugin add com.phonegap.plugins.barcodescanner
Fetching plugin from "com.phonegap.plugins.barcodescanner"...
Starting installation of "com.phonegap.plugins.barcodescanner" for ios
Error during processing of action! Attempting to revert...
/usr/local/lib/node_modules/cordova/node_modules/q/q.js:126
throw e;
^
Error: Uh oh!
cannot find "/path/app/plugins/com.phonegap.plugins.barcodescanner/src/ios/CDVBarcodeScanner.mm" ios <source-file>
at module.exports.source-file.install (/usr/local/lib/node_modules/cordova/node_modules/plugman/src/platforms/ios.js:44:48)
at Object.ActionStack.process (/usr/local/lib/node_modules/cordova/node_modules/plugman/src/util/action-stack.js:46:25)
at handleInstall (/usr/local/lib/node_modules/cordova/node_modules/plugman/src/install.js:380:20)
at /usr/local/lib/node_modules/cordova/node_modules/plugman/src/install.js:331:20
at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/plugman/node_modules/q/q.js:798:54)
at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/plugman/node_modules/q/q.js:827:30)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/plugman/node_modules/q/q.js:760:13)
at /usr/local/lib/node_modules/cordova/node_modules/plugman/node_modules/q/q.js:574:44
at flush (/usr/local/lib/node_modules/cordova/node_modules/plugman/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:415:13)
If I use the github link I get the same error in short:
$ cordova plugin add https://github.com/phonegap-build/BarcodeScanner
Fetching plugin from "https://github.com/phonegap-build/BarcodeScanner"...
Starting installation of "com.phonegap.plugins.barcodescanner" for ios
Preparing ios project
/usr/local/lib/node_modules/cordova/node_modules/q/q.js:126
throw e;
^
SyntaxError: Unexpected token
Also I get the same for the original version of the plugin:
$ cordova plugin add https://github.com/wildabeast/BarcodeScanner
I found a thread about a problem in phonegap 3.0.0 but https://github.com/jonathannaguin/BarcodeScanner still gives me the same error.
I guess the importen part is cannot find "/path/app/plugins/com.phonegap.plugins.barcodescanner/src/ios/CDVBarcodeScanner.mm" ios. Any thoughts how I can dig deeper into this and make it work?
Update
I got the same problem with org.apache.cordova.console. Also if I use phonegap local plugin add ....
I notice that www/config.xml and platforms/ios/www/config.xml are broken. There is some binary empty space at the end of the file that can be removed. There might be something messed up with phonegap itself.
Problem is caused by the directory I am in. If I do cd ~ and run the same command it just works!
I was in \Volumes/www with is a samba share mounted over smbfs.

Resources