Android: Rename Package in Eclipse - android

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.

Related

Publishing Ionic app - Zipalign not working

I am trying to get my Ionic app published. However, when trying to zipalign the apk with the following command
/Users/bertcarremans/Library/Android/sdk/build-tools/23.0.3/zipalign zipalign -v 4 android-release-unsigned.apk chartly.apk
I get the message below:
Zip alignment utility
Copyright (C) 2009 The Android Open Source Project
Usage: zipalign [-f] [-p] [-v] [-z] <align> infile.zip outfile.zip
zipalign -c [-v] <align> infile.zip
<align>: alignment in bytes, e.g. '4' provides 32-bit alignment
-c: check alignment only (does not modify file)
-f: overwrite existing outfile.zip
-p: page align stored shared object files
-v: verbose output
-z: recompress using Zopfli
How can I make the zipalign tool to work? Thanks!
I found the solution.
Copy the zipalign tool to the apk folder of your app. On my computer the zipalign tool was located in /Users/bertcarremans/Library/Android/23.0.3
Then run the command ./zipalign -v 4 android-release-unsigned.apk chartly.apk
There is no need to copy zipalign file anywhere, if it is installed through command line a symbolic link will be created and then you can run it from anywhere.
You are not using the right syntax of the zipalign tool. Please check again, you have written zipalign twice so you are passing zipalign as a parameter to zipalign command which is not correct.

How to compile Android Project's with Windows command line using script?

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.!:)

zipalign: command not found - Ubuntu

I am trying to zipalign an "input.apk" file on an Ubuntu 14.04 LTS system using the command line as I do not have access to the source code just yet. If I'm not mistaken I should be able to do this with the following command
zipalign [-f] [-v] 4 intput.apk output.apk
but I am getting the following output
zipalign: command not found
I have made sure that the zipalign file is in my ...sdk/tools directory which I had to copy over from my ...build-tools/android-4.4W folder because it was originally missing. When I input this line as suggested in another question
./zipalign [-f] [-v] 4 intput.apk output.apk
I get the following output
Zip alignment utility
Copyright (C) 2009 The Android Open Source Project
Usage: zipalign [-f] [-v] <align> infile.zip outfile.zip
zipalign -c [-v] <align> infile.zip
<align>: alignment in bytes, e.g. '4' provides 32-bit alignment
-c: check alignment only (does not modify file)
-f: overwrite existing outfile.zip
-v: verbose output
Does this mean that I need a .zip file instead of my .apk to zipalign?
When a usage message contains an argument in brackets, the brackets mean that that argument is optional and can be left out of the final command; the brackets are not themselves part of the command syntax.
In your case, correct usage might look like:
./zipalign -v 4 intput.apk output.apk
In terminal,
cd /opt/android-sdk/build-tools/21.1.2
sudo ln -sf zipalign /usr/bin/
zipalign -v 4 platforms/android/ant-build/MainActivity-release-unsigned.apk platforms/android/ant-build/YOUR_APP.apk
Open terminal (CTRL + t)
cd YOUR_PATH/android-sdk-linux/build-tools/XX.X.X
sudo cp zipalign /usr/bin/
Open the folder where is located your apk in the terminal.
Execute zipalign -v 4 YOUR_APK.apk YOUR_APK.apk
I had the same issue. This is how i solved it, all you need is here.
1. Get zipalign path by getting sdk path on android studio. which is /Users/s****/Library/Android/sdk for me.
2. Paste the path on your terminal and cd to "build-tools/28.0.3/zipalign" now command will be/Users/s****/Library/Android/sdk/build-tools/28.0.3/zipalign
3. zip the apk on the same command line by adding -v 4 app-release-unsigned.apk my.apkto the command, now command will be
/Users/s****/Library/Android/sdk/build-tools/28.0.3/zipalign -v 4 app-release-unsigned.apk my.apk
4. Done.

Can't recompile working APK with APKtool

I decompiled an APK using APKTool 2.0 Beta 9 and then rebuilt all without doing changes to the sources.
Then I rebuilt the APK using this command:
java -jar apktool.jar build myfolder myapk.apk
But I cannot install the generated APK file on my phone. It tells me:
Application not installed.
Am I missing something ?
I even didn't change the code.
Your new recompiled apk is not signed and according to the rules, you cannot install unsigned apk.
One good thing which I like is that you can self sign the apk file.
You will have to use "Keytool" for generating your own certificate.
Here is the command :
keytool –genkey –v -keystore [nameofkeystore] –alias [your_keyalias] –keyalg RSA –keysize 2048 –validity [numberofdays]
This will ask you few things, just fill it appropriately.
Once the certificate is generated, use "jarsigner" for signing your apk.
jarsigner –verbose –sigalg MD5withRSA –digestalg SHA1 –keystore [name of your keystore] [your .apk file] [your keyalias]
Now try installing your new apk file and everything should work fine.
EDIT - I am using keytool and jarsigner commands directly as I have set their paths in PATH variable. In your case, you will have to traverse to "bin" folder of the jdk directory.
/bin/
You need to resign the regenerated APK file using jarsigner:
$ jarsigner -verbose -keystore my-release-key.keystore HelloWorld.apk alias_name

Asset access error in APK made by using shell script

I wrote the shell script to build APK to automate build process. It's like below.
rm -rf obj
rm -rf gen
rm -rf bin
rm -f build.xml
rm -f local.properties
rm -f proguard-project.txt
ndk-build
android update project --path ./
ant release
jarsigner -verbose -keystore path/keystore -storepass password -signedjar bin/myApp-release-signed.apk bin/myApp-release-unsigned.apk alias
Currently, I got the APK successfully. But I found sometimes app is crashed when it try to access special asset like texture image. LogCat shows the log like below.
04-10 12:46:25.080: E/szipinf(2255): Error reading asset data
04-10 12:46:25.080: E/szipinf(2255): Unable to access asset data: -1
Eclipse can build APK well. I tried to find the way to fox APK's issue. But I cannot find.
Currently, I'm using android-12 and ndk-r6b. Also I'm working on Machintosh. Is there any special guide to fix such a thing?

Categories

Resources