How to rename an apk package name with aapt / apktool? - android

I'm looking to rename an apk package name with existing tools like aapt or apktool.
Found this question that is related : Rename package name using aapt
I tried to adapt the command aapt p -f --rename-manifest-package com.mynewpackagename -M AndroidManifest.xml -F myapp.apk -I android.jar -S res
But it gives an error.

You can decompile the apk using apktool: apktool d apk_path.apk and change this property in apk_path/apktool.yml
renameManifestPackage: new.package.name

If you are looking for a safe and fast rename package name solution. I recommend using "Android Package Renamer" plugin in Android Studio Or Intellij IDEA.
What you need to do is download it:
Open Your Project.
Click -> File -> Rename Package
Input the Package you want to change.
Click OK.
Sync Project with Gradle Files or Invalidate Caches
You can see the detailed answer here or go to the github of this repo

Related

Find versionnumber and versioncode of apk generated by android studio

I know that .apk files are zip files and when we extract them can parse manifest file inorder to finding some information about the app. It is very useful for someone like me that is going to create an app-store. Actually at least I can find the version name and version code of the app.
But in the android-studio when we build a signed apk the version name and version code is not defining in the manifest file. We should define them in the build.gradle file. So now in my app-store when users upload the files how can I find the version code and version name and detect that is not same with old versions?
Just use AAPT from your path/to/your/android-sdk/build-tools/your-api-version-available/...
An example of the command execution:
aapt dump badging theuserapp.apk
And it will respond with something like:
package: name='com.blabla.theuserapp' versionCode='2000' versionName='2.0.0'
Of course, as the tool is an executable which produces a raw text output you can easily script it and parse from your favorite scripting languaje.
On GNU/Linux environment you can make a bash search.
with these steps:
-> on Studio choose terminal tab;
-> change directory to root directory of your project.
-> run this command $ find pwd -name *.apk
-> yours apk files will be listed on the screen, then you can see the directory where they are hosted

Facebook Unity SDK android barfs when project connected to Asset Server

