FORUMS
Remove All Ads from XDA

[guide][wip]all you need to learn about an apk

772 posts
Thanks Meter: 1,037
 
By Aman_Arora, Senior Member on 31st October 2014, 11:31 AM
Post Reply Email Thread
Icon
Let's start by know what's an APK
Android application package (APK) is the package file format used to distribute and install application software and middleware onto Google's Android operating system, and certain other operating systems, such as Blackberry 10 Devices with the OS version 10.2.1 or higher.
Read more here:http://en.wikipedia.org/wiki/Android...cation_package

XDA PORTAL POST:http://www.xda-developers.com/apk-files-modifications/

What's inside an APK
  • AndroidManifest.xml It contains the valuable information for an application to function well.The permission it takes from the android system,the libraries it requires for proper functioning ,the minimum sdk version/api level/or in general the android version required and much more.
  • res(Resources) folder The most important folder inside an apk .It contains the all the things that an apk has.It got the xml codes which tell about diffrent sizes of things in apk the different colors ,labels ,icons ect.
  • lib folder this may or mayn't be present .It contains the few library files required especially for the application to work properly
  • assets folder
  • an odex apk also contains class.dex the java part of the apk.
  • smali folder the java part of the apk in deodexed apk


How to Re-Engineer or Decompile &Recompile an APK

There are many tools that you will find floating over the internet for this very purpose but actually the main tool over which these tools have been built is the APKTOOL .
check out:code.google.com/p/android-apktool/

