Deploy working polymer app to android using cordova - android

Yes,We have resources for this on net and I searched for that ,But it didn't solve my problem so asking this question here.
I have a working polymer web app and I am able to access this using http://localhost:8080//index.html,My app looks like this
I want to deploy this app in android phone,So I used apache cordova
Below are the steps I followed
Installed cordova using
npm install -g cordova.
create cordova project
cordova create alertsDir com.alerts.net "Alerts" --template=C:/Users/212606402/Learning/Alert client/alert-push-notification-client
cd to alertsDir and add platform
cordova platform add android
build platform
cordova build android
run project
cordova run android
I am not getting any error in above steps
I run this in both android emulator and nexus 5 devise but it showing the same default cordova screen,My app is not shown there,Below is the emulator screen I am seeing
I followed some tutorials and just wondering how it works for them.
tuetorial 1
Can anyone please explain me what I am missing or doing wrong.Thanks in advance.

as far as i know, Cordova only deploy 2 folder platforms folder and www folder but not all in platforms folder will get deployed to your device, usually the cli will merge platform_www and www folder.
so if you want to make a cordova app you need to put all your sourcecode or sourcecode that already bundeled using either polymer-build with gulp or polymer-cli inside www directory.

Related

PhoneGap Development

How easy is PhoneGap to build and deploy Android applications? The application I'm thinking of is not a beginner level app. How is the level of debugging and error handling and the support it gives?
Thanks in advance.
Deploying an app with Phonegap is quite easy. You can install Phonegap by using,
npm install -g phonegap#latest
and then create an app by,
phonegap create myApp
Refer the docs, PhoneGap Getting Started
When you create the app you will notice there is a directory called "WWW". All you have to do is copy a build of your existing web app to this directory.
All your assets and code in this directory will be used to build apps for the platforms you specify.
You can use Cordova to add the Android platform, which will be used to get an Android build out of your project.
Use,
cordova platform add android
Notice the directory "platforms". Inside it you will find another directory called "android" and this will be your Android project.
To build an Android app simply use,
phonegap build android
When you run the above command Phonegap will build an Android project using your code in WWW directory and place it in the platforms/android directory.
You can then use Android Studio to open the android directory which is an Android project now.
It's as simple as that and quite easy once you get the hang of it.
Then you can do all the regular debugging inside Android Studio using Logcat.

Cordova not copy fonts when generate APK

I use Cordova 8.0 and it is my www project tree:
When I run cordova run android for test my app in my phone I get the next project tree:
(I show it thanks to Chrome Dev Tools)
So cordova completely omited my fonts folder How can I avoid it?
EDIT:

Cordova Web App

I'm trying to make an apk of the web app I made in babylonjs.
From my understanding you can use Cordova to convert a web app into an apk.
I was able to install Cordova and make its hello world apk download to my phone and open and run it just fine.
However my problem occurs when I put all of my web app files into the www folder in my Cordova project folder. After I do that Cordova gives me this error
Error: ENOENT: no such file or directory, stat '/Users/dylan/practiceApk/www/node_modules/.bin/nopt'
when I try to build the android version.
Here is some information about my setup I believe is relevant.
OS: Mac
cordova -v: 7.1.0
Cordova requirements:
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-26,android-24
Gradle: installed /Applications/Android Studio.app/Contents/gradle/gradle-4.1/bin/gradle
cordova info also gives this error(similar error I believe to the one above):
Error retrieving Android platform information:
Android SDK is not set up properly. Make sure that the Android SDK 'tools' and 'platform-tools' directories are in the PATH variable.
Error: android: Command failed with exit code ENOENT
But I tried a lot of different things to fix this. Most of them involved making the android tools in the path (er something..?) I also downgraded from the most recent version of Cordova and android. I believe the problem is in my web app node_modules/.bin/nopt
But I don't know why its is a problem.
Also im not sure how this affects it, but I'm not hosting the website anywhere I just assumed I can used Cordova to create the web app as an apk that could be used offline, all resource are in the project folder though.
Any ideas on how to fix this? I only started using Cordova today so I don't know much about it.
Thanks for your time!
Update: I tried building an iOS version and I get the same error. I believe this is an issue with my npm setup...
It seems that when I was copying over my project to the newly made Cordova project folder I also copied the node_modules folder and didn't actually initialize npm. After initializing it and then updating it would build the app.

why $cordova prepare when use a new phonegap-cordova api(plugin)

