How to unzip, edit and zip an android apk - android

I have an android apk and I deleted my source code and dont have the project again, I want to change the version code of the old apk. my question is how do I unzip and repack the apk so I can use the. am using a mac system. I saw so many things for windows but i couldnt find for mac.I need help please

unzip apk files
The simplest method is executing unzip command:
unzip xxx.apk -d xxx
A directory xxx will be generated to store unzipped files.
Actually, .apk files are same as .zip files. Execute command file XXX.apk to see that.
get readable text files from apk
If you want readable text files such as the manifest file, I would suggest you to use the apktool. We could install the apktool easily with Homebrew:
brew install apktool
then get the readable text files:
apktool d xxx.apk
after the previous command, a xxx directory contains readable text files and others would be there.
edit zip files
If you want to edit a zip file in place, the Keka might be a good option.

To give a complete answer for unpacking, editing and packing on Mac:
Unpacking / Unzipping
As Liu Tao stated, the easiest way to unpack a *.apk file on mac is to use the following command:
unzip xxx.apk -d xxx
This is because an *.apk file is nothing else than a zip file. Again, as Liu Tao stated, this can be found out with the file command.
file xxx.apk
Which will show an output that looks something like this:
xxx.apk: Zip archive data, at least v2.0 to extract
Editing
I think this is self-explanatory. Go into the folder to which you exported the *.apk contents and edit them as you would usually do.
Packing / Zipping
On Mac, this is also quite straight-forward.
You can use the zip command to pack all the files back into an *.apk file.
zip -r xxx.apk xxx/

You want to use APKTool. It will handle the unzip and rebuild for you: http://ibotpeaches.github.io/Apktool/

Related

Generate Universal APK from Android App Bundle

I have an app bundle file, now I want to generate a universal APK that can be installed to all devices. I have tried to use this command to generate universal APK:
$bundletool build-apks --bundle=myapp_bundle.abb --output=myapp.apks --universal
However, what I got is .apks (not .apk) where I cannot install directly to any devices. Anyone know how to get a universal .apk file instead of .apks?
Thank you very much.
Use --mode=universal in place of --universal. For example, you can run something like this:
bundletool build-apks --bundle=myapp_bundle.aab --output=myapp.apks --mode=universal
At the end you have myapp.apks, this file is something like a zip file. You can extract the content into a folder, for example:
unzip out.apks -d apks
Now in the folder apks you have only one apk, in my case universal.apk, that you can install as usual on any device.
Use either the extract-apks or the install-apks command to respectively extract the APK from the APK Set to a directory, or install them on a connected device.
Alternatively, just unzip the .apks using your favourite zip tool. But that might not always work in the future.

Where is Android SDK download cache folder?

The goal here is to copy and paste downloaded Android SDK packages to multiple computer and run ./sdkmanager 'xxx' to install them locally (with no access to dl.google.com).
I tried ~/Library/Android/sdk/temp and ~/.android/tmp with no luck.
On linux it is in /tmp/PackageOperationX where X is a number.
MacOS
commandline sdkmanager
the temporary files will be downloaded to /private/var/folders/ when regular professional users couldn't comprehend how this decision can be made by developers of this commandline tool and MacOS, and still not informing their users in documentation
For example, to find out the file while sdkmanager is downloading the package system-images;android-29;google_apis;x86_64, with zip file named "x86_64-29_r11.zip":
lsof | grep x86_64-29_r11.zip
## output
java 5422 username 35w REG 1,7 408368096 19062984 /private/var/folders/t7/z9lknwrd31q55t9m7s4qhm140000gp/T/PackageOperation02/x86_64-29_r11.zip
Using find also can work, but if you are searching for / it will take longer, so you can try on /private directly
sudo find / -name "*x86_64-29_r11.zip*" 2> >(grep -v 'Operation not permitted' >&2)
sudo find /private -name "*x86_64-29_r11.zip*" 2> >(grep -v 'Operation not permitted' >&2)
Source for coming up with the solutions:
See what process is using a file in Mac OS X
How can I exclude all "permission denied" messages from "find"?
Android Studio SDK Manager
the location for temporary storage of packages downloaded is $HOME/Library/Android/sdk/.downloadIntermediates and will be moved to $HOME/Library/Android/sdk/.temp/PackageOperation0X for extracting operation where X is a number. These packages will be deleted once they are extracted to their respective directories.

apptool decompile with AND APKTOOL

