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
Related
I have an Android Phonegap proyect and I'm trying to use the Splashscreen plugin Cordova provides. I think I have everything correctly set... Here are the pieces of code I think are relevant.
Config.xml
<widget ...>
...
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="15000" />
<plugin name="SplashScreen" value="org.apache.cordova.SplashScreen"/>
</widget>
Index.html
<script type="text/javascript" charset="utf-8">
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
navigator.splashscreen.hide()
}
</script>
I have correctly installed with the CLI the plugin and the splash itself is in the res/drawable* folders in the Android project as I think it should be, but regardless of what I try to do, the splash is not showing. Not even a default one. Not even if I disable the navigator.splashscreen.hide() function (in case it was too fast).
I'm absolutely lost now, have been trying tweaks for a week but I just can't see it.
I'm using cordova v3.6.3 in my android project.
I read a API & Plugin Documentations but, I confused the some options in config.
but, I found a perfect solution.
1. above all, you don't need to use
"navigator.splashscreen.hide()" or ".show()" in Android project.
2. refer my directory structure for understanding clearly.
3. Add following codes into your config.xml file.
※ Do not change the value="screen".
you just change the src and delay value for your splashscreen image.
[Config.xml]
<platform name="android">
<splash src="www/res/screen/android/screen-default.png" />
</platform>
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="4000" />
4. delete a "screen.png" file from drawable directory for understanding clearly.
5. build your project on your command line (cordova build android)
and, look again drawable directory.
I'll promise, you'll success. :-)
I was having the same issue after the 2.5.1 CLI update. If i run the same project in the VisualStudio ionic simulator all works fine. It also works fine when I run the app in the bowser with Telerik Platform. I just need to comment out navigator.splashscreen.hide(); in my project for the latest CLI simulator or I just get a plain white screen.
James
We have to build a mobile application using HTML5, to be worked on Android and IOS.
We started by using jQuery Mobile Framework to manage the pages and actions.Every thing is fine. The problem is when we use the Apache Cordova API, to get some info from the device like the uuid, and manage an Exit Application Button, nothing working!...
We use the Cordova Script which get from this Google Link.
We put the line below into the config.xml file before building the app pn phonegap:
<plugin name="Notification" value="org.apache.cordova.notification.Notification" />
We use the official documentation presented From Cordova Phonegap Site , which is below:
<!DOCTYPE html>
<html>
<head>
<title>Notification Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.5.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
}
// alert dialog dismissed
function alertDismissed() {
// do something
}
// Show a custom alertDismissed
//
function showAlert() {
navigator.notification.alert(
'You are the winner!', // message
alertDismissed, // callback
'Game Over', // title
'Done' // buttonName
);
}
</script>
</head>
<body>
<p>Show Alert</p>
</body>
</html>
But any thing not happened after building the sources to the Android Platform. No Events fired or anything related to phonegap!
We have searching many results and suggestions to resolve that but without any results!
The applications has been tested on Android 4.3.
Thank you for your suggestions.
You are using a very old version of cordova (2.5), the latest version is 3.5 and here is the proper location for documentation and download: http://cordova.apache.org/
Try putting a console.log or alert inside onDeviceReady function to make sure cordova is initialised properly, but I think your problem is with the cordova project setup. Try creating a fresh project using 3.5 with command line as explained in documentation first.
Try adding the device plugin from the command line:
phonegap plugin add org.apache.cordova.device
This has worked for me in the past. The command is the same for Windows, Linux and Mac. Then put something into your deviceready event to ensure that it's being fired.
Using cordova 2.9.0 and upper cans resolve this issues.
theses lines are needed to put in the config.xml file:
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" /> // android
<param name="ios-package" value="CDVDevice" /> IOS
</feature>
<!-- -->
<plugins>
<plugin name="App" value="org.apache.cordova.App" />
<plugin name="Device" value="org.apache.cordova.Device" />
<plugin name="Device" value="CDVDevice" />
</plugins>
<!-- phonegap plugins -->
<gap:plugin name="org.apache.cordova.console" />
<gap:plugin name="org.apache.cordova.device" version="0.2.8" />
<gap:plugin name="org.apache.cordova.dialogs" />
I have installed cordova (version 3.3) and built a sample project using these commands:
$ cordova create hello com.example.hello "HelloWorld"
$ cd hello
$ cordova platform add android
$ cordova build
and imported the project into Eclipse (according to http://cordova.apache.org/docs/en/3.3.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide). I am able to successfully run the app from Eclipse by selecting Run As → Android Application.
Now I want to make use of cordova's notification ablities. I added the plugins (following this guide: http://cordova.apache.org/docs/en/3.3.0/cordova_notification_notification.md.html#Notification) with the commands:
$ cordova plugin add org.apache.cordova.dialogs
$ cordova plugin add org.apache.cordova.vibration
and when I type:
$ cordova plugin ls
it correctly lists the plugins I just added.
I return to Eclipse and paste the following code into assets/www/index.html (overwriting the existing code in index.html):
<!DOCTYPE html>
<html>
<head>
<title>Notification Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
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>
When I deploy it to a device, it displays three links (Show Alert, Play Beep and Vibrate). When I press on these I expect the corresponding native notification to occur, but it doesn't. Instead I get the following error messages (displayed in LogCat):
Show alert: Uncaught ReferenceError: showAlert is not defined:45
Play Beep: Uncaught ReferenceError: playBeep is not defined:46
Vibrate: Uncaught ReferenceError: vibrate is not defined:47
How am I supposed to fix these errors?
Thanks in advance!
Have you tried to update the files and run everything from the www folder instead?
In your question you didn't mention updating the config.xml and AndroidManifest.xml files as noted in the API documentation. I'll copy them here for reference.
(in app/res/xml/config.xml)
<feature name="Notification">
<param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>
<feature name="Vibration">
<param name="android-package" value="org.apache.cordova.vibration.Vibration" />
</feature>
(in app/AndroidManifest.xml)
<uses-permission android:name="android.permission.VIBRATE" />
For further clarification see the answer to this question.
Should a phonegap plugin be declared in the config.xml file?
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 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.