Im new with phonegap, cordova and android. Im on mac, recently i install all the needs:
Phonegap 3.3.0-0.19.6
Cordova 3.3.1-0.4.1
Got Android SDK and running on eclipse with no problem. Then create a new Android application on eclipse for phonegap successfully, and running on a phone with android.
Then i create another app with cordoba(terminal), put 2 platforms android and ios, i run prepare etc.. and then import the project(android) into eclipse. At this point the app runs ok, so i proceed to install some plugins for testing (Notifications and Device)
https://cordova.apache.org/docs/en/3.0.0/cordova_device_device.md.html#Device
When i run the app with eclipse the examples always return
Uncaught TypeError: Cannot call method 'alert' of undefined
And its the same with device. So looking over the internet i found that if i run $cordova prepare will work, then i run the command, then run the app on eclipse and it work but always when i install a new plugin for testing i have to run cordova prepare, and the problem is that index.html rewrite with example hello world and i loose my code.
Any help over here, im doing ok?, how to install those plugins and make the test and dont have to run prepare all the time. (Please think on eclipse, i dont what to use terminal all the time)
I had the same exact problem and other posts suggestions didn't work for me.
I solved it by switching the steps a bit, despite the official docs and other posts.
If I add ALL the files AND the core plugins BEFORE I add the platforms, then adding the platforms takes these things with it into the new folder structures AND only build once from the command line before I open the project.
If I need to add anything I do it again. Although I can edit the www files without going through the process again, I do not expect the root www to perpetuate the platform www's. I just copy it myself into all the www folders. It shouldn't be this way but I think this is a well documented bug with multiple command line builds, for now and thats my working fix.
The recommended way is to edit html/js/css... in the root www folder of the project, not in the platfotms/xxx folders.
The reason is that if you have multiple platforms, you just need to modify in one place and cordova prepare or cordova build or phonegap build will propagate your code to all the platforms and update plugins.
If you have only android platform and want to be able to change code directly in eclipse for the platforms/android/assets/www folder, I suggest you create a shell script to
copy all the content of projectroot/platforms/android/assets/www to projectroot/www
run cordova prepare android
Then, instead of running cordova prepare android, you'll just have to run your script after you add new plugins.
Edit
I think there may be a better way for your problem.
You should be able to use plugman to install your plugins instead of cordova.
First you need to install plugman cli : npm install -g plugman
then install a plugin using
plugman -d --platform android --project projectname --plugin nameorurlofplugin
http://cordova.apache.org/docs/en/edge/plugin_ref_plugman.md.html
I had these issues too.
One approach I use now is:
Edit the index.html in the platform folders which is platform/iOS/appname/www and so. Then add plugins using the normal terminal way using cordova plugin add but always run the project using Xcode for iOS and eclipse and not from the terminal because then you will lose your code.
From my experience when you run using .xcodeproj or say android project the www on the inside is used and if you use cordova run ios from terminal the www on the outside will overwrite the www in the platform folders.
If you get xcode errors saying can't find so and so plugin files just move them to the path the error says xcode expects them to be in.

cordova create VS cordova-ios/bin/create

On OSX I want to create a PhoneGap app to run on iOS and Android.
I installed cordova (3.0.0) and phonegap (3.0.0-0.14.0) using npm.
Following the CLI guide I can create my app using
cordova create hello com.example.hello HelloWorld
then add platforms
cordova platform add ios
cordova platform add android
It works well but I'd like to use XCode as IDE. I read the IOS platform guide and saw I can create my app using
./path/to/cordova-ios/bin/create /path/to/hello com.example.hello HellowWorld
I can't execute that command if the folder already exists, so I removed it first. I then tried adding android to it but it doesn't work (Current working directory is not a Cordova-based project.). I then noticed that the content of the directories are really different depending on the tool used.
Is there an easy way to create an XCode project and still be able to use the CLI to build for Android and iOS?
I was able to create a project for ios using the CLI against the bin directory of the ios platform as in your example EXCEPT, I had to create an empty folder first. Try this..
./create ~/My-Project/name of empty project folder com.example.appname. "Project Name"
You can:
create a project using cordova create projectname
add ios support with cordova platform add ios
navigate to projectname/platforms/ios and open the .xcodeproj file in XCode
to use XCode as the IDE.
cordova platform add ios uses the create script under the covers.
The issue you will run into is that if you make changes to the html, css, or js files under projectname/platforms/ios, you will have to manually push those changes back to projectname/www. Or you can only make changes to projectname/www and use cordova prepare to push them to your ios directory (and your android directory).
You'd also need to decide how you want to handle version control--will you do it yourself with a command line client, or within your IDE?

Categories

Resources