i have same problem whit the command:
ionic cordova build android
the process termined with successfull and it create the apk.
if i send the apk on my smartphone, it see the file same zip and not install
The app work all right, and i can test it with
ionic cordova run android
but i can not generate the apk.
My configuration:
Ionic 6.18.2
gradle 7.4
node 16.14.0
npm 8.3.1
java 1.8.0_321
can someone help me?
Related
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
CIL Version Info
node v8.4.0
cordova v7.0.1
ionic v3.9.2
I create a tabs project; then use cmd:
ionic cordova build android --prod --release
a unsigned release version apk ,signe info:
enter image description here
After signature,run apk in device (my device android version:4.4.4), Like this:
enter image description here
Anybody know what's going on?
Problem solved,use cnpm install has this Problem , use npm install no problem;
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).
I am no longer able to build my app and generate an apk anymore because an error shows up. Here is what happens when I try to build the app in the command prompt: Command Prompt
Can somebody please help me with this? Oh and this is what happens if I type ionic info in the command prompt:
Your environment has been set up for using Node.js 0.12.4 (x64) and npm.
C:\Users\Singh>ionic info
Your system information:
Cordova CLI: 5.1.1
Ionic CLI Version: 1.6.1
Ionic App Lib Version: 0.3.3
OS: Windows 7 SP1
Node Version: v0.12.4
C:\Users\Singh>
Try to remove the platform, and then add it again, and then build your application.
So, if you have android as targeted platform execute these commands:
ionic platform remove android
ionic platform add android
ionic build android
My son had a very similar problem, and we never did figure out what caused it. He ended up creating a brand new blank ionic project, and then just copying the www folder from the old project. It worked, and he was able to get things building again. If you try it, you'll also have to re-add your plugins, copy package.json and bower.json, and then rerun bower install and npm install. It's not pleasant, but it might be worth a shot if you're desperate.
When I want to try ionic weather app (https://github.com/driftyco/ionic-weather/) I've got problems when I wanted to build android to my phone-gap application using cordova. I receive this message in terminal when I execute the command cordova build android
Error: An error occurred while listing Android targets
I work on ubuntu 13.10
I was able to successfully build the project with the following steps:
npm install -g cordova ionic
git clone https://github.com/driftyco/ionic-weather/
cd ionic-weather
cordova platform add android
cordova build android
You may be missing the required android sdk tools, or they may not have been added to your system path.
Refer to this question
cordova ubuntu: An error occurred while listing Android targets
And follow this guide to ensure your environment was setup correctly.