What I'm trying to do is embed a cordova application into a native android application.
It seems to me that the documentation is out of date or not clear about the steps that needs to be done.
Documentation:
https://cordova.apache.org/docs/en/latest/guide/platforms/android/webview.html
I am at the point that I can't create the .jar file for the following reasons.
I don't have a /framework directory in my root project directory or in platforms/android
Cordova seems to be using gradle instead of ant for building the android project. I can't find a build.xml anywhere in the android project.
My Cordova version: 8.0.0
As as followup question, I expect this .jar file will also contain the plugins that the cordova project depends on, correct?
Related
I'm creating an Ionic project using Capacitor (edit: the newer recommended framework compared to Cordova) and added Android as a target.
I've been able to build the app and add the Android target, which creates a bucketload of files under android/, using:
ionic build
ionic cap add android
Then, I was able to launch Android Studio and emulate my app, using npx cap open android, with "Run App" in Android Studio. This added a few more bucketloads of files.
I was able to get most of them to be ignored by adding the "ionic" and "AndroidStudio" gitignore entries from gitignore.io, but if someone clones the repo, they can rebuild the entire Android directory from scratch, right? Do I just consider everything in the android folder to be a build artifact that can be recreated from the core ionic project using capacitor (i.e. "cap").
Is there anything that needs to be saved to the repo in the ionic android directory? If so, which files - or should I fall back to ionic/Android Studio gitignore entries for the android folder?
Is there anything that needs to be saved to the repo in the ionic android directory?
I would suggest that you include your native folders in your repo as well.
Based on my experience with capacitor over the past year while developing two applications, consider these things.
Most of the times you will be using at least a few cordova plugins, since capacitor still doesn't have a viable plugin for certain features.
These plugins, will require you to manually add some variables ( like sdk keys ) or initialization function on the native side of the codes.
In fact, even for capacitor community plugins ( which are plugins created by other samaritans ), you will have to add some minimum lines of code to the native side. Consider this plugin for facebook sign in. Just go through the installation steps, you will see a long list of configurations on both ios and android sides.
Capacitor is not formerly Cordova. Both of these are different frameworks. Capacitor completely depends on native ide's for compilation, whereas cordova cli could build the native codes for you (ios, mac required).
but if someone clones the repo, they can rebuild the entire Android directory from scratch, right?
When your application grows, depending on its intended functionality, this would not be an easy task. They will have to go through all these minor tweaks to get it working.
All in all, put your native code in the repo as well. For me, the repository size with the native codes is not terribly huge.
In Capacitor you are supposed to commit the ios and android folders. They contain their own .gitignore files with the recommended files for iOS and Android.
They are not build artifacts, if you change icons or configurations (in Info.plist, AndroidManifest.xml, etc) and you delete the folders, those changes will be lost.
If you clone a Capacitor project you should run this commands:
npm install (or other install package depending on your package manager)
npm run build (or ionic build if using ionic)
npx cap sync (this copies files and generates non committed files)
As #jcesarmobile
In Capacitor you are supposed to commit the ios and android folders. They contain their own .gitignore files with the recommended files for iOS and Android.
But if you're looking for a .gitignore to use at the root of your project, this one should do the job.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
.vscode
.idea
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Optional eslint cache
.eslintcache
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.
I this documentation:
Cordova documentation
I cloned the latest Cordova here: https://github.com/apache/cordova-android
But when I run "ant jar" as described in the documentation, I get this error:
cordova-android-master/framework/build.xml:124: Cannot find
/Users/neigaard/Library/Android/sdk/tools/ant/build.xml imported from
/Users/me/cordova-android-master/framework/build.xml
Google say that is because ant/build.xml was removed from Android SDK. I found a post saying that I should download a old Android SDK tools and replace my SDK tools folder with that, but I rely on my Android SDK to be working and up to date.
Is there no way to build the Cordova Android jar without an outdated Android SDK or is there somewhere I can download a pre-built jar or is there another way to integrate Cordova into a existing Android app?
You don't really need the .jar anymore, Cordova is distributed through gradle, so you can just add this in the dependencies section of your app gradle file:
implementation 'org.apache.cordova:framework:7.1.0'
Tutorial cordova.apache.org/docs/en/latest/guide/platforms/android/… looks outdated. If you just want to embed a cordova webview you don't really need the .jar anymore, Cordova is distributed through gradle, so you can just add this in the dependencies section of your app gradle file:
implementation 'org.apache.cordova:framework:7.1.0'
However if you want to create jar through ant then you don't required to use complete outdated Android SDK.You have to just place ant/build.xml in tools folder.
Below are the steps to create corodva.x.x.x.jar on Windows
Step-1 Download Android tool package from below location:
https://dl.google.com/android/repository/tools_r25.2.5-windows.zip
Step-2 Copy ant folder to
C:\Users\xxxx\AppData\Local\Android\sdk\tools
Step-3 Install Cordova using npm
npm install -g cordova
You can install specific version of cordova using cordova#version.
Step-4 Go to below location and copy your local.properties from your android project:
C:\Users\xxxxx\.cordova\lib\npm_cache\cordova-android\x.x.xx\package\framework
Step-5 Navigate to the Android package's /framework directory and run ant jar.
It creates the Cordova .jar file, formed as /framework/cordova-x.x.x.jar
FYI: It is recommended to refer the cordova requirements-and-support https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#requirements-and-support
I'm trying to add additional Phonegap plugins (namely, the File plugin) to an existing android application that uses Phonegap.
I've tried navigating to my project directory (in my workspace) and then run the command
cordova plugin add https://theurlwhichworks.org/
It says the plugin is installing, and when I go to look in my workspace on my computer, there is a folder titled plugins, and inside, a directory called
org.apache.cordova.file
which means that the plugin (apparently) downloaded correctly, but doesn't seem to have been added to my project.
Is there any way to manually add this plugin (or others) to my android project directly? I build+run my application to an attached device from eclipse, because anytime I try to use the CLI with regard to cordova/phonegap I always seem to be doing something wrong, or the result is not at all what I expected.
Hopefully it is possible to add these plugins manually. I appreciate any suggestions
It is possible to add plugins manually, and that is how we did it in the old days before the Cordova/Phonegap CLI or PlugMan
options
A. use PlugMan directly
npm install -g plugman
check out the plugman documentation. Outside of a Cordova project, plugman is your best bet for a clean automated install
B. manually
add the .java files to the android project src/ directory
remember their path has to match their namespace
dump the plugin js file somewhere in assets/www/*
add a feature tag to platform config.xml
It has been a long time since I added a plugin manually, and the cordova plugin spec has gone through major changes multiple times since then. You may need to manually include the plugin js implementation (eg via script tags in index.html)
I would highly recommend you use PlugMan, or at least try before the manual install.
Seems you're using eclipse.
A cordova 3.x project looks like this :
/www
/plugins
/platforms
/platforms/android
/platforms/android/assets/www
...
When you run cordova plugin add https://theurlwhichworks.org/ the plugin is added only in the /plugins folder but not in your platform folder.
In your eclipse project you only see /platforms/android folder.
To actually add the plugin to the android platform, you have to build the platform :
cordova build android
or at least prepare the platform (same as build but does not try to compile):
cordova prepare android
But be aware that when you either build or prepare, the content of the platform/android/assets/www folder will be replaced with the content of the root www folder.
So if you've been modifying directly the assets/www folder in eclipse, DO NOT FORGET TO SAVE IT BEFORE YOU BUILD OR PREPARE!!!
Every time plugins start acting funny for me I usually remove and re-add the platform and everything usually sorts itself out. The commands for Android for example,
cordova platform remove android
cordova platform add android
If your plugin list has what you expect, re-adding the platform re-downloads all the plugins.
I've created by command line a new phonegap application.When I try to get it by eclipse from android existing code it can't recognise as a android project.
Have I build my phonegap app before?
Phonegap project's folders are:
.cordova
hooks
merges
platforms
plugins
www
phonegap create [optional params] will setup a blank project space. To add platforms to this project you must run phonegap platform add [ios/android/wp8]. Then depending on the platform and how you wish to develop it, you run either phonegap prepare or phonegap build.
In your case, since you wish to import to Eclipse, you will want to run:
phonegap platform add android
phonegap build
Then in Eclipse you can browse to /PROJECT_PATH/platforms/android and import your project.