Tricky little issue. A test project with FB plugin worked fine, my project gave me below error. Turns out when i connected FB test project to asset server, and the .meta files got created for each folder, it would barf also. Any way to tell compiler to skip .meta files?
Error building Player: CommandInvokationFailure: Failed to re-package resources. See the Console for details.
/Users/me/android-sdk-macosx/platform-tools/aapt package --auto-add-overlay -v -f -m -J gen -M AndroidManifest.xml -S "res" -I "/Users/me/android-sdk- macosx/platforms/android-17/android.jar" -F bin/resources.ap_ --extra-packages com.facebook.android -S "/Users/me/Unity/FBTest/Assets/Plugins/Android/facebook/res"
stderr[
invalid resource directory name: /Users/me/Unity/FBTest/Assets/Plugins/Android/facebook/res/drawable-hdpi.meta
invalid resource directory name: /Users/me/Unity/FBTest/Assets/Plugins/Android/facebook/res/drawable-ldpi.meta
invalid resource directory name: /Users/me/Unity/FBTest/Assets/Plugins/Android/facebook/res/drawable-mdpi.meta
UPDATE: can't seem to get rid of .meta files, even though i disconnected from asset server :( any ideas?
UPDATE: had to go Edit -> Project Settings -> Editor and disable version control to get this to compile. Would be nice if this could be fixed so meta files are ignored in the packageing of an APK...
May as well mark this as answered. The .meta files added for asset server are breaking the android packaging, so the work around is to disable source control under Edit -> Project Settings -> Editor before doing a build. Be nice if this was fixed so that step was unnecessary though...
UPDATE:
Um, reconnecting to asset server makes it think everything locally has changed, so this is a really, really sucky workaround
Found a stupid workaround because I was having the exact same problem, only tested on OSX since it relies on executing a python script via the hashbang line.
Go find the path where aapt is in your android SDK (android-sdk-macosx/build-tools/17.0.0/aapt for example) and rename it to aapt.real
Make a new file called aapt and put the following in it:
#!/usr/bin/env python
import os
import sys
os.execv(os.path.join(os.path.split(__file__)[0], 'aapt.real'), ['aapt'] + sys.argv[1:] + ['--ignore-assets', '!.svn:!.git:!.ds_store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~:!*.meta'])
Wonder why Unity doesn't include the --ignore-assets option to fix this problem.
i added the line
<property name="aapt.ignore.assets" value="!*.meta:!.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~" />
to the build.xml file of the facebook android unity sdk. no need to patch android sdk.
Another workaround that seems to work is to delete all the .meta files from the res folder after starting the build, but before unity starts the packaging process. Unity will not recreate the meta files while it is building the project. This way you don't have to disable and re-enable version control.

How to modify a pre-packaged apk file on client-side by user who is using my desktop application?

Well, I know the title is not well-written, but my case is as complicated as that! I searched for this case here but other similar questions really differ from mine.
Here is my problem:
I have written an Android program which displays contents (text, images, etc. in raw format) that is stored in "assets" folder. Now I want to deliver this app along with a windows application (also written by me) to end users, which lets them add contents to "assets" folder of the apk file and output the modified apk with their desired name (to appear on their phone).
Now what is best solution to do this and which tools and commands I should use? I mean which tools (aapt, jarsigner, ...) I should include in my software and which commands must be launched by my software to do this?
More info about my case:
My users aren't advanced and don't know anything about Android programming and modifying apk, and I want them to only use my client windows application.
I want not to use JDK, JRE, ... on client's machine.
Modification process includes: replacing AndroidManifest.xml and drawable\icon.png and adding some files to assets folder.
I would distribute my keystore file and unsigned original apk file along with my software to be signed at the end of process.
P.S:
OK, after some hours I nearly found solution in 9 steps and got final custom-signed-zip-aligned apk file and installed on device without errors! But now the problem is: all of apk files that would be produced by my users would have same package name (com.MyName.MyApp) and would cause problem if someone installs 2 or more of them on their phones. Should I try "aapt --rename-manifest-package" for this problem? and how to use it?
I finally have ended up with this working solution, I put it here for anyone interested.
1- Extract "original.apk" (source.apk) to a temp folder (ie. TempFolder)
2- Put user-generated files in "assets" and "res\drawable" folders under TempFolder
3- generate AndroidManifest.xml and put in TempFolder
4- Run this command:
aapt package -f -M "PathToManifest" -S "PathToResFolder" -I android.jar -F "NearlyFinal.apk" -A "PathToAssetsFolder"
5- copy "classes.dex" to folder where NearlyFinal.apk exists.
6- run this command:
aapt add -f NearlyFinal.apk classes.dex jad.properties
7- sign apk file:
jarsigner -storepass [keystorePass] -keystore KeyStoreFile.key NearlyFinal.apk [KeyStoreName]
8- zipalign apk file:
zipalign 4 NearlyFinal.apk "Final.apk"
9- rename and move Final.apk according to user's pref's.
FINISH

Managing android projects from command line

I am managing and running my android app from command line without using ant, I followed these steps:
generate R.java
compile R.java and all .java files in src to .class files
assembling set of class files into dex file using the command below
dx --dex --verbose --output=./bin/classes.dex ./bin
.class files are in bin directory.
But I'm getting the following errors in these steps:
java.lang.Runtime exception:.\bin file not found
at com.android.dx.cf.direct.ClassPathOpener.process
at com.android.dx.command.dexer.Main.processOne
at com.android.dx.command.dexer.Main.processAllFiles
at com.android.dx.command.dexer.Main..run
at com.android.dx.command.dexer.Main.main
at com.android.dx.command.Main.main
Due to this, I'm unable to create the Classes.dex file.
Can someone suggest a solution for this?
[not using eclipse and ant only through command line]
If you need to "manage your Android projects from command line", when you should use Ant build.
Ant's build.xml is a official standardized way to build Android projects. Ant scripts can do anything you may need to build your project.
If you want most modern build tools for Android, you can look at Gradle for Android projects. Note: today it's still in alpha stage.
Try entering the full path instead of the relative path.
Also you must put the class files inside a directory named exactly like it's package name. for example for com.test.me.MyActivity you must use com/test/me/MyActivity.class
And since we are on the topic, remember that dx can only work with class files created using Java6 (or less) so if you are using java7 to compile your code, add "source 1.6 target 1.6" parameters to your command line.

How to view AndroidManifest.xml from APK file?

Is it possible to view Androidmanifest.xml file?
I just changed the extension of the apk file to zip. This zip file contains the Androidmanifest.xml file. But I am unable view the contents of Androidmanifest.xml. It is fully encrypted.
How can I view the Androidmanifest.xml file?
Yes you can view XML files of an Android APK file. There is a tool for this: android-apktool
It is a tool for reverse engineering 3rd
party, closed, binary Android apps
How to do this on your Windows System:
Download apktool-install-windows-* file
Download apktool-* file
Unpack both to your Windows directory
Now copy the APK file also in that directory and run the following command in your command prompt:
apktool d HelloWorld.apk ./HelloWorld
This will create a directory "HelloWorld" in your current directory. Inside it you can find the AndroidManifest.xml file in decrypted format, and you can also find other XML files inside the "HelloWorld/res/layout" directory.
Here HelloWorld.apk is your Android APK file.
See the below screen shot for more information:
Android Studio can now show this. Go to Build > Analyze APK... and select your apk. Then you can see the content of the AndroidManifest file.
aapt d xmltree com.package.apk AndroidManifest.xml
will dump the AndroidManifest.xml from the specified APK. It's not in XML form, but you can still read it.
aapt (Android Asset Packaging Tool) is a built in tool that comes with the Android SDK.
Google has just released a cross-platform open source tool for inspecting APKs (among many other binary Android formats):
ClassyShark is a standalone binary inspection tool for Android developers. It can reliably browse any Android executable and show important info such as class interfaces and members, dex counts and dependencies. ClassyShark supports multiple formats including libraries (.dex, .aar, .so), executables (.apk, .jar, .class) and all Android binary XMLs: AndroidManifest, resources, layouts etc.
Install version 8.2:
wget https://github.com/google/android-classyshark/releases/download/8.2/ClassyShark.jar
Run:
java -jar ClassyShark.jar -open <file.apk>
In this thread, Dianne Hackborn tells us we can get info out of the AndroidManifest using aapt.
I whipped up this quick unix command to grab the version info:
aapt dump badging my.apk | sed -n "s/.*versionName='\([^']*\).*/\1/p"
You can use apkanalyzer, the command-line version of the APK Analyzer bundled with the Android SDK. Just execute the following command on the CLI:
/path/to/android-sdk/tools/bin/apkanalyzer manifest print /path/to/app.apk
You only have to replace /path/to/android-sdk with the correct path to your version of the Android SDK, and /path/to/app.apk with the path to your APK file.
You can use this command: save to file AndroidManifest.txt
aapt dump xmltree gmail.apk AndroidManifest.xml > AndroidManifest.txt
To decode the AndroidManifest.xml file using axmldec:
axmldec -o output.xml AndroidManifest.xml
or
axmldec -o output.xml AndroidApp.apk
Aapt2, included in the Android SDK build tools can do this - no third party tools needed.
$(ANDROID_SDK)/build-tools/28.0.3/aapt2 d --file AndroidManifest.xml app-foo-release.apk
Starting with build-tools v29 you have to add the command xmltree:
$(ANDROID_SDK)/build-tools/29.0.3/aapt2 d xmltree --file AndroidManifest.xml app-foo-release.apk
The AXMLParser and APKParser.jar can also do the job, you can see the link. AXMLParser
There is an online tool that lets you upload an APK It decompiles it and finally lets you to download a zip with all sources, manifest XML file and so on decompiled, all of that without having to install any program on your computer:
http://www.javadecompilers.com/apk
Also if you wish just to check on some params you can, by their UI
All these answers seem a bit over-engineered!
Just grab this chrome extension: https://chrome.google.com/webstore/detail/apk-downloader/fgljidimohbcmjdabiecfeikkmpbjegm
Download the .apk file you want from the playstore using the above extension.
Upload the .apk to this online tool to grab the manifest.xml: https://www.sisik.eu/apk-tool
You can also use my app, App Detective to view the manifest file of any app you have installed on your device.
This is an old thread, but I thought I would mention, of your phone has root, you can view it directly on your phone using the root explorer app. You don't even have to extract it to see.
Another useful (Python-based) tool for this is Androguard, using its axml sub-command:
androguard axml my.apk -o my.xml
This extracts and decodes the app manifest in one go. Unlike apktool this doesn't unpack anything else.
Another option is to use Jadx: https://github.com/skylot/jadx
Just open your APK and in treeview select "AndroidManifest.xml".
It will be readable just like that.
The file needs to be decompiled (or deodex'd not sure which one). But here's another way to do it:
-Download free Tickle My Android tool on XDA: https://forum.xda-developers.com/showthread.php?t=1633333https://forum.xda-developers.com/showthread.php?t=1633333
-Unzip
-Copy APK into \_WorkArea1\_in\ folder
-Open "Tickle My Android.exe"
-Theming Menu
-Decompile Files->Any key to continue (ignore warning)
-Decompile Files->1->[Enter]->y[Enter]
-Wait for it to decompile in new window... Done when new window closes
-Decompiled/viewable files will be here: \_WorkArea3\_working\[App]\

Categories

Resources