How to configure cordova installed plugins in Android Studio - android

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.

Related

Error : Unable to prepare project

While trying to do a release using the following command:
code-push release-cordova myApp android
I'm getting the following error in the terminal:
Running "cordova prepare" command:
[Error] Unable to prepare project. Please ensure that this is a Cordova project and that platform "android" was added with "cordova platform add android"
Any one knows what might be wrong? The project is a cordova project created using the command:
cordova create myApp
And also has android platform added.
UPDATE :
Running cordova prepare android --verbose returns the following output :
Executing "before_prepare" hook for all plugins.
Searching PlatformJson files for differences between project vs. platform installed plugins
No differences found between project and android platform. Continuing...
Generating config.xml from defaults for platform "android"
Wrote out Android application name to "HelloCordova"
Wrote out Android package name to "io.cordova.hellocordova"
This app does not have launcher icons defined
updated project successfully
Executing "after_prepare" hook for all plugins.
Make sure your Nodejs is the last version.
code-push-cli required "child_process"
That error indicates that the current working directory didn't represent the root of a Cordova project at the time that you ran the release-cordova command. Can you make sure that you CD into the directory that contains the www, platforms, plugins, etc. directories, and then run the release-cordova command? That should do the trick for you

Can't install cordova plugin

I am trying to use AdMob in my app.
I am using this : https://github.com/appfeel/admob-google-cordova
Following this tutorial : https://github.com/appfeel/admob-google-demo
I have downloaded the zip. Run it on device and got the following error message :
cordova-admob plugin not ready. Are you in desktop browser ? It won't
work...
I investigated and found out the plugin isn't even installed. So I tried installing it via the CLI like so :
cordova plugin add cordova-admob
And I get the following messages :
cordova-admob: Warning, could not copy necessary files for angular
browser platform.
cordova-admob: Please ensure 'www/lib/angular-admob/angular-admob.js'
exists (you can copy it from 'plugins/cordova-admob/angular-admob.js')
I tried copying it from there and created a folder at the location www/lib/angular-admob, as it wasn't there but I get build errors.
Anyone come across this ? I've been at this for weeks, on and off, trying to get the adMob to work for PhoneGap/Cordova but I keep getting different errors. I have tried this plugin :
https://github.com/floatinghotpot/cordova-admob-pro
That one worked great on the android emulator, but not when I, both, served it to my device via the phonegap desktop app and served it from CLI to my device.
Here's the error I am getting now :
When creating the project from scratch and following these steps :
cordova create AdMobTest || cordova platform add android || cordova
plugin add cordova-admob || creating empty lib folder inside my
project www folder || cordova plugin remove cordova-admob || cordova
plugin add cordova-admob || cordova prepare android || cordova compile
android || cordova run android --device –
I'm now getting this error :
Just create a EMPTY folder with the name lib inside your project www folder:
Clean your project by removing the current version of the plugin with the cordova cli. Remeber to use the cli inside your project root folder:
Add the plugin with the cordova cli:
Have a nice day!
EDIT : Your error occur inside processDebugResources so it´s nothing about the plugin. To avoid this problem change your target Android SDK to an prior version.
Here is one answered question which adress this problem: Execution failed app:processDebugResources Android Studio

Cant get rid of this error. I'm trying to build a mobile first app using cordova. Error: You must be in a MobileFirst project to execute this command

