How to compile AndroidManifest.xml programmatically on Android? - android

I want to know how to implement a apk editor which can edit app name and version.
A way I can figure out takes several steps:
unzip apk file
modify app name and version in AndroidManifest.xml
replace the AndroidManifest.xml with the modified one
compress them into a new apk file
sign and align it
I can do all the steps above except Step 2. The AndroidManifest.xml file is compiled and cannot be parsed as normal xml file. I know apktool can compile and decompile it but I cannot find a easy way to run apktool on Android after several hours searching. I also cannot find any open-source apk editors(what I need is not only a apk editor, I want to develop another app based on it).

Finally I find some projects for reading and writing AXML(Android XML) and resources.arsc:
ArscEditor
axml
So I can wirte an apk builder with them. For more information, see my repo Auto.js-ApkBuilder.

Related

From an apk file, can we delete an activity of an android application

I want to make some changes on an android application based on its .apk file.
I could act on the XML part but I could not change all that is java code.
Is it possible to change the java code in the apk file and have another apk file ? If yes, how can i do it ?
Thank you for helping me.
Welcome in stack overflow, Iskander Soltani!
First of all: No, it isnt possible. An apk file is signed and you cant get access to rebuild it.
If you want to change some code or xml layout files, you have to open the project with android studio or other IDE and edit your project not the apk file(!).
An apk file is just the signed output of an android-project.
Did this asked your question?

Editing an APK file's resources from Android

I want to edit the resources of an APK file from WITHIN Android. I know how to do it with ApkTool in windows/linux, but I'm having problems doing it in an Android app itself.
In particular, I need to add a few files to the resouces, edit the AndroidManifest.xml and put the files back in the APK.
I know APKs are simply zip files, but the resources and manifest inside them are "compiled" in binary format so they cannot be edited directly, so I need some kind of library or tool for Android that can decompile the resources and then put them back in the APK.
I know this can be done, since apps like APK Editor do it (and without needing root!) but I can't find any documentation on how to do it myself.
I used this library for parsing an APK.

In android how to get which compiled version(compiled with(library file version)) they used in the project from apk file

In android how to get which compiled version((compiled with)(library file version)) They used in the project By using .apk file
I decompiled the apk and check it. But i can,t able know that.
In AndroidManifest.xml They didn't mentioned like "android:minSdkVersion" and "android:targetSdkVersion".That's Why i am asked this question
Thanks In advance
.apk is just a simple archive file. You can open it with WinRar for example and find the AndroidManifest.xml file inside that archive and you should have a line that starts with android:minSdkVersion and android:targetSdkVersion. The former is what's the oldest version of Android that the application supports and the latter is the target devices i.e. the version of SDK that compiled the code.

How can I add a jar to an APK & make the APK refer to it without Eclipse?

This may seem a bit weird, but I need to implement it.
I have an APK & I dont have its source code.
Now I can break the apk , modify & repack it, but while doing so, I need to add my custom jar to it & make the app/apk refer this library/jar at run time.
If I just create a folder libs inside the apk & put my jar inside, I get a NoClassDefFound error.
Any idea how to implement it using ANT or any other tool ?
Thanx in advance
The Jar(s) you attach in your android project, are not copied into APK.
What happens is that, The code of your Jar(s) file becomes part of your Android code. That means you can not simply place(or copy) Jar files in your APK.
But, There is a way around. In APK, your source code can be found in the classes.dex file.
What you need to do is, follow the steps
1 - Extract APK using winRAR
2 - Convert classes.dex to Jar using dex2jar
3 - Extract Jar file
4 - You will have source code in *.class, You can use JdGUI to convert it to *.java.
Now, you can create new android project and use the code.
This is not possible. All the classes are already compiled. You will need to "build" the APK again so that proper references could be remapped.

How do I use Ant to build multiple Android APKs with the same code base, but with different resource files?

I am trying to build a branded Android app, that will have different resource files (mainly drawables) for different customers. The Java code in the apps will be the same, but the different apps will have a different look--meaning different color schemes and different logos etc. I have been told, and my research suggests that Ant is the best way to achieve this.
Where should I change the Android 'build.xml' file? What sort of Ant task should I use to achieve this?
For debugging, I would like to just use Eclipse and build with the default resources. But for production releases, I would like to run Ant on build.xml to produce multiple APKs from different /res folders. I do not even need any code snippets (although that would be nice), just even some tips from people that have done this before or something similar.
I ended up writing a Python script to reorganize the Android project before each build. I recommend avoiding the use of Ant for stuff like this. My 100-200 lines of Python achieved the equivalent of about 1000+ extra lines of Ant that was required in addition to the default Android build.xml Ant script.
I have encountered a similar issue where I want to compile the same code base with some changes as well as changes in the resource files. The solution I am pursuing at the moment is creating a library with the shared code/resources and separate "regular" projects for each of the different APK releases. Unfortunately, I don't have a functional final solution to the problem yet, so all I can give is these vague hints.
Requirement Setup
1. Go to the URL :
http://ant.apache.org/bindownload.cgi
and download the apache ant and extract it in to the any folder like d:/ant .
2. I think you already having the Android SDK path is like(D:/Android SDK/)
Now go to the Enviroment variables and check whether path variable is there is there add these in path otherwise create a new varible with name path and put it there in vaue
D:/ant/bin;D:/Android SDK/tools
done
Go to command prompt and navigate it to the root directory of your project and run the command
android update project -p /
Note: / if you are in the root directory of project else you need to give the path of root directory like d:/myworkspace/mysampleproject
this will generate and build.xml file in your project.
now run the command for this it is necessary to be in root directory of your project
ant debug
this will generate an apk file in bin folder signed with default debug key.

Categories

Resources