0

I am trying to sign apk by using apksigner and zipalign tools, which are located in jdk/bin folder. I have already set path environment variable to it. Now what I want to do is, execute some shell commands which signs my apk through java code in ubuntu. Commands are,

command-1 :

keytool -genkey -v -keystore /Desktop/my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias app

This command required some inputs at run time, like first name last name etc.

command-2 :

./zipalign -v 4 inputAPK.apk outputAPK.apk

command-3 :

apksigner sign --min-sdk-version 15 --ks my-release-key.jks outputAPK.apk

command-4 :

apksigner verify --min-sdk-version 15 outputAPK.apk

All above 4 commands I want to execute it through java code in ubuntu environment, how can I achieve it?

4
  • Whats the problem that you're facing? Commented Nov 25, 2016 at 11:51
  • Actually I am new to java programming, so don't know the exact solution for it, I mean how can I execute above 4 commands through java program and also at runtime how can I send inputs to the command line in ubuntu. Commented Nov 25, 2016 at 11:56
  • 1
    Possible duplicate of Run cmd commands through java Commented Nov 25, 2016 at 13:16
  • I tried with the link you suggested but while running second command getting exception like, java.io.IOException: Cannot run program "zipalign -v 4 myInput.apk myOutput.apk": error=2, No such file or directory Commented Nov 26, 2016 at 5:30

1 Answer 1

1

Oh k. You can use java.lang.Runtime.exec to run simple code. Have a look at these sites:

http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#exec(java.lang.String)

http://alvinalexander.com/java/edu/pj/pj010016

https://www.mkyong.com/java/how-to-execute-shell-command-from-java/

Also you can use Process.getOutputStream() method to get input. Whatever data you enter will be passed to your input stream.

Sign up to request clarification or add additional context in comments.

6 Comments

I tried with the link you suggested but while running second command getting exception like, java.io.IOException: Cannot run program "zipalign -v 4 myInput.apk myOutput.apk": error=2, No such file or directory
In that case either you are pointing to a wrong location as the error says... or you need to do this - sudo apt-get update sudo apt-get install gcc-multilib lib32z1 lib32stdc++6
zipalign tool is located in Android/sdk/build tools/24.0.3/zipalign. I have already located this path in environment variable, but even though not working.
How about your OS? x64 or x32.? Also check your build.xml.
Hey! this post may help you.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.