When I use the command: cordova build --release android the CLI throws the following error:
Error: Cannot find module 'minimatch'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (C:\Users\sologic\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\node_modules\glob\glob.js:44:17)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
But when I use Ionic Lab (Windows Installer) and using the Build option - it generates 'android-debug.apk' & 'android-debug-unaligned.apk' in the android\build\outputs\apk folder.
Note that it is not generating android-release-unsigned.apk
My questions are:
1: What is wrong with the CLI ??
2: can I use the android-debug-unaligned.apk for Signing (with jarsigner) and Aligning (with zipalign ) for submitting on Google Play ??
Please advice.
Nothing went wrong with IONIC CLI at this time (v1.7.6), because I'm using it every day.
Check your CLI version by this command ionic --version and see if your version is lower than 1.7.6.
If your CLI is old, run npm install -g ionic again to install the lasted version of Ionic CLI.
If not, try to re-create all new project, and try to build again with, if it OK, just because of your project:
ionic start appName blank
ionic platform add android
ionic build android --release
You can't use the debug apk for Google Play because they can read your APK and check if is is debug or release version. But I think you can set the debug mode in your AndroidManifest.xml to false and try like this:
Add android:debuggable="false" to the <application> element.
More info : Using Hardware Devices.
Ionic also provide a package cloud service very helpful for non-plugin project inside the Ionic CLI. It can build all your project in the cloud in a minute and you can download the apk anytime.
cd to your ionic project folder by Ionic CLI.
Run ionic package build android an wait for the progress to done.
Run ionic package list to get the list and see the status if it has been done the building progress.
Run ionic package download [id] to download your apk to your project folder. id is the number you see in the list.
These commands will help you build the debug apk, for the release version, check this ionic.io package documents to build with profile (keystore).
Related
I have inherited an Ionic 5 project with Angular and Cordova - not Capacitor. It is using a couple of native plugins, namely QR Scanner and In-app Browser. The application works fine when launching in the Android emulator using:
ionic cordova run android
Now I want to build an APK that I can distribute to a few testers to give the application a try. This APK has to be built using a specific configuration to connect to a pre-production environment (using Firebase, but that shouldn't matter I guess). The process I am using is:
ionic build --prod --platform=android --configuration=preprod
ionic cordova prepare android --no-build --prod
ionic cordova build android --no-build --release
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <PATH_TO_KS> <PATH_TO_APK> <KEY_NAME>
zipalign -v 4 <PATH_TO_APK> <PATH_TO_SIGNED_APK>
Now the signed APK installs correctly to the emulator and the application starts AND connects to the pre-production environment. But the native plugins (e.g. QR Scanner) do not work. The error I am getting is Native: tried calling QRScanner.prepare, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator. It seems that Cordova is not active because when printing the platforms, they do not include the "cordova" string:
import { Platform } from '#ionic/angular';
constructor(private platform: Platform) {...}
ngOnInit() {
this.platforms = this.platform.platforms().join(',');
}
The result of this.platforms is android,phablet,cordova,desktop,hybrid when running with ionic cordova run android, but is just android,phablet,desktop when installing the APK I built with the process above.
Do you have any ideas why? I am quite new to mobile development, so you can absolutely assume I have made newbie mistakes. And if you feel that any other information would be useful, please let me know and I will happily add it.
EDIT: In order to support the preprod configuration, I added the following sections in angular.json:
{
"projects": {
"app": {
"architect": {
"build": {
"configurations": {
"preprod": {
...
}}}}}}}
Building with just ionic cordova build android yields the following error:
> ng run app:ionic-cordova-build:preprod --platform=android
An unhandled exception occurred: Configuration 'preprod' is not set in the workspace.
This is why I am building in 3 phases, ionic build ... --configuration=preprod, ionic cordova prepare ..., ionic cordova build android --no-build. My intention is for the first to build the app in the correct configuration, the second to update the Android project with the web files built with the configuration and the third to build the final APK.
The simple normal way of building a new app for debug (apk) is just calling
ionic cordova build android
This calls prepare internally, so no need for another call. It will produce an apk file that you can use for testing on devices (and possibly emulators depending on functionality).
When it's time to release to the store, considering this is a new app and Google's requirements have changed, you need to build a .aab file. The following will do that:
ionic cordova build android --release
As for signing, you need to provide the key to Google and they will sign it for you via the .aab provided. This is explained in more detail here:
https://ionicframework.com/blog/google-play-android-app-bundle-requirement-for-new-apps/
Now, if you need to create a custom configuration (what you're referring as preprod) because you have some very specific angular environment changes or requirements, outside of what the defaults have to offer, as you found out in the comments, you will need to edit the angular.json file to add it.
Ionic by default provides a structure for environment variables, which can be found in src/environments. More details about how this works can be found here:
https://medium.com/swlh/environment-variables-in-angular-ionic-8aa1698f2cc5
This is mostly Duplicate of build fail for android but no answer is yet available and my scenario is little different so putting it again.
In my my case I am able to build apk properly and I want to create a app bundle after successful of command
ionic cordova build android --prod --release by running this cmd I am able to generate the apk.
After that I am going to /platform/android and running ./gradlew bundle and here I am getting this error
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
FAILURE: Build failed with an exception.
* What went wrong:
Task 'bundle' is ambiguous in root project 'android'. Candidates are: 'bundleAppClassesDebug', 'bundleAppClassesDebugAndroidTest', 'bundleAppClassesDebugUnitTest', 'bundleAppClassesRelease', 'bundleAppClassesReleaseUnitTest', 'bundleDebug', 'bundleRelease'
How to fix it?
For those that end up here and find that the --packageType=bundle flag doesn't seem to work, pay close attention to the note here:
Note: You should use double -- to indicate that these are platform-specific arguments, for example:
cordova run android --release -- --keystore=../my-release-key.keystore --storePassword=password --alias=alias_name --password=password --packageType=bundle.
Notice the empty -- after --release. The below assumes you already have your keystore and password configuration in build.json:
cordova build android --packageType=bundle // flag is silently ignored, generates apk
cordova build android -- --packageType=bundle // flag works, generates aab
Ionic has built-in command line to generate the .aab format.
AAB:
ionic cordova build android --prod --release -- -- --packageType=bundle
It will generate automatically the .aab at android/app/build/outputs/bundle/release
APK:
ionic cordova build android --prod --release
May it helps someone.
Thanks
In other answers it seems that you can run:
./gradlew bundleRelease
In my case it's not working.
I solved upgrading android platform version for ionic.
ionic cordova platform rm android
ionic cordova platform add android#8
ionic cordova build android --prod --release
After that, if you go in platforms\android folder you are able to do
./gradlew bundle
I didn't check gradle versions for both android versions but I suppose it's changed.
Regards,Vincenzo
My requirements were different to the original question but this still might be useful for some.
After upgrading Cordova the build command below was producing an .aab file where prior to update it was producing an .apk. Our build pipeline was set up for signing an APK file so I wanted to make APK the default.
$ ionic cordova build android --prod --release
When I upgraded from cordova 8.x.x to 10.x.x This command defaulted to an .aap file being produced
adding the -- --packageType=apk did not work.
I had to create a build.json in the root cordova app directory with the following:
{
"android": {
"debug": {
"packageType": "apk"
},
"release": {
"packageType": "apk"
}
}
}
This worked perfect.
I got it to build successfully by updating build.json and running the command cordova run android --release!
What I did is:
Upgrade Gradle form v6.7.1 to v7.3.3 (Windows version, download .zip and setup "Path").
build.json add ,"packageType": "apk".
Build app-release.apk successful:
This works for me, keys are already generated.
cordova build android --prod --release -- --packageType=bundle
ionic cordova build android --prod --release -- -- --packageType=bundle
This is the right answer
I just executed the command "ionic build android" on my ionic 2 project and it was done successfully it says. But there is no APK file generated. What am I supposed to do? Thanks in advance. I'm using node v6.11.2, Ionic CLI 3.7.0, cordova 7.0.1.
First create an account at ionic Io
than hit this ionic Io init in project directory
after login hit this ionic package build android
after successful your apk file store in your cloud and download it and install
The Path as mentioned before is the correct path to find your generated apk file.
yourProject/platforms/android/build/outputs/apk/android-release-unsigned.apk
Please check these steps if there something missing.
I. Development environment dependencies
1)You need at Least to download a java JDK 8
2)Download an Android SDK manager
3)you must Add them to the environment variables
(Windows)
i)Open environment variables
ii)ANDROID_HOME:create a new user variable with name ANDROID_HOME and add the path of the SDK manager
ex.C:\xxx\Android\sdk
iii)edit the user variable PATH value and add to it platform tools path ex. C:\xxx\Android\sdk\platform-tools
iV)JAVA_HOME:Don't forget also to edit in the user variable PATH, your old JAVA_HOME env path with the new JDK Path . ex.C:\Program Files\Java\jdk1.8.0_144
4)Globally install ionic and cordova
npm install -g ionic cordova
II. Ionic CLI for build android
5)ionic cordova platform add android
6)ionic cordova build android
N.B: there sometimes logging in issue through CLI when using this command, the next steps doesn't really make sense but it worked for me.
ionic config set backend pro -g
Retry the build process again ,if Still there a problem change to legacy and Then again back to pro
ionic config set backend legacy -g
ionic config set backend pro -g
It should work now, retry the build process again.
If still there a problem then make an app through the website of ionic
use this command with the --pro-id of your app and retry again.
ionic start --pro-id <ID>
Follow this steps
Run ionic cordova build --release android
Open android studio go to Build -> Generate Signed APK, press next
If you don't have Key store please create new one
Finish
you can find the APK under Platforms/android
While trying to do a release using the following command:
code-push release-cordova myApp android
I'm getting the following error in the terminal:
Running "cordova prepare" command:
[Error] Unable to prepare project. Please ensure that this is a Cordova project and that platform "android" was added with "cordova platform add android"
Any one knows what might be wrong? The project is a cordova project created using the command:
cordova create myApp
And also has android platform added.
UPDATE :
Running cordova prepare android --verbose returns the following output :
Executing "before_prepare" hook for all plugins.
Searching PlatformJson files for differences between project vs. platform installed plugins
No differences found between project and android platform. Continuing...
Generating config.xml from defaults for platform "android"
Wrote out Android application name to "HelloCordova"
Wrote out Android package name to "io.cordova.hellocordova"
This app does not have launcher icons defined
updated project successfully
Executing "after_prepare" hook for all plugins.
Make sure your Nodejs is the last version.
code-push-cli required "child_process"
That error indicates that the current working directory didn't represent the root of a Cordova project at the time that you ran the release-cordova command. Can you make sure that you CD into the directory that contains the www, platforms, plugins, etc. directories, and then run the release-cordova command? That should do the trick for you
I have a Meteor Cordova Android app which I'm trying to migrate and build using Crosswalk. I followed the steps from here:
https://meteor.hackpad.com/Building-Meteor-app-with-Crosswalk-kHKh4DzGxFQ
Until here, the build succeeds.
android update project --subprojects --path . --target "android-19"
ant debug
cd ..
ant clean
The next step, ant release or ant debug, the build fails with 100 javac errors. The error log is very close to whats mentioned here: https://github.com/meteor/meteor/issues/3076
The solution partly is here:
https://github.com/RayHuo/MyXwalk/wiki/MIGRATE-AN-EXISTING-CORDOVA-APPLICATION-TO-CROSSWALK-WITH-CORDOVA-3.4-OR-LATER.
Its says:
"And the solution is to changing the second ant debug to cordova build android"
But the android project folder is generated by Meteor and not Cordova, so I do not have cordova executable installed to run a cordova build android.
I still tried installing cordova separately and building it, but it simply says, 'its not a cordova based project'.
How do we do the last step using Meteor? There is another option to build it using Eclipse/ADT, but I want to figure this out within the Meteor build process.
I know I'm missing something simple here. Any help is greatly appreciated!
Thanks.
crosswalk provides a HelloWorld cordova/example via the bin/create
utility on the intel crosswalk website.
that CordovaLib directory can replace the meteor equivalent
,however the latest meteor version fails, so there maybe some
crosswalk/meteor version problems now to resolve.
HelloWorld appears to work with old version 8 crosswalk
and new meteor build
https://crosswalk-project.org/documentation/cordova/develop_an_application.html
Meteor 1.2 now supports CrossWalk with $ meteor add crosswalk