Cant seem to follow the tutorials for building apps with Mobile first and cordova.
i used mfp cordova create to create an app and named it Idealaketest.
Enter name of app: Idealaketest
Enter the package ID: com.ibm.Idealaketest
have progressed on as far as the code below.
Please help with a workaround or a link to a page with appropriate tuts.
I'm following this at the moment.
https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/hello-world/integrating-mfpf-sdk-in-cordova-applications/
D:\Mobilefirst_workspaces\workspace3>mfp cordova create
? Enter name of app: Idealaketest
? Enter the package ID: com.ibm.Idealaketest
? Enter the app version: 1.0.0
? Select platforms to be supported by your app: android
? The following plugins will be automatically added to your app:
cordova-plugin-mfp
org.apache.cordova.device
org.apache.cordova.dialogs
org.apache.cordova.geolocation
org.apache.cordova.globalization
org.apache.cordova.inappbrowser
org.apache.cordova.network-information
Please press enter to continue...
? Select additional plugins you would like to add:
? Enter a path to an app template to be added: cordova-hello-world-mfp
Embedded Cordova Command: cordova create "Idealaketest" "com.ibm.Idealaketest" "
Idealaketest" --copy-from="C:\Program Files\IBM\MobileFirst-CLI\mobilefirst-cli\
node_modules\cordovacmd\cordova\templates\cordova-hello-world-mfp"
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms\android
Package: com.ibm.Idealaketest
Name: Idealaketest
Android target: android-22
Copying template files...
Project successfully created.
Adding "cordova-plugin-mfp"
Installing "cordova-plugin-mfp" for android
Installing "org.apache.cordova.device" for android
Installing "org.apache.cordova.dialogs" for android
Installing "org.apache.cordova.geolocation" for android
Installing "org.apache.cordova.globalization" for android
Installing "org.apache.cordova.inappbrowser" for android
Installing "org.apache.cordova.network-information" for android
Plugin install completed
CordovaApp.java was renamed to MainActivity.original, if you made manual changes
to CordovaApp.java, you need to merge them with the current main activity file,
CordovaApp.java, in /platforms/android/src/[package_path]
Plugin "cordova-plugin-mfp" added successfully.
Preparing for push...
MFP App settings not found, configuring..
Embedded Cordova Command: cordova prepare android
D:\Mobilefirst_workspaces\workspace3\Idealaketest\mobilefirst\com_ibm_Idealakete
st-android-1.0.0.wlapp has been built.
Push Completed Successfully.
MFP Cordova project created successfully.
D:\Mobilefirst_workspaces\workspace3>mfp start
Cannot find the server configuration. Creating a new MobileFirst test server.
The development server is being created.
The development server has been successfully created with the following informat
ion:
Server Directory: C:/Users/guest/.ibm/mobilefirst/7.1.0.00.20160307-2032/server
/
URL: http://localhost:10080/
Error: You must be in a MobileFirst project to execute this command.
D:\Mobilefirst_workspaces\workspace3>cd Idealaketest
D:\Mobilefirst_workspaces\workspace3\Idealaketest>mfp start
Error: You must be in a MobileFirst project to execute this command.
D:\Mobilefirst_workspaces\workspace3\Idealaketest>mfp cordova preview
? Select how to preview your app: browser: Simple browser rendering
Preparing for push...
Verifying Server Configuration...
Error: There are no runtimes available on this server.
Run 'mfp help intro' for guidance.
Error: error code: 305
Error: There was an error with the server.
Error: MASTERPUSHSERVERFAILED
Error: Push has failed
You didn't a project...
Create the project:
mfp create myproj
cd myproj
mfp start
Create the Cordova project:
cd ..
mfp cordova create myapp
cd myapp
mfp cordova platform add android
mfp push
mfp cordova run

Debugging custom CordovaPlugin

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.

phonegap - navigator.connection.type not defined

I am trying to check for an established network connection through the phonegap/cordova API, but alas, it is not working.
I added the plugin as explained on the cordova documentation, and phonegap local plugin list gives [phonegap] org.apache.cordova.network-information.
However, simply calling
document.addEventListener("deviceready", function () {
alert(Object.keys(navigator.connection));
}, false);
results on my phone (Android 4.0.4) always returning 0 and running on an emulator with Android 4.4.2 logs into LogCat that navigator.connection is undefined. In fact, on both machines alert(Object.keys(navigator)); never shows the connection key.
Any solution?
Phonegap with Cordova 3.3.0
When you install the plugin it copies files to www/plugins and updates android.json
then when you build the project, the build copies the java to platforms/android/src/... and the js files to platforms\android\assets\www\plugins (and does any customisation defined in plugin.xml)
At multiple occasions I saw android.json not correctly updated and javascript files not copied. Removing and re-installing plugins solved the problem for me.
If you did not perform manual customisations to the platforms/android folder, I think the easiest way to clean your project would be to empty the /plugins folder and the platforms folder and then re-install all the plugins you need.
I had the same issue and found I had to run "cordova build" and then the status was returned correctly.
BEWARE
When I run cordova build, it appears to take everything in my ~/app/www directory and overried everything in app/platforms/android/assets/www/
My "install process" is as follows:
cordova create app com.app "App"
cd app
cordova platform add android
cordova plugin add org.apache.cordova.network-information
cordova plugin add org.apache.cordova.camera
cordova plugin add org.apache.cordova.geolocation
cordova build
I can then do code changes in app/www and when happy, 'deploy' it using 'cordova build' (which seems to always copy the files to app/platforms/android/assets/www/.
If I add another plugin using: (for example)
cordova plugin add org.apache.cordova.file
then I need to run
cordova build
to have it work.
I hope this helps
(I am using cordova 3.3.1-0.1.2 )

Categories

Resources