i want to decompile my recent apk to test is it.
i run the code
C:\Users\admin\apktool d OwnApp.apk
but it's getting error with :
Input file (OwnApp.apk) was not found or was not readable.
why am i getting this?
Procedure for decoding .apk files, step-by-step method:
Step 1:
1). Make a new folder and copy over the .apk file that you want to decode.
2). Now rename the extension of this .apk file to .zip (e.g. rename from filename.apk to filename.zip) and save it.
3). Now you can access the classes.dex files, etc. At this stage you are able to see drawables but not xml and java files, so continue.
Step 2:
1). Now extract this .zip file in the same folder (or NEW FOLDER).
2). Download dex2jar and extract it to the same folder (or NEW FOLDER).
3). Move the classes.dex file into the dex2jar folder.
4). Now open command prompt and change directory to that folder (or NEW FOLDER). 5). Then write d2j-dex2jar classes.dex (for mac terminal or ubuntu write ./d2j-dex2jar.sh classes.dex) and press enter.
6). You now have the classes.dex.dex2jar file in the same folder.
7). Download java decompiler, double click on jd-gui, click on open file, and open classes.dex.dex2jar file from that folder: now you get class files.
8). Save all of these class files (In jd-gui, click File -> Save All Sources) by src name. At this stage you get the java source but the .xml files are still unreadable, so continue.
Step 3:
1). Now open another new folder
2). Put in the .apk file which you want to decode
3). Download the latest version of apktool AND apktool install window (both can be downloaded from the same link) and place them in the same folder
4). Open a command window apktool d myApp.apk (where myApp.apk denotes the filename that you want to decode)
5). now you get a file folder in that folder and can easily read the apk's xml files.
this solutions is extracted from this StactOverflow site Check Here
you can download all the required libraries from here libraries
Recompiling apk using apktool for MAC:-
Process to DeCompile APK(Android Package):
Open terminal and cd to apk directory
type su
apktool d <../../pathToMyAPK>
Process to ReCompile APK(Android Package):
Open terminal and cd to apk directory
type su
apktool b <../../pathToMyAPKFolder>
New apk is generated in  pathToMyAPK/dist/NewAPP.apk
->Now we need to sign the apk to be able to port to device.
To sign an apk:
jarsigner -verbose -keystore <path of my-keystore.keystore> <path of apk> alias_name
For Decompile, Run Apktools Over CMD like C:\\example: apktool d x.apk

Android unzip archive that contains symlink

I've been working on something that requires me to extract files from a zip archive on an Android system that contains symlinks.
When I try to create an archive using zip --symlinks command on the Android filesystem, the symlinks are stored correctly.
When I try to extract the files on a Linux system, ls shows that the symlink links point to the correct place (e.g symlink -> /storage/emulated/legacy).
However, when I use unzip in the adb shell, the extracted symlink don't point to the desired location.
How can I extract the symlinks and make them point to the location they pointed before they were archived? Is it even possible?

Modified and re-signed app doesn't retrieve file names

I have "updated" an old Mac to Mac OS X 10.7.5. I have installed JDK 1.7.0_72 on this Mac. I'm trying use a LiveCode standalone application on my old Android tablet with Android version 2.3.3.
The unmodified standalone, built with the option "sign for development only" runs fine on my tablet, but video won't display.
First, I built the app for Android, using LiveCode 6.6.2 for Windows. Then I copied it over to my Mac. I used
$ java -jar apktool.jar decode /Volumes/Macintosh\ HD/Users/User/Desktop/apk\ tool/MyApp.apk app
to decompile the apk file. It appeared in a folder with the name "app" in my Home directory, with subdirectories:
app
AndroidManifest.xml
apktool.yml
assets/
doc/
links.txt
pic/
vid/
Demos/
Examples/
Other/
Simple Animation.mp4
Vimeo Pro Example.html
Tutorials/
SQL.html
build/
lib/
res/
smali/
The contents of the assets folder is included by LiveCode's standalone builder. I created all of these files and folders during project development. The folders in the vid folder contain several HTML files and one mp4 file. I have listed only a few of the html files in the file tree.
I changed the file AndroidManifest.xml by replacing the line
<application android:label="MyApp" android:debuggable="false">
with
<application android:label="MyApp" android:debuggable="false" android:hardwareAccelerated="true">
After this, I rebuilt the app, using apktool again. I used sudo, because here it said I had to use sudo:
$ sudo java -jar /Volumes/Macintosh\ HD/Users/User/Desktop/apk\ tool/apktool_1.5.2.jar b -a /Volumes/Macintosh\ HD/Developer/android-s-d-k-mac_x86/platform-tools/aapt
It appears that if you use sudo once, you have to use sudo all the time. So, now I had to sign it using
$ sudo jarsigner -verbose -sigalg SHAwithRSA -digestalg SHA1 -keystore /Volumes/Macintosh\ HD/Users/User/app/dist/MyApp.apk myalias
I verified that it was signed and changed the name of the file then aligned the file
/Volumes/Macintosh HD/Users/User/app/dist/MyApp.apk
to
/Volumes/Macintosh HD/Users/User/app/dist/MyApp_unaligned.apk
I aligned the file using
$ zipalign -v 4 /Volumes/Macintosh\ HD/Users/User/app/dist/MyApp_unaligned.apk /Volumes/Macintosh\ HD/Users/user/app/dist/MyApp.apk
This file should work on my Android tablet. I'm able to start and run the file, but my app doesn't see any of the files in the sub folders of folder vid/, except for Simple Animation.mp4. However, it does notice that there are files. A repeat loop that checks all folders in folder vid/ for files creates a list, but the lines in the list are empty, one line for each file, meaning that it can't figure out what the names of the files are. Needless to say, I checked that all files are included in the new apk file.
What may cause this?
If you wonder about the file paths: I started my Mac from an external disk and used the files on the internal disk. So, /Volumes/Macintosh HD isn't the system disk here.

Categories

Resources