Debugging custom CordovaPlugin - android

This is my first question here.
I am using Cordova 3.4.0-0.1.3 and would like to write a custom Android plugin. After some tutorials, I have managed to call my custom plugin from my Cordova app by executing "cordova run android" command. The app starts and with my remote debug console I can see my own "Hello world" message from my own Cordova plugin.
The next thing I would like to do is debugging my plugin in Eclipse.
The first thing I tried was to launch the app from Eclipse by executing the AndroidManifest.xml located in the /cordovaproject/platforms/android/ folder.
After the app was launched, the following javascript errors i get in my remote console:
deviceready has not fired after 5 seconds. cordova.js:1128
Channel not fired: onNativeReady cordova.js:1121
Channel not fired: onPluginsReady cordova.js:1121
Channel not fired: onCordovaReady cordova.js:1121
It look likes there are Cordova components that aren't loading when you directly run the app in Eclipse.
This error does not occur when I deploy the app with "cordova run android".
My question is:
How can I properly run/debug my Cordova plugin in Eclipse?

I have fixed my problem. The problem was that I added the android plugin by "Import existing project".
The correct way to add the Cordova android project in Eclipse is to create an new "Android Application project" with existing sources.
When you do this, the referenced CordovaLib project is also found by Eclipse.

Related

Cannot find module "./app.module.ngfactory"

I updated Ionic from RC1 to RC3 following the documentation instructions and after that I can't run my app properly in Android using ionic run android or ionic build android. Previewing with ionic serve and .apk build works properly, but when I run the app in my device or in an emulator, it shows the splashscreen and after a blank WebView. When I debug via chrome://inspect, it shows in console the following error:
main.js:7 Uncaught Error: Cannot find module "./app.module.ngfactory"
I made a backup of the project folder before the update, when my app was working properly, and the code is the same (no changes during the upgrade), and the app.module.ts, main.dev.ts and main.prod.ts seems fine.
I tried remove .tmp and node-modules folder and run npm install again, but the error persists.
check this out: https://forum.ionicframework.com/t/cannot-find-module-app-module-ngfactory/72832/3
The newest version of typescript caused the error for me.
In my case I had an import problem with NGTranslate.
See here Ionic Forum Post

Unable to use cordova plugin from github in Intel XDK

I am trying to add cordova plugin at https://github.com/dbaq/cordova-plugin-contacts-phone-numbers in Intel XDK thrid-party plugins. I have given plugin id at com.dbaq.cordova.contactsPhoneNumbers and Repo URl as https://github.com/dbaq/cordova-plugin-contacts-phone-numbers.git but even after bulding the whole project for android, when I use navigator.contactsPhoneNumbers.list after deviceReady event, I get "Cannot read property 'list' of undefined". Is there anything, I am missing. Same thing happens with other cordova plugins located on Github like Cordova CallNumberPlugin located at github.com/Rohfosho/CordovaCallNumberPlugin.
Note that, I have tested the build on android phone but still no success.

Adding Dialogs Plugin to phonegap project prevents deviceReady from Firing

I started using phonegap but as a beginner i ran into many problems.
one of the latest is problem with adding plugins
I added plugin of dialogs
org.apache.cordova.dialogs
with command line tool and it added successfully . but after running application in android emulator it never fire deviceReady Event. before adding plugin it was OK.
as a note I should say I installed older versions of plugin but they didn't work either !
Well I found the answer , I was building my project with phonegap but installed cordova plugins , I create a new project with command
cordova create project [folder name] [namespace "like com.example.appname"]
[project name]
and it worked correctly after that and I installed plugins as usual .

How to configure cordova installed plugins in Android Studio

I have completed the following steps:
I currently have a cordova created project using the Cordova CLI.
I have installed plugins using plugin add *
My project runs successfully as do the plugins when I cordova emulate android
Now I wish to go down the SDK route (no longer the CLI) to make specific changes to the Android platform files. I have:
Created a new Android Studio project
Imported the output from platforms/android directory
Added dependency to CordovaLib in platforms/android directory
I can now build successfully and run the app on an emulator but none of my previously installed plugins from the CLI are running. Instead the following errors are logged:
"deviceready has not fired after 5 seconds.", source: file:///android_asset/www/cordova.js (1154)
"Channel not fired: onPluginsReady", source: file:///android_asset/www/cordova.js (1147)
"Channel not fired: onCordovaReady", source: file:///android_asset/www/cordova.js (1147)
"Channel not fired: onDOMContentLoaded", source: file:///android_asset/www/cordova.js (1147)
Can anyone explain how to configure cordova installed plugins from the CLI and use them in the SDK route in Android Studio?
Thanks
Plugins are accessible only after the deviceReady event. Have you defined the device ready in the index.html ? can you please provide the code you used?
no need of creating the android studio project.
directly open the android studio and import platforms/android project.
in the project you will get the plugin files in src folder with respective plugin package names.
their you can make specific changes.

How to Build and run the cordova project with eclipse and run project for android

I have created the project with cordova CLI but i do not know where i need to change and how to run the cordova android project with eclipse for each platform. Thanks for helping
Before run the android project inside your Cordova Project you should know these things.
If you are making any changes in the Cordova Project then first you need to prepare the cordova. use the command cordova prepare
Then it changed in your config.xml (for android) automatic as you added or any changes you made. Do not make any change in your android project which exist inside your Cordova project. You can only make change inside the www folder of your Cordova project. And after made changed you need to make cordova prepare every time.
After prepare the cordova you can run the android project on device or emulator. For this you make sure you have made the path of android sdk for platforms-tools and tools in your environment system. If you not configure this path and add this two path in system environment .
Now run the android project on device use command cordova run android and run on emulator use this command cordova emulate android.
And if want to run on eclipse then you should import this android project of your workspace in eclipse. But if you again made changes in your cordova project then need to delete and again import the android project this switching happened every time so better to run through CLI.
I hope you got all things
Sunil's answer is good. I would like to add logging using Android Debug Bridge(adb).You may want to run:
adb logcat on a seperate shell window for logs after running cordova run android you need when you run into errors.This will produce huge logs, so I would recommend using:
adb logcat|grep Cordova

Categories

Resources