I would be glad if we had an example on how cordova plugins should be wrapped for CocoonJS.
I'm trying to use the device-orientation plugin (compass) in a simple example but after the app has initialized, the navigator.compass.getCurrentHeading() returns an CompassError with the code:
Class not found
The class name cannot be resolved correctly, so probably something's wrong with the config.xml file.
After combining many sources, mine looks like this:
../www/config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="my.compass.html" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>HelloCordovaCompass</name>
<description>
A sample Apache Cordova application that displays the current compass heading after the deviceready event.
</description>
<author email="a#cordova.apache.org" href="http://cordova.io">
</author>
<content src="index.html" />
<access origin="*" />
<preference name="fullscreen" value="true" />
<preference name="orientation" value="landscape" />
<preference name="webviewbounce" value="true" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="Compass">
<param name="android-package" value="org.apache.cordova.deviceorientation.CompassListener" />
</feature>
</widget>
I've also tried to include compass as plugin:
<plugin name="Compass" value="org.apache.cordova.device-orientation" />
with no difference..
PS: The app works fine on plain Cordova.
[UPDATE]
Maybe the problem is here:
For this example I zipped the <project-name>/platforms/android/assets/www folder.
I'm not sure if this is enough for a Cordova plugin app, as the native code of the plugin is not included (CompassListener.java) and the only part that seems to work is actually its JavaScript interface (compass.js, CompassError.js, etc)..
On the other hand, If I try to zip the whole <project-name> directory as pointed out at the bottom of this tutorial, the CocoonJS Launcher crashes..
So, could at least someone confirm that the launcher can actually compile Cordova plugins?
If you want to use plugins you have to zip all Cordova project folders. Example:
cd ~/projects/ && zip -r -X hellococoonfull.zip helloCocoonJS && cd -
See the section "Using Cordova Plugins" of Getting Started with Cordova and CocoonJS guide.
[Update]
The CocoonJS Launcher is not ready for plugins yet. For using plugins you have to use de cloud compilation system.
Related
I tried to build an cordova based android aplication, with "cordova-plugin-media" installed because I want my apps to be able to record my voice.
after the build success with no errors, I run the apps, the recording is working, but my apps become stuck.
The Cordova project was exported from Construct 2, and I've already checked the media permission on export. I've built the apps using SDK via CMD, and also add the "plugin-media" here.
before I add the plugin, the apps run well, but it can't record.
That's why I re-build it with plugin-media attached.
From the result export, I only edit the config.xml on my Cordova project.
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.mawar.speak" version="1.0.0.2" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Speech Platformer</name>
<description>
Aplication Description.
</description>
<author email="dummy#gmail.com" href="http://cordova.io">
Node.js
</author>
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<!-- fullscreen -->
<preference name="Fullscreen" value="true" />
<!-- orientation -->
<preference name="Orientation" value="landscape" />
<engine name="android" spec="~7.1.1" />
</widget>
What I want is to make my apps run well with plugin-media installed. But when I build with it, it's stuck as I run it on my device.
Sorry for my bad english.
I upgraded today to the newest Cordova - 5.4.1. App on iOS kept working just fine but not on Android. All requests were returning 404 error, so I dig into the topic and found out that I need "cordova-plugin-whitelist". I installed it and added
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'">
to the header of index.html as well as <access origin="*" /><allow-navigation href="*"/> to config.xml
and now every request to external world is returning "net::ERR_NAME_NOT_RESOLVED"
In AndroidManifest.xml I have those two lines so I guess it's not a problem with Internet access.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
I went through many questions on SO related to cordova-plugin-whitelist but nothing seems to work
My config.xml
```
<?xml version='1.0' encoding='utf-8'?>
<widget id="app" version="1.1.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>app</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<allow-navigation href="*" />
<platform name="ios">...splash screens and icons</platform>
<platform name="android">...splash screens and icons</platform>
<icon src="resources/android/icon/drawable-xhdpi-icon.png" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="3000" />
<preference name="Orientation" value="default" />
<feature name="phonegap-parse-plugin">
<param name="id" value="org.apache.cordova.core.parseplugin" />
<param name="url" value="https://github.com/fastrde/phonegap-parse-plugin" />
</feature>
<feature name="Insomnia (prevent screen sleep)">
<param name="id" value="nl.x-services.plugins.insomnia" />
<param name="url" value="https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin.git" />
</feature>
<feature name="Toast">
<param name="id" value="cordova-plugin-x-toast" />
<param name="url" value="https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git" />
</feature>
<feature name="Cordova SMS Plugin">
<param name="id" value="com.cordova.plugins.sms" />
<param name="url" value="https://github.com/cordova-sms/cordova-sms-plugin.git" />
</feature>
<feature name="OpenTokCordovaPlugin">
<param name="id" value="com.tokbox.cordova.opentok" />
<param name="url" value="https://github.com/doxyme/cordova-plugin-opentok" />
</feature>
</widget>
```
I have no idea what the issue was but restarting device resolved it. Nothing related to the app, just the phone had difficulties with connecting to Internet even though it was connected to Wi-Fi and signal strength seemed to be on max.
In your app's 'config.xml', place only this:
<allow-navigation href="*" />
And remove what you added to your index.html header.
Then if it still doesn't work that means your problem is not related to the whitelist plugin.
I used this plugin in different Android projects and never had to do more than this to allow my app to communicate with the back-end.
Hope that helps!
We ran into a similar issue where we received the "Failed to load resource net::ERR_NAME_NOT_RESOLVED" error on two different systems from the android emulator running in HAXM using Cordova 6.4.0 and the version 25 (7.1.1) android SDK. Simply removing and adding the whilelist plugin resolved our issue without changing any configuration files.
I was having the same issue and nothing seemed to solve... And I figured out that in my case was the splashscreen image size that was too big (about 3.2MB)... I used this website to compress the file and then worked.
Restarting Device seems to resolve this problem for me locally, but this piece of work always comes back to me from support. So would like to have a fix for the solution not a workaround.
The whitelist plugin also has Content Security Policy declarations:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
This seems to have resolved the issue for me, but only time will tell as I can never get this issue to replicate on demand.
For me, none of the mentioned solutions worked. What worked for me was adding the plugin directly from the repo:
cordova plugin rm cordova-plugin-inappbrowser --force
cordova plugin add https://github.com/apache/cordova-plugin-inappbrowser.git
If the problem persists you can go ahead and remove and add the platform again:
cordova platform save
cordova platform rm <platform>
cordova platform add <platform>
It seems you are trying to send requests yet you are offline, try to check internet connection.
I have an application based on Cordova 2.7 for Android platform.
Yesterday I had to upgrade Cordova version because of Google Play warning about vulnerabilities...
What I did is to create a basic Cordova app throw terminal commands before upgrades.
After that I put this code into the index.js default file:
onDeviceReady: function() {
app.receivedEvent('deviceready');
//navigator.app.loadUrl('http://www.google.com/');
alert('inside');
//console.log(navigator.app);
//window.location = encodeURI('http://www.example.com');
//window.location.href = 'http://www.example.com/';
window.location = 'http://www.example.com/'; <--- Not works
//window.location = 'local_page.html'; <--- this works perfect
//window.open('http://www.google.com', '_self');
}
And the config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget
id="com.example.app" version="0.0.1"
xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
<preference name="loglevel" value="DEBUG" />
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<feature name="InAppBrowser">
<param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser" />
</feature>
<name>TPV_APP</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
Window.location doesn't work. Indeed doesn't show any posible error.
Its just doesnt work.
If window.location redirect to local pages, it works perfectly,
but for external pages it doesnt.
The alert is executed ok.
INFO: In my previous version of Cordova was working without problems.
I need to be redirected within the same webview. Not open another webview or browser.
I have been searching solutions for 2 days.
Any idea will be appreciated.
Thanks.
The problem I am encountering is that I want to unable the orientation on the application that is running on my tablet, I only want landscape view.
I have created the application using cordova, then added the platform "Android". Then I moved the config.xml into the www folder with HTML, CSS and JavaScript code and added the code line below inside config.xml.
Then I zip the www folder with config.xml, and used PhoneGap Build, to convert to an Android application.
When I test this on the tablet, the orientation does not work. How can I prevent orientation on the tablet by using config.xml?
I found the preference here.
<preference name="Orientation" value="landscape" />
Config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.BachelorProject.KPEC" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>ProjectKPEC</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<preference name="Orientation" value="landscape" />
</widget>
Preference attribute values are case sensitive I think.
Try:
<preference name="orientation" value="landscape"/>
Instead of
<preference name="Orientation" value="landscape" />
I found out the problem, just built the whole project and added android platform again, then I moved config.xml inside www folder, and it worked.
I have the following config.xml file for my android app, and I am trying to install launchmyapp plugin. Everytime I clean, I get this the following error
/code/platforms/android/res/xml/config.xml:21: error: Error parsing XML: unbound prefix
I checked other stack questions and everyone is pointing to wrong formatting in the parameter fields, but all seems ok...
here is the config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.myappname.Myappname" version="2.2.3" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>MyAppName</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<feature name="org.apache.cordova.facebook.Connect">
<param name="ios-package" value="FacebookConnectPlugin" />
</feature>
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
<content src="index.html" />
<access origin="*" />
<gap:plugin name="nl.x-services.plugins.launchmyapp">
<param name="URL_SCHEME" value="myappname" />
</gap:plugin>
</widget>
I've encountered the same question as yours. I supposed it's because
<gap:plugin> must be bound to phonegap prefix.
So I solved this question by adding xmlns:gap="http://phonegap.com/ns/1.0" at node.
In your case, the full <widget> should be:
<widget id="com.myappname.Myappname" version="2.2.3" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:gap="http://phonegap.com/ns/1.0">
Hope it works for you.