I followed the tutorial of Phonegap from the official Phonegap.com site (getting started with Android).
I have created project with following all the steps.
created activity and extended from "DroidGap" and added loadURL method from onCreate().
Added cordova-2.0.0.js and cordova-2.0.0.jar on the respective folder.
Added the jar file to the build path
Loaded the js file from the html tag
Added permissions from AndroidMainfeast.xml
copied the xml folder containing "configs.xml"
Now I don't understand where's the problem. It is showing the below error as shown in the screenshot
Here is my HTML file
<!DOCTYPE html>
<html>
<head>
<title>Notification Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
// Empty
}
// Show a custom alert
//
function showAlert() {
navigator.notification.alert(
'You are the winner!', // message
'Game Over', // title
'Done' // buttonName
);
}
// Beep three times
//
function playBeep() {
navigator.notification.beep(3);
}
// Vibrate for 2 seconds
//
function vibrate() {
navigator.notification.vibrate(2000);
}
</script>
</head>
<body>
<p>Show Alert</p>
<p>Play Beep</p>
<p>Vibrate</p>
</body>
</html>
Any advice? Thanks!
It is config.xml not configs.xml.
Based on the logs I'm seeing you are missing this file in your apps res/xml directory. It is included as part of the distribution at lib/android/res/xml/config.xml so copy that file into your res/xml directory and you should be all set.
Just as aharris88 in his answer to this question, I had the [CORDOVA] Error initilizing Cordova: Class not found error message when using Cordova 3.1.0 on my Android dev phone after migrating from Phonegap 3.0.
All fiddling with the config.xml file in the /platforms/android/res/xml directory did not help. Based on the Stackoverflow answer mentioned above, I tried to "start over" by reinstalling Android platform support:
cordova platform rm android
cordova platform add android
After this step it worked again, and I was able to cordova build android && cordova run android without any further problems.
I have had this error because of a plugin that I deleted. I Added
<plugin name="Device" value="org.apache.cordova.Device"/>
to the config.xml file again and it fixed it.
My you not have following plugin:
<plugin name="Device" value="org.apache.cordova.Device"/>
You have to put that in between <plugins></plugins>.
like
<plugins>
<plugin name="Device" value="org.apache.cordova.Device"/>
</plugins>
Well,the error I found is:
05-28 08:19:53.139: E/PluginManager(1478): =====================================================================================
05-28 08:19:53.139: E/PluginManager(1478): ERROR: config.xml is missing. Add res/xml/config.xml to your project.
05-28 08:19:53.139: E/PluginManager(1478): https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml
but I found /res/xml/config.xml in my project
finally,I found error in org.apache.cordova.api.PluginManager:
public void loadPlugins() {
int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getClass().getPackage().getName());
...
should change to:
public void loadPlugins() {
int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getPackageName());
...
you could read more about the method "getIdentifier(String name, String defType, String defPackage)" in offical doc
I had this problem using phonegap 3.x and the problem turned out to be that phonegap hadn't properly installed the plugins, or they just messed up along the way. Basically when you install the plugins and build for a platform it takes the javascript files from plugins/org.apache.cordova.core.specific-plugin/www and puts them in platforms/android/assets/www/plugins/org.apache.cordova.core.specific-plugin/www and then it takes the Java files (or objective C for iOS) and puts them in platforms/android/src/org/apache/cordova/specificplugin
And all of this is specified by plugins/org.apache.cordova.core.specific-plugin/plugin.xml. If you look in a plugins.xml you should see something like:
<source-file src="src/android/NetworkManager.java" target-dir="src/org/apache/cordova/networkinformation" />
So this tells you that in platforms/android/src/org/apache/cordova/networkinformation, there should be NetworkManager.java. And that file can be copied from plugins/org.apache.cordova.core.network-information/src/android/NetworkManager.java
Now all of this is supposed to happen automatically without having to touch the platforms folder. But if it messes up you can fix it by manually copying the correct files into the correct folders.
You can resolve this when using phonegap command line by doing the following:
Delete merges/android, platforms/android, plugins/android.json
run phonegap local build android
Had same problem with Class not found. One problem to look at is to ensure that the android.json (or ios.json) file is being updated on a build. Mine was effectively empty.
Also, remove and add back the plugins as mentioned in some other posts.
Finally, the thing that worked for me was to ensure that the plugins were corrected referenced in the config.xml:
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device"/>
</feature>
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.camera.CameraLauncher"/>
</feature>
<feature name="Notification">
<param name="android-package" value="org.apache.cordova.dialogs.Notification"/>
</feature>
Note the double naming of 'device.Device' and also the sub-classing of the 'camera' and 'dialogs' plugins. This just isn't properly referenced by the Phonegap documentation.
So After near to kill myself , i found that i was using cordova version 5.3.3 and cordova-android version 5.0.0, somehow i don't know may be there are not compatible or there can be a bug ,so i fall back to cordova android 4.1.1
cordova platform rm android
cordova platform add android#4.1.1
and this saved me up
I ran into the same error: "Error initializing Cordova: Class not found", using cordova with visual studio 2015. But this wasn't the only error, none of my plugins seem to get trough. I've tried about EVERYTHING. From cordova platform rm/add android x1000 times, to deleting and re-adding the plugins manually, nothing seem to do the trick.
Then i changed my cordova-cli in the taco.json file from 5.3.3 to 5.4.0 and ran it on my device. Finally this fixed the whole issue for me. I then downgraded the cordova version back to 5.3.3 ( the 5.4.0 version is not supported by the adb bridge as of yet ). Try it out!
I'm getting the same error, I checked my Cordova plugin list
by running the command "cordova plugin list" in my Android project directory and found "org.apache.cordova.device" plugin missing.
I updated it using "Cordova plugin add cordova-plugin-device" and Error was gone.
[Solved in my case]
First, step six is wrong: it is config.xml and not configs.xml
I have the same error despite I have my config.xml in res/xml folder.
It is because you have to install manually plugins for basic API functions.
Through console navigate to your project folder and type:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
You can read more here in phonegap Doc (last section called add features) : Phonegap Doc
I leave you also my config.xml file
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.helloCordova" version="2.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<name short="Menu">Menu Digital</name>
<description>
Description
</description>
<author email="asd#gmail.com" href="www.facebook.com/usr"> Name </author>
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="http://api.phonegap.com/1.0/device" />
<feature name="http://api.phonegap.com/1.0/media" />
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<content src="index.html" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<access origin="*" />
<preference name="useBrowserHistory" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
</widget>
This could happened 'cause your cordova plugin have a different path from what IONIC expect to found:
You should correct the file plugin.xml inside your plugin source folder:
<config-file target="app/src/main/res/xml/config.xml" parent="/*">
should be:
<config-file target="res/xml/config.xml" parent="/*">
If you try to searching that error inside the Android Studio Logcat usually you find something like:
io.ionic.starter E/chromium: [ERROR:service_manager.cc(156)] Connection InterfaceProviderSpec prevented service: content_renderer from binding interface: blink::mojom::BudgetService exposed by: content_browser
2019-02-22 13:40:06.144 30230-30258/com.android.webview:sandboxed_process0 E/chromium: [ERROR:BudgetService.cpp(167)] Unable to connect to the Mojo BudgetService.
Related
I am building and Application using Phonegap. Following is my problem:
I did cordova create hello, then I did cordova platform add android , followed by cordova plugin add org.apache.cordova.splashscreen and then finally cordova build android.
My top level config.xml contains:
<preference name="SplashScreen" value="screen" ></preference>
<feature name="SplashScreen">
<param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
</feature>
My index.html from www folder contains
<script src="cordova.js"></script>
<script src="cordova_plugins.js"></script>
<script src="js/main.js"></script>
My main.js somewhere contains:
navigator.splashscreen.hide();
I imported
<project root directory>/platforms/android into eclipse ADT.
I guess navigator.splashscreen.hide() is not working because splashscreen gets hide on 3000 ms only, which is by default and I am getting this on my ADT Logcat:
06-10 12:33:39.641: W/System.err(7663): java.lang.ClassNotFoundException: org.apache.cordova.splashscreen.SplashScreen
and a large dump regarding the same and then
06-10 12:33:39.651: D/PluginManager(7663): exec() call to unknown plugin: SplashScreen
I installed the FacebookConnect plugin into my cordova project with the code:
cordova -d plugin add /Users/your/path/here/phonegap-facebook-plugin --variable APP_ID="123456789" --variable APP_NAME="myApplication"
Then linked the Facebook API (3.8.0) in /platforms/android/project.properties with:
android.library.reference.2=../../facebook-android-sdk-3.8.0/facebook
Then copied the example 'Simple' into the /www folder, added my app id and changed phonegap.js to cordova.js.
When I compile and run the application on my android phone I receive the following errors:
Cordova Facebook Connect plugin fail on init
Cordova Facebook Connect plugin fail on auth.status
and on login:
Cordova Facebook Connect plugin fail on login!Class not found
LogCat gives the following error:
exec() call to unknown plugin: org.apache.cordova.facebook.Connect
I've scoured the internet but cannot find a solution to this problem.
I did notice that my /platforms/android/res/xml/config.xml file lists the plugin as:
<feature name="FacebookConnectPlugin">
<param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
</feature>
When the Documentation says that it should be:
<feature name="org.apache.cordova.facebook.Connect">
<param name="ios-package" value="FacebookConnectPlugin" />
</feature>
But I can't change this as it's automatically generated during the compiling process.
Did you remember to copy (from the download) www/cdv-plugin-fb-connect.js, www/facebook-js-sdk.js into your apps www folder?
I got the same error, managed to fix by updating my root config.xml (which isn't generated) to include:
<feature name="org.apache.cordova.facebook.Connect">
<param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" />
</feature>
(Note android-package as looks like you are using android.)
This is under the manual install section of the readme, but also seems to be necessary after following the automatic install process.
Now you can execute cordova build android from the root, bob's your uncle.
As of 6/13/14 this is what works for me, so I laid out my steps on PasteBin.
http://pastebin.com/WvQvqx6U
Basically just reverted back to 0.4.0 of Facebook Connect.
It's working perfectly for me, and I didn't have any issues setting it up.
hoping anyone can figure this out, have been battling with this issue the whole day.
I'm trying to browse through folders on the file system to select a file, but I cannot seem to connect to the file system.
When ever I call "window.requestFileSystem", the error callback returns a "Class not found" error. Going into Cordova's "requestFileSystem" function, I notice the "Class not found" is returned during the exec() call (where I can't trace it).
Did anyone get past this problem, or know how to fix it?
I am aware it's listed on several forums, but the fixes suggested there don't work for me.
As far as I can see, all the plugins are there. Installed using Cordova CLI, they appear in the plugin folder. I do wonder if the file plugin is actually loaded, not sure how I can verify that..
org.apache.cordova.console
org.apache.
cordova.device org.apache.cordova.file
org.apache.cordova.file-transfer
www/index.html
<body onload="onLoad();">
<script type="text/javascript">
// Init when we're good and ready.
function onLoad(){document.addEventListener('deviceready', init, true);}
// Init :)
function init(){
// window.requestFileSystem is recognized, so far so good.
window.requestFileSystem(1, 0, function(fileSystem){
alert('success');
}, function(e){
// 'e' is an object, {code: 'Class not found'}
alert('Error accessing local file system');
});
}
</script>
<div class="app">
<h1>Apache Cordova</h1>
...
</div>
<script type="text/javascript" src="cordova.js"></script>
</body>
config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.fwd.cwptakeonsheetsv1" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>CWPTakeOnSheetsV1</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="*" />
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<feature name="File">
<param name="android-package" value="org.apache.cordova.file" />
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
<param name="onload" value="true" />
<param name="android-package" value="org.apache.cordova.FileUtils" />
</feature>
<feature name="FileTransfer">
<param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>
</widget>
Cordova's requestFileSystem.js
/**
* Request a file system in which to store application data.
* #param type local file system type
* #param size indicates how much storage space, in bytes, the application expects to need
* #param successCallback invoked with a FileSystem object
* #param errorCallback invoked if error occurs retrieving file system
*/
var requestFileSystem = function(type, size, successCallback, errorCallback) {
argscheck.checkArgs('nnFF', 'requestFileSystem', arguments);
var fail = function(code) {
errorCallback && errorCallback(new FileError(code));
};
if (type < 0) {
fail(FileError.SYNTAX_ERR);
} else {
// if successful, return a FileSystem object
var success = function(file_system) {
if (file_system) {
if (successCallback) {
// grab the name and root from the file system object
var result = new FileSystem(file_system.name, file_system.root);
successCallback(result);
}
}
else {
// no FileSystem object returned
fail(FileError.NOT_FOUND_ERR);
}
};
// The error happens in exec()
exec(success, fail, "File", "requestFileSystem", [type, size]);
}
};
I think I found the problem (at least in my case). I'd struggled with this one popping up over and over again:
Simply open up plugins/android.json and move any entries under the 'config.xml' heading to the 'res/xml/config.xml' heading.
I think this is an issue with certain plugins (in my case, Immersify) not having switched to the new config.xml location. After I fixed this, all of the 'missing' plugins magically appeared in my platforms/android/res/xml/config.xml file, and the 'class not found' errors disappeared.
Have you checked the android.json that is generated in the plugins folder?
I had a similar problem because some 'not yet updated to 3.4' plugins like sqlite generated wrong directions in this file (which is used at build time). That lead into removing some other plugins from my actual config.xml
I eventually solved my problem. Here are the steps I did to get it working:
Moved all the JavaScript to the head-section of my index.html (including references to .js files).
Took all the feature-tags out of config.xml. My /platforms/android/AndroidManifest.xml still contains:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Took all alerts() and custom debugging functions out of my code. I don't know if the delay caused issues or what, but it seems to have an effect.
I also noticed that if window.requestFileSystem is undefined, it is likely due to a JavaScript error which causes it not to load.
There's a good example of this here - Thanks Ram for publishing this.
Thanks #QuickFix for your reply!
Using phonegap 3.1 I'm trying to hide the splash screen when device is ready:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.splashscreen.hide();
}
But it returns:
Cannot call method 'hide' of undefined
The navigator object doesn't including the splashscreen attribute.
I've tried it on phonegap 2.9 and it works fine.
After research and experiments this is what we had to do in order to get it work:
cordova plugin add org.apache.cordova.splashscreen
cordova build
Then, cordova build was adding the wrong lines to the config.xml - So we had to change it to the following:
<feature name="SplashScreen">
<param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
</feature>
And in your main activity
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.setIntegerProperty("splashScreenDelay", 10000); //time to display the splash
Finally we have been able to use hide method from javascript.
Are you using the CLI to add the SplashScreen plugin? You have to add the plugin with $ cordova plugin add org.apache.cordova.splashscreen (copy the plugin code from plugins.cordova.io into /yourApp/plugins/org.apache.cordova.splashscreen/ and then later cordova build to copy the plugin code into the appropriate platform location.
If you're using phonegap build, rather than doing
cordova plugin add ...
from the command line, you'll need to add the plugin and feature to the config.xml:
<gap:plugin name="org.apache.cordova.splashscreen" />
<feature name="SplashScreen">
<param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen" />
<param name="ios-package" value="CDVSplashScreen" />
</feature>
Only thing I can guess is to double check that you have <script type="text/javascript" charset="utf-8" src="cordova.js"></script> in the head of your HTML that is calling that JS. Sorry, haven't messed with 3.1 yet.
Add this:
<preference name="SplashScreen" value="splash.png" />
<preference name="SplashScreenDelay" value="3000" />
The navigator.splashscreen.hide() doesn't work for me either.
UPDATE: navigator.splashscreen.hide() only works when building online (phonegap build).
After upgrading to Phonegap Desktop 0.3.6, I had a similar issue and one of my older apps was stuck on the splash screen. In the configuration window, it was showing the correct app name and version and it was updating as soon as I was modifying the config.xml. In the console I had only one error: 500 for http://localhost:3000/cordova_plugins.js
A new app was working fine.
I tried all the above:
splash screen plugin and configuration
adding the cordova.js and cordova_plugins.js to index.html. This is not necessary anymore since many versions ago - the build does it for you.
in the platforms/android/assets/www folder there were cordova.js and cordova_plugins.jsfiles present
in the config.xml there was specified <content src="index.html" />
In the end what solved my problem was to completely delete the platforms folder and run cordova platform add android again. I guess it's safe to do this after each Phonegap upgrade.
I've been trying to upgrade a plugin to v3, and I've managed to get past the plugin loading issues, and I've managed to expose the plugin to the client environment (making changes to the way exec works, etc).
But when I watch the adb logcat with
adb logcat | grep -v nativeGetEnabledTags | grep -i web
I get this error:
D/PluginManager(11189): exec() call to unknown plugin: WebSocket
I can't work out what's gone wrong, and I'm not sure why the Android build can't see the plugin.
I've pushed ALL the code to a github repo, so if someone is able to replicate and help I'd be very welcome! I'm also trying to write up my experience of the conversion and logging the gotchas as I hit them (there's some in the readme, though it's incomplete):
Here's the repo: https://github.com/remy/phonegap_test
– Remy
define your plugin in "res/xml/config.xml"
find these lines in the file
<feature name="App">
<param name="android-package" value="org.apache.cordova.App" />
</feature>
and append these right after:
<feature name="MyPluginName">
<param name="android-package" value="com.phonegap.plugins.plugin.class" />
</feature>
replace the dummy names (MyPluginName, plugins.plugin.class, etc) with the actual names. This works for me when I was getting this error:
exec() call to unknown plugin : MyPluginName
I am all of a sudden getting the same issue with my phone gap build (2.6). Same exact code worked prior so it must be a build issue.
Did you tried to open your apk and see if config.xml is included (there is where plugins are defined).
On Android Studio 1.0.1 (running on Mac OS 10.9.5) + Cordova 4.2.0, I fixed a similar problem ("exec() call to unknown plugin") as follow:
it happened that the content of the tag:
<feature name="MyPluginName">
<param name="android-package" value="com.phonegap.plugins.plugin.class" />
</feature>
Under YourCordovaProjectName/config.xml was not duplicated under YourCordovaProjectName/platforms/android/res/xml/config.xml
I had to alter the file config.xml under YourCordovaProjectName/platforms/android/res/xml/ and to add the tag:
<feature name="MyPluginName">
<param name="android-package" value="com.phonegap.plugins.plugin.class" />
</feature>
Then it worked.
I will also add that I've experienced the same problem with IOS, I had to enter manually:
<feature name="MyPluginName">
<param name="ios-package" value="com.phonegap.plugins.plugin.class" />
</feature>
In the file config.xml under the folder YourCordovaProjectName/platforms/ios/YourCordovaProjectName
Hopefully that will be fixed in the future and the content of YourCordovaProjectName/config.xml will correctly be reflected in the config.xml files that are under each specific platforms (it used to worked correctly for Android few months ago).
For adding plugin definition in android under ProjectFolder/platforms/android/res/xml/config.xml,update the ProjectFolder/plugins/android.json
"cordova build” command will read this android.json file and update the ProjectFolder/platforms/android/res/xml/config.xml automatically with all plugins mentioned here.
Are you getting a successful deviceready event? I have gotten that error in the past when my app was silently failing for other reasons in my code causing my deviceready event to never fire. In my case the silent error was due to some javascript syntax errors in my app.initialize() code blocks.