Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:54:24+00:00 2026-06-15T04:54:24+00:00

I need to instrument the dalvik bytecode of any given .apk file as part

  • 0

I need to instrument the dalvik bytecode of any given .apk file as part of my research and to obtain working, modified .apk with the instrumented bytecode.

I am programming in Java 1.6 under Windows 7.

Input

  • The original .apk file with the original, unchanged classes.dex dalvik bytecode.
  • the instrumented classes.dex bytecode of the .apk (yes, we assume we already instrumented the bytecode).

Desired output

  • The .apk file with the instrumented classes.dex bytecode instead of the original.

Problem statement

What is the most straightforward way to obtain the desired output from Java source code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:54:26+00:00Added an answer on June 15, 2026 at 4:54 am

    Update Apr 12 ’16

    Regarding step 2 of original answer:

    The sources of current version of ApkBuilder can be found in the official repo here and comment explaining why it should be used can be found also in the official repo.

    In your local Android SDK installation, the classes seem to live in android-sdk/tools/lib/sdklib.jar


    Original answer Nov 30 ’12

    Step 1: remove the original classes.dex

    To rebuild the .apk with custom classes.dex file first we need to delete the original classes.dex file from it. This can be easily done using the the aapt.exe tool from Android SDK install dir, e.g. located here: c:\Program Files (x86)\Android\android-sdk\platform-tools\aapt.exe

    The command:

    aapt.exe remove <path-to-the-apk> classes.dex 
    

    will remove the file.

    Step 2: rebuild the .apk

    There is a lot of confusion about building .apks as the (...)\android-sdk\tools\apkbuilder.bat script is deprecated. See this discussion for details.

    Behind the scenes the script calls ApkBuilderMain which calls non-deprecated ApkBuilder.

    Based on no longer available unofficial sources, I came up with the following code snippet:

      /**
       * Builds the {@code sourceApk} with bytecode merged from {@code classesDex}. The built .apk file has the same
       * name as {@code sourceApk} and is put in {@code outputDir}.<br/>
       * <br/>
       * <b>Precondition:</b> The {@code sourceApk} doesn't contain {@code classes.dex}, so the {@code classesDex} can be
       * merged into it.
       */  
      private static File buildApk(File sourceApk, File classesDex, File outputDir) throws Exception
      {
    
        File outputApk;
        try {
          outputApk = new File(outputDir, sourceApk.getName());
          ApkBuilder builder = new ApkBuilder(outputApk, sourceApk, classesDex, ApkBuilder.getDebugKeystore(), null);
          builder.sealApk();
        } catch (ApkCreationException e) {
          throw new Exception(e);
        } catch (SealedApkException e) {
          throw new Exception(e);
        }
    
        return outputApk;
      }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a musical instrument app for iPhone and need sample sounds
Solved previous part of problem, still need to understand why this isn't working though
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
Need some regular expressions help. So far I have my code working to allow
Need help getting Ember-Data working with Zend Rest. At first, I'm familiar with Zend
I need to programmatically instrument the lines of code of a method so that
I need to send a command to a GPIB instrument and I can do
I am working on one component where I need to scale and rotate image.
I am working on the software for an instrument that logs batch results into
The program was working with this implementation: class Instrument { public string ClassCode {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.