I am finding it extremely difficult to get my heard around signing my app under the new cordova 5.0 guideline
this is what i have done
(bongoapp)project root
->build.json
->phistoKey.keystore
->www
this is what i have inside my build.json file
{
"android": {
"release": {
"keystore": "phistoKey.keystore",
"storePassword": "",
"alias": "phistoKey",
"password" : "",
"keystoreType": ""
}
}
}
when i try
cordova build --release
or
cordova build android --release
I get error stating
Keystore file does not exist: C:\wamp\www\towncrier\platforms\android\..\..\phistoKey.keystore
I will be glad if anyone can help cos I am on a deadline TODAY. thank you
The way I do it in new Cordova CLI (with gradle) is using the options that cordova give us for doing it without make our own script or doing it manually in different steps. In my case, I have created a file in platforms/android directory, with the name release-signing.properties. The content of this should be the configuration for signing your apk, something like:
key.store=/PATH/TO/YOUR/KEYSTORE
key.alias=your_alias
key.store.password=key_store_pass
key.alias.password=key_store_alias
With this file created, you just need to run the standard command, cordova build android --release, and it will generate new release APK in your output directory (platforms/android/outputs/apk/yourapp-release.apk)
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
I do the following in a shell script to build and sign an APK. This assumes that the app is named "bongoapp" and that your Cordova project and keystore file (phistoKey.keystore) are located in the same folder as the shell script.
# Run this script in the bongoapp folder to build and sign a release APK.
# Hint: the password is "bongoapp"
# Build the release APK
echo "Building Android release APK"
cordova build android --release
# Sign the APK
echo "Signing Android release APK"
jarsigner -verbose -certs -sigalg SHA1withRSA -digestalg SHA1 -keystore phistoKey.keystore platforms/android/ant-build/MainActivity-release-unsigned.apk bongoapp_alias
jarsigner -verbose -certs -verify platforms/android/ant-build/MainActivity-release-unsigned.apk
zipalign -v 4 platforms/android/ant-build/MainActivity-release-unsigned.apk platforms/android/ant-build/bongoapp.apk
echo "Done, output file is located here -> platforms/android/ant-build/bongoapp.apk"
Related
I've built a signed apk with cordova build --release android, should I zipalign it or did cordova already do all the job?
I know this is an old question, but figured I'd pitch the answer:
Cordova let's you hook on the "after_build" event, in which you can run a .bat file which will handle the zipalign.
Example (config.xml):
<hook type="after_build" src="zipalign_release.bat" />
The "src" is relative to project root (ie: same place config.xml resides).
My .bat:
if exist platforms\android\app\build\outputs\apk\release (
cd platforms\android\app\build\outputs\apk\release
zipalign -f -v 4 app-release.apk app-release-zipaligned.apk
) else (
echo Debug build.
)
no, you should zipalign it using the command prompt zipalign -v 4 app-release-unsigned.apk app-release.apk
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.
Walkthrought with react-native tutorial (react-native 0.30):
I created app which couldn't be installed on android device here are steps:
react-native init demo
cd android
gradlew assembleRelease
Copying unsigned apk to mobile device ( htc m8 mini 2 )
and got result : Application demo was not installed
Based on this similiar question apk didn't run on mobile android react native:
Unsigned apk won't install on mobile.
But why I am able to run unsiged application made by Ionic 2?
Whats the problem?
In Ionic 2 you run a debug apk, its not possible to run an unsigned apk.
What you can do in react is sign your apk and run.
The first setup can be a little complex, but after you complete the setup is very easy to generate a signed apk when you need it.
You can follow these instructions to sign your apk:
Generating a signing key
You can generate a private signing key using keytool.
$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
This command prompts you for passwords for the keystore and key, and to provide the Distinguished Name fields for your key. It then generates the keystore as a file called my-release-key.keystore.
The keystore contains a single key, valid for 10000 days. The alias is a name that you will use later when signing your app, so remember to take note of the alias.
Note: Remember to keep your keystore file private and never commit it to version control.
Setting up gradle variables
Place the my-release-key.keystore file under the android/app
directory in your project folder.
Edit the file ~/.gradle/gradle.properties and add the following
(replace ***** with the correct keystore password, alias and key
password),
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=*****
MYAPP_RELEASE_KEY_PASSWORD=*****
These are going to be global gradle variables, which we can later use in our gradle config to sign our app.
Note about saving the keystore: Once you publish the app on the Play
Store, you will need to republish your app under a different package
name (losing all downloads and ratings) if you want to change the
signing key at any point. So backup your keystore and don't forget the
passwords. Note about security: If you are not keen on storing your
passwords in plaintext and you are running OSX, you can also store
your credentials in the Keychain Access app. Then you can skip the two
last rows in ~/.gradle/gradle.properties.
Adding signing config to your app's gradle config
Edit the file android/app/build.gradle in your project folder and add the signing config,
...
android {
...
defaultConfig { ... }
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
buildTypes {
release {
...
signingConfig signingConfigs.release
}
}
}
...
Generating the release APK
Simply run the following in a terminal:
$ cd android && ./gradlew assembleRelease
Gradle's assembleRelease will bundle all the JavaScript needed to run your app into the APK. If you need to change the way the JavaScript bundle and/or drawable resources are bundled (e.g. if you changed the default file/folder names or the general structure of the project), have a look at android/app/build.gradle to see how you can update it to reflect these changes.
The generated APK can be found under android/app/build/outputs/apk/app-release.apk, and is ready to be distributed.
Testing the release build of your app
Before uploading the release build to the Play Store, make sure you test it thoroughly. Install it on the device using:
$ cd android && ./gradlew installRelease
Note that installRelease is only available if you've set up signing as described above.
You can kill any running packager instances, all your and framework JavaScript code is bundled in the APK's assets.
#EvghenyKalkutin if you are beginner in react-native then just follow this simple step
Download chocolatey from your cmd just write this code in cmd #powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
after successfully install the chocolatey now install node.js and Python2 using chocolatey. for this use this code for install node.js choco install nodejs.install and install Python# use this code choco install python2
ok now open node.js command promt and run this code npm install -g react-native-cli to start react-native
ok now download sample project using this code react-native init AwesomeProject or react-native init HelloWorld :)
Now go to the directory where this project downloaded using cd AwesomeProject
Start android stduio and open this project and correct your gradle error if it occurs(and clean project) and connect your device with usb debugging
and check your device is available or not using this code adb devices
if device is available then convert it's port for the react native using this code adb reverse tcp:8081 tcp:8081
now perform this code npm start for the build node.js bridge
after build the node.js bridge now start your project using this code react-native run-android and here you go your sample project is run on your device
**And for unsign apk or assembleRelease just go through below step **
just write this code in node.js command prompt cd android && gradlew clean && gradlew assembleRelease
I use windows os so all this instructions are for windows os I don't know this code is same for mac os or linux os
i hope this wiil help you for start up in react-native. if any problem just comment it.
WINDOWS USERS
FOLLOW THESE INSTRUCTIONS ....IT WORKED FOR ME
Prerequisite - You must have a keystore file, If you don't have then Open cmd run keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000 follow instructions and you are done.You will have a keystore file. Now follow these steps.
1 .On windows cd android and then run gradlew assembleRelease in Editor Terminal or Command Prompt in your project directory.
2 .Find APK at this location
android/app/build/outputs/apk/release/app-release-unsigned.apk
3 .Copy this APK to bin folder of jdk installation directory ( for me directory was C:\Program Files\Java\jdk1.8.0_181\bin ) [ Basically in this step we are trying to go to the same directory as jarsigner]
4 .Also Copy your keystore file to this ( C:\Program Files\Java\jdk1.8.0_181\bin ) directory.
5 .Now Open cmd in Administrator mode and run
cd C:\Program Files\Java\jdk1.8.0_181\bin
6 .Now run
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <<your keystore file name >> <<your apk file name>> alias_name
Here goes your apk , now find your signed apk here cd C:\Program Files\Java\jdk1.8.0_181\bin . Install it, Now it should install.
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
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.