I am using ionic framework to generate apk for android platform.
After running ionic build android, an android-debug.apk is generated. How can I generate a non-debug apk which is smaller and faster?
This is my android release shell script
IFY
clear
gulp
ionic build --release android
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore "path/to/your/keystore" "platforms/android/build/outputs/apk/android-release-unsigned.apk" "keystore alias" -storepass xxx -keypass xxx
/path/to/android-sdk/build-tools/23.0.2/zipalign -v 4 "platforms/android/build/outputs/apk/android-release-unsigned.apk" "android-release.apk"
rm "platforms/android/build/outputs/apk/android-release-unsigned.apk"
In cordova 6.2.0 you can release an apk with follwoing commands. Since ionic is a wrapper around cordova, this should work.
cd cordova/ #change to root cordova or ionic folder
platforms/android/cordova/clean #clean if you want
cordova build android --release -- --keystore="/path/to/keystore" --storePassword=password --alias=alias_name #password will be prompted if you have any
As ionic CLI is based on cordova CLI, you can use, directly:
ionic build android --release
Also, if you are worried about optimization, you might find interesting usign zipalign, in order to align data on 4-byte boundaries, thus causing the app to reduce the amount of RAM used. Once you have build the release apk with the previous command, you can run:
zipalign -v 4 yourReleaseApp.apk zipalignedReleaseApp.apk
Basically, as Jan commented, you should use the command: cordova build android --release. You can take a look at the official guide from Ionic about how to publish your app.
1. To release build for Android, we can use the following cordova cli command
ionic cordova build --release android
2. Build apk is unsigned. Need to sign it. That’s why create private key with keytool of JDK. we can use following cli command
keytool -genkey -v –keystore mykey.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
keep the mykey.keystore file in a safe place for future use.
if the keytool is not work then copy path of this file and set it in the system environment variable.
3. Now sign the unsigned apk with the following command
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore mykey.keystore projectpath\platforms\android\build\outputs\apk\android-release-unsigned.apk alias_name
4. At last optimize the apk file.
zipalign -v 4 projectpath\platforms\android\build\outputs\apk\android-release-unsigned.apk projectpath\platforms\android\build\outputs\apk\android-release.apk
for more details you can visit following url
Build Release APK of Android Application from ionic
Related
I made the application using Ionic Cordova
Now I want to assemble it and suggested that I create a key at the assembly stage.
On the official site it offers to execute the command in the console
$ keytool -genkey -v -keystore MY-RELEASE-
KEY.keystore -alias MY_ALIAS_NAME -keyalg RSA -keysize 2048 -validity 10000
but where exactly should it be performed?
In what directory is the nada?
Do I need to install android SDK or android Studio.
Who had the experience of building applications, tell me how to do everything correctly
Keytool and jarsigner comes with the java jdk. You can run it wherever you want.
The zipalign tool can be found in /path/to/Android/sdk/build-tools/VERSION/zipalign. For example, on OS X with Android Studio installed, zipalign is in ~/Library/Android/sdk/build-tools/VERSION/zipalign
Just follow everything here. Of course you need JDK
https://ionicframework.com/docs/v1/guide/publishing.html
I have developed an app with Ionic 2 and would like to test it on an Android phone. Thus in my bash CLI, I tried to run several commands to build the APK, such as:
ionic cordova build android --release
ionic cordova build --release android
ionic cordova build android --release --prod
ionic cordova build android --prod
In the end, the APK file is generated, but when I transfer it on my android phone, it says the app is corrupted and it won't run.
Any ideas how to fix my problem? Thanks.
EDIT: I also tried to plug my phone by USB. adb devices returns a list showing that my device is indeed connected. Then I ran ionic cordova run android, but I get an error : Your Android platform does not have api.js.
ionic info output:
global packages:
#ionic/cli-utils : 1.4.0
Cordova CLI : 7.0.0
Ionic CLI : 3.4.0
local packages:
#ionic/app-scripts : 1.3.7
#ionic/cli-plugin-cordova : 1.4.0
#ionic/cli-plugin-ionic-angular : 1.3.1
Cordova Platforms : browser broken ios 4.4.0
Ionic Framework : ionic-angular 3.1.1
System:
Node : v6.10.3
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
npm : 3.10.10
I was facing the same issue, after a long R&D, I found the issue. As per my understanding, the issue is not with the Android build, its the generated unsigned APK that you are running on your mobile device. The fact is that system will not allow to install an application with unsigned instead, it will show the corrupt message. So whether you want to upload your application to Google Store or not you have to make the application signed so that the system will at least allow the application to install into the mobile device.
Kindly refer below step to generate signed APK
Step 1: Open command prompt and go to the JDK path's bin folder
Step 2: Now we need to create a new certificate/keystore to generate your private key using the keytool command that comes with the JDK.
keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize
2048 -validity 10000 -alias my-alias
Or you can specify particular drive/folder where you want to generate keystore file
keytool -genkey -v -keystore D:\my-release-key.jks -keyalg RSA
-keysize 2048 -validity 10000 -alias my-alias
You’ll first be prompted to create a password for the keystore. Then, answer the rest of the nice tools' questions and when it’s all done, you should have a file called my-release-key.jks created in the current or specified directory.
Note: Make sure to save this file somewhere safe, if you lose it you won’t be able to submit updates to your app!
Step 3: To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore
my-release-key.jks android-release-unsigned.apk my-alias
Or use below one, do forgot to specify the exact path to keystore.jks and app-release-unsigned.apk file
jarsigner -verbose -sigalg SHA1withRSA -d igestalg SHA1 -keystore
D:\ionic_apk\my-release-key.jks
D:\Ionic...\platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk
my-alias
That's it, you have just build a signed APK. Rename the APKfile if required. Copy that on your mobile device and install it.
So if you want to optimize you APK, then we need to run the zip align tool which can be found in /path/to/Android/sdk/build-tools/VERSION/zipalign. For example, on OS X with Android Studio installed, zipalign is in ~/Library/Android/sdk/build-tools/VERSION/zipalign:
zipalign -v 4 android-release-unsigned.apk HelloWorld.apk
To verify that your APK is signed run apksigner. The apksigner can be also found in the same path as the zipalign tool:
apksigner verify HelloWorld.apk
Please use this guide: https://developer.android.com/studio/publish/app-signing#signapp
As #Prashob Thekkyal correctly have guessed, you have to signed the app before it can be installed by Android Nougat. That being said, jarsigner refuse to sign an apk file. You have to use the apksigner utility that is present in the android build-tools.
Cordova Platforms should be android x.x.x in your case.
Check root/platforms/platform.json it should be
{
"android": "x.x.x"
}
Make sure your android folder is in right place(root directory/platforms/android).
Try removing and adding the platform again.
I am trying to build a signed apk for Android platform using cordova.
I have already created unsigned apk using cordova --release android.
But i am unable to sign usejarsigner and zipalign.
kindly help.
I have already solved my problem.
I am explaining its steps for the people who are still stuck in it:
Create a unsigned apk.
Run this command cordova --release android after getting to the location of the project.
You can find the unsigned apk in
project_name\platforms\android\build\outputs\apk\android-release-unsigned.apk
Copy this apk and keystore tool in one folder.
Navigate to the folder and sign it using jarsigner present in java.
Run this command,
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <keystorename <Unsigned APK file> <Keystore Alias name>
After this you will be prompt to enter password of keystore.
Go to location of zipalign.
(it is present in Android\SDK\build-tools\version)
Run this command
zipalign -v 4 "location of signed apk" "location of aligned apk"
I'm trying to generate my release apk to deploy it on Play Store.
I'm running this command
Sudo cordova build android --release
Which is generating me a file named Android-Release-Unsigned.apk
I tried many solutions, like creating keystore
keytool -genkey -v -keystore key-name.keystore -alias alias-name -keyalg RSA -keysize 2048 -validity 10000
or the trick of creating a Ant.properties file like here and none of them worked at all.
Any other possible solution for this ? Cordova version is 5.1.1
Create a file called release-signing.properties and put in APPFOLDER\platforms\android folder Cordova used to use ant.properties but now ignores that file.
Contents of the file: edit after = for all except 2nd line
storeFile=C:/yourlocation/app.keystore
storeType=jks
keyAlias=aliasname
keyPassword=aliaspass
storePassword=password
Now running cordova build android --release should produce a signed version.
If you have keystore file generated, this should work.
You may also need to remove console plugin if the same apk directly goes to production.
In cordova 6.2.0
cd cordova/ #change to root cordova folder
platforms/android/cordova/clean #clean if you want
cordova build android --release -- --keystore="/path/to/keystore" --storePassword=password --alias=alias_name #password will be prompted if you have any
Sorry I couldn't comment. Possible duplicate?
How to create a signed APK file using Cordova command line interface?
This worked perfect for me.
I'am trying to build the final release version of my app that using phonegap 3.0 and a few plugins. I have followed this answer on SO to link my keystore file to the app however I am not sure this is working.
Everything runs locally when I use phonegap run android.
Into myapp/platforms/android I have placed ant.properties
key.store=/Users/XXXXX/Desktop/keystore/my-release-key.keystore
key.alias=FishAppKey //I wasn't sure as it is suggested this can be whatever.
When I build my app instead of placing the .apk files into platforms/android/bin they are put into platforms/android/ant-build?
When I move into platforms/android and run ant release I get Build failed ...tools/ant/build.xml:698:null returned 1
Really I am trying to figure out how to go from phonegap run android to a apk file I can upload to google play.
As answer to your comment, you use jarsigner and pass the full path to your keystore in the -keystore argument. So let's say your keystore is on the desktop and named yourkeystore.keystore,
On Windows you would :
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore %userprofile%\Desktop\yourkeystore.keystore yourappname-release-unsigned.apk youraliasforthekeystore
On linux (and probably OSX also):
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore $HOME/Desktop/yourkeystore.keystore yourappname-release-unsigned.apk youraliasforthekeystore
And of course you can replace yourappname-release-unsigned.apk with the full path of your apk in case it's not in the current directory.