android create project --name YourProjectName --path C:\dev\YourProject --target android-3 --package com.company.testproject --activity MainActivity
i want to compile it with command line in windows.
Any Ideas ?
i think your question is Duplicate, anyway this is for Bash tag, because you added in question !.
requirements for linux example (Debian base) :
sudo apt-get install lib32ncurses5 lib32stdc++6
sudo apt-get install ia32-libs
also :
android update sdk -u -t platform-tools
android update sdk -u -t name_of_android_target_platform
Target platforms are named like android-7, for Android API level 7. If you need a non-android platform (for example: Google Inc.:Google APIs:7) then you need to find its numeric id.
Generate ./local.properties and ./build.xml based on your ./project.properties
android update project --path .
If you also need to generate ./project.properties (though normally you should have it in source control), you can do that with :
android update project --path . --target 'Google Inc.:Google APIs:7'
Build debug apk :
ant debug
Build release APK:
ant release
and this is for Creating keystore :
keystore=$projectname.keystore
alias=mykey
storepass=some_new_password
keypass=some_new_password2
keytool -genkey -v -keystore $projectname.keystore -storepass $storepass -keypass $keypass -validity 10000 -keyalg RSA
Create signed release APK :
jarsigner -verbose -keystore $keystore -storepass $storepass -keypass $keypass bin/$projectname-release-unsigned.apk $alias
rm -f bin/$projectname-release.apk
zipalign -v 4 bin/$projectname-release-unsigned.apk bin/$projectname-release.apk
Usefull Resources :
Building Android application (.apk) from the Command Line
How to compile APK from command line?
Building and Running from the Command Line (from developer.android.com)
Cheers.!:)
Related
I've an app created using react native. I am trying to install the app on my device.But showing this error "app not installed -package appears to be corrupted".
What would be the reason? I've tried the following method to build apk.
gradlew assembleRelease.
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
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 . Run it, Now it should install.
For me the reason that my phone already had a version of the app installed on it.
Once I remove the app - reinstall the apk it went smoothly.
This will help: - on Latest android studio
Go to Build-> Build Apk(s).
After creating apk you will see a dialog as below.
Click on locate and install it on your phone
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 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 tried to figure out how i can see the SHA-1 fingerprint, according to the Google guide https://developers.google.com/maps/documentation/android/start, I should do the following
For Windows Vista and Windows 7, run:
keytool -list -v -keystore "C:\Users\your_user_name.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android "
But I cannot understand where i should run this trial in windows?
You need to run it directly in the bin sub-directory of your Java JDK directory (e.g. for me it is C:\Java\jdk1.6.0_37\bin) or add the bin directory to your PATH environment variable. If you do the latter, you can run the command from any command line prompt.
Is there a way to excecute the Eclipse command "Android Tools -> Rename Application Package" as a script from the shell?
I want to compile my Android application several times with different options (e.g. free and paid version) without doing some things manually.
It is important to do this automatically. All solutions like libraries won't help because several things have to be done by hand.
Yes, it is possible. You have to manually call aapt tool to package the compiled project, then call aapt again to add the classes, sign it with jarsigner and align it with zipalign. Normally, the Eclipse ADT plugin does the chain of build steps for you.
Example calls of the steps would be following.
Packaging the app with different package name:
aapt package -f -M ./AndroidManifest.xml -S res/ \
-I android.jar -F renamed_project.apk.unaligned \
--rename-manifest-package "com.example.some_new_package" -v
Then add the classes:
aapt add -f renamed_project.apk.unaligned classes.dex -v
Sign it:
jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 \
-keystore "some_keystore_file" \
renamed_project.apk.unaligned "key_name"
Align it:
zipalign -v 4 renamed_project.apk.unaligned renamed_project.apk
Some more information can be found for example here.
Also you can do it more easily with Ant. Here you can find some more information.