Install your apktool.
I'll recommend you to install the Android SDK or use my reduced sdk in the attachments below (if you use windows)
Once you have installed the apktool.(I'm considering you have completly installed and configured java well)It's time to get started!
So we are going to pull the framework files from the system.
type in command prompt (cd it to the folder containing adb i.e. android-sdk/platform-tools or my the reduced sdk )
Quote:

abd pull /system/framework/framework-res.apk framework

pull all the framework files from system/framework (only the apks) and systemui from the app folder .

Now let's install the framework
Open command prompt cd to the folder containing the pulled framework and type:-
Quote:

apktool if framework-res.apk

Similarly install all resources.

Now let's decompile the an APK.
if you have an APK thats nice but if you don't let's pull some form the system

Quote:

adb pull /system/app/ applications

Lets say we are decompiling an APK names xxx.apk
Open cmd ,cd to the folder containg the apk and type
Quote:

apktool d xxx.apk xxx

let's recompile the apk back
cd the cmd to the folder containing the decompile apk i.e. if /a/b/c contains folder xxx i.e. the decompiled apk then cd to a/b/c.
type
Quote:

apktool b xxx xxx_new.apk


For more information on signing zipaling and other tools that were developed over apktool and offering more features checkout: http://forum.xda-developers.com/show....php?t=2295002
Thanks to @XperienceD for this awesome write up.
Attached Files
File Type: rar ReducedSDK_win.rar - [Click for QR Code] (693.3 KB, 327 views)
The Following 49 Users Say Thank You to Aman_Arora For This Useful Post: [ View ] Gift Aman_Arora Ad-Free
31st October 2014, 11:31 AM |#2  
Aman_Arora's Avatar
OP Senior Member
Flag New Delhi
Thanks Meter: 1,037
 
More
Understanding the Decompiled apk
Let's get started :D
  • Apktool.yml :It contains some of the basic information regarding the apk it version the its file name(It's not the name that you see but you can say it be a like a code name of the apk that actually plays role in linking of the application).
    Quote:

    version: 2.0.0-3d2e93-SNAPSHOT
    apkFileName: framework-res.apk
    isFrameworkApk: true
    sdkInfo:
    minSdkVersion: '19'
    targetSdkVersion: '19'
    packageInfo:
    forced-package-id: '1'
    versionInfo:
    versionCode: '19'
    versionName: 4.4.2-937116
    compressionType: false


    It contains the min. sdk version and the sdk version which for which this application was actually made.It also the compression level to which this application was compiled and at times you also find some extra information related to the vendor.
    Editting this you can change the version name the min sdk version so that the app. can run on lower versions of android aswell but it's always not possible to lower all application to a lower level or a very lower sdk level.
  • Android Manifest : Lets do this in bit detail.
    1.
    Quote:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:sharedUserLabel="@string/app_label" package="com.android.calendar">

    the UserLable is the App-Drawer Name of the application.It's the name or say the data in res/values/strings.xml and string app_label.
    the package/codename for this application is "com.android.calendar"

    2.the Permissions part
    Quote:

    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.READ_CALENDAR"/>
    <uses-permission android:name="android.permission.WRITE_CALENDAR"/>
    <uses-permission android:name="com.sonymobile.permission.READ_LUNAR "/>
    <uses-permission android:name="com.sonymobile.permission.WRITE_LUNA R"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.USE_CREDENTIALS"/>
    <uses-permission android:name="android.permission.READ_SYNC_SETTING S"/>
    <uses-permission android:name="com.google.android.googleapps.permis sion.GOOGLE_AUTH.mail"/>
    <uses-permission android:name="com.sonymobile.email.intent.permissi on.SEND_CALENDAR_EMAIL"/>
    <uses-permission android:name="android.permission.CALL_PHONE"/>
    <uses-permission android:name="android.permission.AUTHENTICATE_ACCO UNTS"/>
    <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_ST ORAGE"/>
    <uses-permission android:name="com.android.email.permission.ACCESS_ PROVIDER"/>
    <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
    <uses-permission android:name="android.permission.AUTHENTICATE_ACCO UNTS"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_ST ATE"/>
    <uses-permission android:name="com.google.android.providers.gsf.per mission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOC ATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCAT ION"/>
    <permission android:description="@string/tasks_provider_permdesc_readTasks_txt" android:label="@string/tasks_provider_permlab_readTasks_txt" android:name="com.sonymobile.tasks.provider.permis sion.READ_TASKS" android:permissionGroup="android.permission-group.PERSONAL_INFO" android:protectionLevel="dangerous"/>
    <permission android:description="@string/tasks_provider_permdesc_writeTasks_txt" android:label="@string/tasks_provider_permlab_writeTasks_txt" android:name="com.sonymobile.tasks.provider.permis sion.WRITE_TASKS" android:permissionGroup="android.permission-group.PERSONAL_INFO" android:protectionLevel="dangerous"/>
    <uses-permission android:name="com.sonymobile.tasks.provider.permis sion.READ_TASKS"/>
    <uses-permission android:name="com.sonymobile.tasks.provider.permis sion.WRITE_TASKS"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMP LETED"/>
    <uses-permission android:name="android.permission.READ_SYNC_STATS"/>
    <uses-permission android:name="android.permission.WRITE_SYNC_SETTIN GS"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WIND OW"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STO RAGE"/>

    These permissions can be easily found in /system/etc/permissions the *.xmls most of the these are already integrated in the android system .. but the some especially the vendor related ..these permissions can be granted through applications .

    Quote:

    <intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.LAUNCHER"/>
    <category android:name="android.intent.category.APP_CALENDAR "/>
    </intent-filter>

    If you see this " <category android:name="android.intent.category.LAUNCHER"/>" line in the manifest then you'll find the application in your lancher's apdrawer unless you have hid it :p
    3.Libraries
    Quote:

    <uses-library android:name="android.test.runner"/>
    <uses-library android:name="com.sonymobile.provider.tasks_1" android:required="false"/>
    <uses-library android:name="com.sonyericsson.uxpres" android:required="false"/>

    these permissions can be in the apk itself or in the /system/lib
  • Assets : The name says it's all the assets require for an application to do it all . :)
  • The res folderIt got most of the important part of the APK .The icon images you see in the apk are stored in the drawable-ydpi where y can be m,h,x,xx,xxx dpi.
    now the /res/value folder contains the stylees :the design the theme of the APK ,bools are the boolean part of the APK enable/disable can be easily controlled by editing the bools.xml the dimensions part of the apk are in /res/values/dimens.xml
    As I stated above the Appdrawer name of the application,
    /res/values/strings.xml

    search app_label and you find a line like this
    Quote:

    <string name="app_label">Calendar</string>

    Now replace the name as in here"calendar" with say your name
    to make it
    Quote:

    <string name="app_label">My name</string>

    compile the application back install it and you'll see the apppdrawer name is now My name from Calendar
  • Smali folder It contains the java based codes for the apk file.
The Following 20 Users Say Thank You to Aman_Arora For This Useful Post: [ View ] Gift Aman_Arora Ad-Free
31st October 2014, 11:31 AM |#3  
Aman_Arora's Avatar
OP Senior Member
Flag New Delhi
Thanks Meter: 1,037
 
More
Understanding the framework-res

framework-res.apk is the most important apk of the android system.Without this android system wouldn't boot properly it will bootloop and if it is poorly edited it will still be the same i.e. bootloop.
  • To begin with the assets folder
    1.It has a images and sound folder which contain the sound and the images which act as the bootup sound and bootanimation if the bootanimation.zip is missing from the system folder
    2.It contains a webkit folder:if you open it you'll understand what are those yourself
  • The res folder :
    Lets thing what all we can do with the android system by editing framework res..
    The capabilities of the the bool.xml
    ->enable/disable WImax
    ->enable/disable nav bar
    ->enable/disable turning on of screen after plugging in or removing the charger.
    each(most) line in bools.xml can help in enabling disabling some or the other feature
    dimens.xml
    These mods related to Bools.xml was part of a question at an event which was conducted by me and @Dev Jaskirat .And this was his question so thanks bro
    Dimens stands for dimensions so it makes it clears THAT it is used to change the dimestions of diffrent things eg. say nav bar the face unlock

    now lets go to strings.xml
    Have you ever wiped up dalik and seen Android is upgrading..??
    If yes lets make it something new and classy
    Quote:

    <string name="android_upgrading_title">Android is upgrading…</string>
    <string name="android_upgrading_apk">Optimizing app %1$d of %2$d.</string>
    <string name="android_upgrading_starting_apps">Starting apps.</string>
    <string name="android_upgrading_complete">Finishing boot.</string>

    %1$d of %2$d is the app count .

    Edit everything else as you wish
The Following 14 Users Say Thank You to Aman_Arora For This Useful Post: [ View ] Gift Aman_Arora Ad-Free
2nd November 2014, 11:12 AM |#4  
mrkhokho's Avatar
Member
Flag Tbilisi
Thanks Meter: 5
 
More
Thumbs up nice!
NIce thread finally knew what i was doing wrong while decompiling apps. I wasn't pulling all frameworks but only framework-res and systemui. After reading this found that in system/framework was mediatek-res after installing this too my systemui decompiled succesfully and finally ported lolipop checkboxes
The Following 2 Users Say Thank You to mrkhokho For This Useful Post: [ View ] Gift mrkhokho Ad-Free
2nd November 2014, 11:24 AM |#5  
Aman_Arora's Avatar
OP Senior Member
Flag New Delhi
Thanks Meter: 1,037
 
More
Keep Going!
The Following 5 Users Say Thank You to Aman_Arora For This Useful Post: [ View ] Gift Aman_Arora Ad-Free
2nd November 2014, 05:43 PM |#6  
methuselah's Avatar
Senior Member
Thanks Meter: 2,095
 
More
this post rocks
well a very great description for a newbie and very clearly mentioned.
The Following User Says Thank You to methuselah For This Useful Post: [ View ] Gift methuselah Ad-Free
7th November 2014, 03:26 PM |#7  
Aman_Arora's Avatar
OP Senior Member
Flag New Delhi
Thanks Meter: 1,037
 
More
The thread has been updated with few more information
The Following User Says Thank You to Aman_Arora For This Useful Post: [ View ] Gift Aman_Arora Ad-Free
16th November 2014, 09:04 PM |#8  
c0d3r!pp3r's Avatar
Member
Flag Vadodara
Thanks Meter: 16
 
Donate to Me
More
Nice compilation of commands.... highly appreciated...
can you add more variation? by providing with more details... it would be great
17th August 2015, 04:26 PM |#9  
Aman_Arora's Avatar
OP Senior Member
Flag New Delhi
Thanks Meter: 1,037
 
More
Quote:
Originally Posted by c0d3r!pp3r

Nice compilation of commands.... highly appreciated...
can you add more variation? by providing with more details... it would be great

I know it is too late to comment here , but after attending a workshop and talking to some friends I feel that it's good that the guide is kinda incomplete .Android has no boundries and thus even one of the smallest part of our systen the APK can't be just explained with a guide .APK and its structure is a very vast topic and you must try things yourself .I am always here to help you out if and when needed .
If you think you should not post a question here then you can PM me
The Following 2 Users Say Thank You to Aman_Arora For This Useful Post: [ View ] Gift Aman_Arora Ad-Free
18th August 2015, 07:07 PM |#10  
c0d3r!pp3r's Avatar
Member
Flag Vadodara
Thanks Meter: 16
 
Donate to Me
More
Quote:
Originally Posted by Aman_Arora

I know it is too late to comment here , but after attending a workshop and talking to some friends I feel that it's good that the guide is kinda incomplete .Android has no boundries and thus even one of the smallest part of our systen the APK can't be just explained with a guide .APK and its structure is a very vast topic and you must try things yourself .I am always here to help you out if and when needed .
If you think you should not post a question here then you can PM me

i have been moved to more deep in to the ROM building.. but i would love to share my experiences as well....
The Following User Says Thank You to c0d3r!pp3r For This Useful Post: [ View ] Gift c0d3r!pp3r Ad-Free
15th September 2015, 01:43 PM |#11  
IPM devlopers(ethiopia)'s Avatar
Junior Member
Thanks Meter: 3
 
More
hi Guys sent me
Apk tools new version
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes