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

Search This thread

Aman_Arora

Senior Member
Jan 28, 2013
772
1,024
23
New Delhi
APK_format_icon.png
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_application_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! :D
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 )
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:-
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

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
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
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/showthread.php?t=2295002
Thanks to @XperienceD for this awesome write up. :)
 

Attachments

  • ReducedSDK_win.rar
    693.3 KB · Views: 338
Last edited:

Aman_Arora

Senior Member
Jan 28, 2013
772
1,024
23
New Delhi
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).
    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.
    <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
    <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_LUNAR"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.USE_CREDENTIALS"/>
    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
    <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.mail"/>
    <uses-permission android:name="com.sonymobile.email.intent.permission.SEND_CALENDAR_EMAIL"/>
    <uses-permission android:name="android.permission.CALL_PHONE"/>
    <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
    <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <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_ACCOUNTS"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <permission android:description="@string/tasks_provider_permdesc_readTasks_txt" android:label="@string/tasks_provider_permlab_readTasks_txt" android:name="com.sonymobile.tasks.provider.permission.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.permission.WRITE_TASKS" android:permissionGroup="android.permission-group.PERSONAL_INFO" android:protectionLevel="dangerous"/>
    <uses-permission android:name="com.sonymobile.tasks.provider.permission.READ_TASKS"/>
    <uses-permission android:name="com.sonymobile.tasks.provider.permission.WRITE_TASKS"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.READ_SYNC_STATS"/>
    <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    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 .

    <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
    <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
    <string name="app_label">Calendar</string>

    Now replace the name as in here"calendar" with say your name
    to make it
    <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.
 
Last edited:

Aman_Arora

Senior Member
Jan 28, 2013
772
1,024
23
New Delhi
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 :good:
    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 :cool:
    <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 :)
 
Last edited:

mrkhokho

Member
Jul 1, 2014
35
5
21
Tbilisi
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
 

c0d3r!pp3r

Member
May 31, 2012
30
16
Vadodara
Nice compilation of commands.... highly appreciated...
can you add more variation? by providing with more details... it would be great
 

Aman_Arora

Senior Member
Jan 28, 2013
772
1,024
23
New Delhi
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 :)
 

c0d3r!pp3r

Member
May 31, 2012
30
16
Vadodara
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.... :good:
 
  • Like
Reactions: Aman_Arora

Top Liked Posts

  • There are no posts matching your filters.
  • 47
    APK_format_icon.png
    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_application_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! :D
    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 )
    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:-
    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

    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
    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
    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/showthread.php?t=2295002
    Thanks to @XperienceD for this awesome write up. :)
    19
    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).
      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.
      <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
      <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_LUNAR"/>
      <uses-permission android:name="android.permission.WAKE_LOCK"/>
      <uses-permission android:name="android.permission.USE_CREDENTIALS"/>
      <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
      <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH.mail"/>
      <uses-permission android:name="com.sonymobile.email.intent.permission.SEND_CALENDAR_EMAIL"/>
      <uses-permission android:name="android.permission.CALL_PHONE"/>
      <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
      <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
      <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_ACCOUNTS"/>
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
      <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
      <permission android:description="@string/tasks_provider_permdesc_readTasks_txt" android:label="@string/tasks_provider_permlab_readTasks_txt" android:name="com.sonymobile.tasks.provider.permission.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.permission.WRITE_TASKS" android:permissionGroup="android.permission-group.PERSONAL_INFO" android:protectionLevel="dangerous"/>
      <uses-permission android:name="com.sonymobile.tasks.provider.permission.READ_TASKS"/>
      <uses-permission android:name="com.sonymobile.tasks.provider.permission.WRITE_TASKS"/>
      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
      <uses-permission android:name="android.permission.READ_SYNC_STATS"/>
      <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
      <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
      <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
      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 .

      <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
      <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
      <string name="app_label">Calendar</string>

      Now replace the name as in here"calendar" with say your name
      to make it
      <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.
    13
    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 :good:
      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 :cool:
      <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 :)
    2
    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