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 8446105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:50:24+00:00 2026-06-10T09:50:24+00:00

I have developed a Java application. The application connects to an android device programmatically

  • 0

I have developed a Java application. The application connects to an android device programmatically to transfer some files to connects Android devices.

In my application I have added the adb PATH so it can use it to connect to devices.

I was wondering if its possible to maybe package it within the application ? or just copying the adb into the application directory ? Because I want who ever to download this application, wouldn’t need to also have download the adb or Android sdk for the application to work

Is it possible ?

  • 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-10T09:50:26+00:00Added an answer on June 10, 2026 at 9:50 am

    After doing some research you can package an exe within a jar file but you have to extract the exe each run of the application. Following TofuBear’s example here I was able to encapsulate adb within a jar file. You’ll need to include the AdbWinApi.dll (or equivalent linux libraries).

    import java.io.BufferedReader;
    import java.io.Closeable;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.net.URI;
    import java.net.URISyntaxException;
    import java.net.URL;
    import java.security.CodeSource;
    import java.security.ProtectionDomain;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipException;
    import java.util.zip.ZipFile;
    
    public class Sandbox
    {
        public static void main(final String[] args)
            throws URISyntaxException,
                   ZipException,
                   IOException
        {
            final URI uri;
            final URI exe;
    
            uri = getJarURI();
            // Extract the adb application
            exe = getFile(uri, "adb.exe");
            // Extract the AdbWinApi dll file.
            getFile(uri, "AdbWinApi.dll");
            System.out.println(exe);
        }
    
        private static URI getJarURI()
            throws URISyntaxException
        {
            final ProtectionDomain domain;
            final CodeSource       source;
            final URL              url;
            final URI              uri;
    
            domain = Sandbox.class.getProtectionDomain();
            source = domain.getCodeSource();
            url    = source.getLocation();
            uri    = url.toURI();
    
            return (uri);
        }    
    
        private static URI getFile(final URI    where,
                                   final String fileName)
            throws ZipException,
                   IOException
        {
            final File location;
            final URI  fileURI;
    
            location = new File(where);
    
            // not in a JAR, just return the path on disk
            if(location.isDirectory())
            {
                fileURI = URI.create(where.toString() + fileName);
            }
            else
            {
                final ZipFile zipFile;
    
                zipFile = new ZipFile(location);
    
                try
                {
                    fileURI = extract(zipFile, fileName);
                }
                finally
                {
                    zipFile.close();
                }
            }
    
            return (fileURI);
        }
    
        private static URI extract(final ZipFile zipFile,
                               final String  fileName)
            throws IOException
        {
            final File         tempFile;
            final ZipEntry     entry;
            final InputStream  zipStream;
            OutputStream       fileStream;
    
            //tempFile = File.createTempFile(fileName,     Long.toString(System.currentTimeMillis()));
            tempFile = new File(System.getProperty("java.io.tmpdir") + File.separator + fileName);
    
            tempFile.deleteOnExit();
            entry    = zipFile.getEntry(fileName);
    
            if(entry == null)
    
            {
                throw new FileNotFoundException("cannot find file: " + fileName + " in archive: " + zipFile.getName());
            }
    
            zipStream  = zipFile.getInputStream(entry);
            fileStream = null;
    
            try
            {
                final byte[] buf;
                int          i;
    
                fileStream = new FileOutputStream(tempFile);
                buf        = new byte[1024];
                i          = 0;
    
                while((i = zipStream.read(buf)) != -1)
                {
                    fileStream.write(buf, 0, i);
                }
            }
            finally
            {
                close(zipStream);
                close(fileStream);
            }
    
            return (tempFile.toURI());
        }
    
        private static void close(final Closeable stream)
        {
            if(stream != null)
            {
                try
                {
                    stream.close();
                }
                catch(final IOException ex)
                {
                    ex.printStackTrace();
                }
            }
        }
    }
    

    I had to change the file creation from TofuBear’s example so that the file name of the exe would not be changed. It’s still created in the temporary folder and will be deleted on exit. I left the original code as a comment.

    Edit: Seems I got so caught up with the technical possiblity of it I forgot the legal ramifications. It’s been stated here by Chris Stratton that the SDK Terms of Service prohibits redistribution of any part of the sdk. Which would include adb.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a Java Application that connects with a database (insert, select ...)
I have developed a Java application and now i want to give some simple
I have developed and Simple android application in Java and also uploaded it on
I have developed Java desktop application using Netbeans. In my application, I used some
I have a stand-alone Java windows application developed based on Swing. It connects to
I have developed a java application which run's perfectly in local server. But When
I have developed a java swing client-server application. The server has many services like
I have developed a Java program that will count the number of files in
I have developed a basic Chat application in Java. It consists of a server
I have developed an Java application with RMI,JPA and H2DB, look at the screenshot

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.