I have cordova latest version installed on my system and I created the basic app with command
cordova create
and I added the platform using
cordova add platform android
and I replaced the default index.html in the www directory with my own index.html
but whenever i tried to generate apk, and tried to run it on my mobile. It was the apk generate with default index.html
the screen of my app will be
How to resolve this issue ?
This is a normal behaviour.
Cordova is going to take the index.html from your projects root folder, everytime you run cordova build, prepare or serve without attribues, which is located directly inside your projects www folder.
Root www folder inside your cordova project contains the index.html which is taken and "thrown" into all platform folders when you run those commands.
projectName -> www -> index.html
Solution
You work in your projects root folder, and run cordova prepare everytime after you did a change to your index.html file.
You work directly inside your android project folder and the index.html which is located inside the assets -> www folder
You can change default index.html file to your own .html file
Simply open config.xml file in your project folder and edit its src attribute in <content> tag:
like:
default:
content src="index.html"
edited:
content src="helloCounterApp.html"
(Then it will load helloCounterApp.html not index.html(default))
Related
I am adding plugins to my cordova android application but I am unable to reference cordova.js file in the index.html page. Image of Structure of my application is : [App structure Image][1]. I have highlight both files in the image index.html and cordova.js. The solution I though was to copy the plugin JS files from platform_www folder to inside www folder. But as the plugins keeps on adding its seems not a good solution to copy paste js files.
the cordova.js file gets copied into the www directory structure when the app is compiled, you don't need to manually copy it - you just add a link:
<script src="cordova.js"></script>
While creating my app I issues the command:
phonegap create appdir com.site.myapp myapp
so now the appdir folder has the following.
-.cordova
-hooks
-platforms
-plugins
-www
-config.xml-----(config.xml is generated at top level)
In my www folder i have one index.html and one image that I want to use as my icon
www
-index.html
-icon.png
1)so which do I give the path for the tag in the config.xml file?
2)where do I put the config file do i need to move the config file inside the www folder like in phonegapbuild
I have tried various path combinations but none is working
Using Android, The application icon is located here: res/drawable/
So replace icon.png there.
Same thing for splash screen, replacing res/drawable/screen.png.
I have an existing native Android app to which I'm adding a cordova webview.
This is in the new gradle project format with Intellij.
I've successfully gotten the cordova activity loaded, and opens as expected.
I added the webview by following the cordova docs.
Now I'd like to use some of the plugins available but can't find a way to add them to the project.
Since this isn't a cordova generated project, plugman doesn't work. I've tried copying the JS and Java files for the plugins I'm interested in to my source dir but that results in various errors.
e.g. require is undefined, when this happened, I added requirejs to the webview's index.html
and it moved on to
Uncaught Error: Module name "cordova/exec" has not been loaded yet for context: _. Use require([])
http://requirejs.org/docs/errors.html#notloaded cordova.js:8
Failed to load resource file:///android_asset/www/scripts/cordova_plugins.js
deviceready has not fired after 5 seconds. cordova.js:1191
Channel not fired: onDOMContentLoaded
How do I get a plugin working with this?
EDIT:
I am manually moving stuff around.
This has to be put into an existing project which uses gradle for building.
Using cordova create generates a project in the old ANT format.
I followed the docs on embedding a WebView in an existing project (see the link above), but it doesn't mention any of the JavaScript files. So I just copied cordova.js from the android platform directory.
Like wise, I download the plugins I wanted, copied their JavaScript files, added the feature to build.xml and copied their Java files to my src directory.
I didn't know about cordova_plugins.js or that cordova prepare generates them.
You have to use Plugman to manage your plugins in the custom built Cordova WebView.
Please remove all your existing plugins and read them using plugman.
plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts
where the <proj> is the folder where you main project is created,
Alternatively you could use --www parameter which allows you to specify where root of web application is stored. Example:
plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts
Plugman reference
EDIT
If you have highly customized project, you could create empty Cordova project where you add
plugins, and copy cordova_plugins.js from this project to assets\www\scripts, Cordova should pickup these files. If you have your plugins JS files not in the assets\www\scripts\plugins\ folder, but instead of that in assets\www\plugins you have to modify content of cordova_plugins.js like that
module.exports = [
.....
{
"file": "../plugins/org.apache.cordova.inappbrowser/www/InAppBrowser.js",
"id": "org.apache.cordova.inappbrowser.InAppBrowser",
"clobbers": [
"window.open"
]
},
...
]
Here is some input on how I came though,
I am in a similar position like the OP, embedding a Cordova Web View in my Native Android Application.
After executing
plugman install --platform android --project <proj> --plugin org.apache.cordova.battery-status --www <proj>/assets/www/scripts
What happens is you get a new 'Cordova' folder in your original 'main' Folder, (Where your AndroidManifest.xml is). Besides that, there is the 'src' folder with the code you actually need generated.
What I did, was copying the org folder from src to the 'java' folder. And everything worked.
I've got a simple app for Phonegap. In the www folder I added some NPM sugar to help development. Now, during the build I'd like to ignore this node_module folder created by NPM when it loads the dependencies. It actually make the build fail.
I've added an ant.properties file within root/platforms/android/ and wrote this line:
aapt.ignore.assets:!.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~:<dir>node_*
It prints that it ignores the folder node_modules because of that property, but when I look at the folder root/platforms/android/assets/www I can see the node_modules folder.
I guess my question is, is the folder actually being ignored in the created APK?
Make a copy of your APK and change the file extension from .apk to .zip then extract the zip. You will be able to browse to the www folder and see if it's in there or not.
I just created an Android Project in Eclipse with all the phonegap and cordova files as expected. However, I have no such directory, and thus, no config.xml. According to the Apache Cordova documentation, it is supposed to be located at: app/res/xml/config.xml.
My folder structure is as follows, for the /res directory:
/res/drawable-hdpi
/res/drawable-ldpi
/res/drawable-mdpi
/res/drawable-mdpi
/res/layout
- /res/layout/main.xml
/res/values
- /res/layout/strings.xml
What have I done wrong or what step am I missing? I hope I have provided enough information.
Just create the /res/xml/ folder manually. Then create config.xml using a text editor and use this as a template: https://github.com/phonegap/phonegap/blob/master/lib/android/xml/config.xml
Whenever we create a cordova project, config.xml gets created automatically. We need to check if there is any folder in excluded list.
Go to Build path -> Resources -> Check for excluded resources.
Remove them from the project and build the project. You will be able to view the config.xml and www folder in the Project/Package Explorer.