Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[ADB Binaries] [Installation] [Linux/Mac OS X] [*Sigh*Windows] All ADB Binaries Here!

OP Beatsleigher

19th January 2014, 10:20 PM   |  #1  
Beatsleigher's Avatar
OP Senior Member
Flag Somewhat around here : 52.366848,8.3345
Thanks Meter: 558
 
1,078 posts
Join Date:Joined: Oct 2011
Donate to Me
More
Hey guys,

I've seen quite a few threads here, regarding ADB binaries, but I've not seen one which incorporates the binaries for every OS.
So here's mine. And as a little special, I'm going to add a guide on how to download these binaries from my server (All links refer to there) and install them to any computer using Java.

FIRST:
Download links:

Linux (64-bit only!):
Mac OS X (Intel):
Windows (Any, except ARM!):
SECOND (Optional)
Installation on Debian systems.

If you just want to use ADB for your own personal use, you don't have to download the binary and always CD (change directory: Terminal) to the location on your hard drive where you downloaded it to.

If you're running Debian Linux, you can enter following commands into the terminal.
(
KDE: Konsole
Gnome: Terminal
)
Code:
For ADB: sudo apt-get install android-tools-adb
For Fastboot: sudo apt-get install android-tools-fastboot
Or for both (Easiest)
sudo apt-get update && sudo apt-get install android-tools-adb && sudo apt-get install android-tools-fastboot
Just copy & paste the command(s) into the terminal program of your choice and enter your password, the rest is done via the package manager.

Post #2 has the Java code examples for downloading the binaries in your program from my server to your client's computer.
Before you go there;
Please do not mirror these links.
I compiled them myself on my system (and my Dad's Mac Mini) and it was a real pain getting these to work correctly.
The Following User Says Thank You to Beatsleigher For This Useful Post: [ View ]
19th January 2014, 10:20 PM   |  #2  
Beatsleigher's Avatar
OP Senior Member
Flag Somewhat around here : 52.366848,8.3345
Thanks Meter: 558
 
1,078 posts
Join Date:Joined: Oct 2011
Donate to Me
More
Java Download Tutorial

FIRST;
Open your editor or IDE of choice.
I'm using NetBeans 7.4.

You will be greeted by this screen (if you're using NetBeans):


Next, create a new project and create a main class.
(I'll be using Universal Android Toolkit for this example, so I already have the code I want).

For the basic stuff, you should add at least two buttons, one to install ADB, and one to remove it again.


Now, go into the code section of your IDE and add the following variables (or copy this code):
Quote:

import java.io.*;
import javax.swing.*;

public class Main extends JFrame {
// Files
static File adb = null;
static File fastboot = null;
// Depending on the operating system you're programming for, you'll have to add more variables.

// Weblinks
static String webAdb = "http://team-m4gkbeatz.eu/Beatsleigher/adb_linux/adb";
static String webFastboot = "http://team-m4gkbeatz.eu/Beatsleigher/fastboot_linux/fastboot";

// Constructor
public Main() {
adb = new File(System.getProperty("user.home") + "/.programName/.bin/adb");
fastboot = new File(System.getProperty("user.home") + "/.programName/.bin/fastboot");
}

/**
* Calls method <saveUrl> and downloads file.
static void installAdb() {
try {
if (adb.exists()) adb.delete(); // Delete file if it exists, to ensure a clean install
if (fastboot.exists()) fastboot.delete(); // Delete file if it exists, to ensure a clean install
adb.getParentFile().mkdirs(); // Create all directories in front of ADB (user.home/.programName/.bin/).
adb.createNewFile(); // Create new file, so we can write data into it.
;
fastboot.getParentFile().mkdirs(); // Create all directories in front of fastboot (In case they're in different locations)
fastboot.createNewFile(); // Create new file, so we can write data into it.
;
saveUrl(adb.toString(), webAdb); // Download data into ADB.
saveUrl(fastboot.toString(), webFastboot); // Download data into fastboot.
; // Now we chmod the files, so that we can execute them at a later time.
; // I spent a few hours working this out, so please don't forget to give credit in your code/program!
new Thread() { // Create background thread, so UI doesn't freeze.
public void run() {
try {
Runtime r = Runtime.getRuntime();
r.exec("chmod 775 " + adb.toString()); // Chmod the adb executable, so it is marked as executable.
Thread.sleep(2000); // Give the program some time to finish.
interrupt(); // Exit thread.
} catch (IOException | InterruptedException ex) {
// Enter your handling code here.
}
}
}
;
new Thread() { // Create another background thread, so the UI doesn't freeze and so the program can chmod fastboot, while it is sorting out adb.
public void run() {
try {
Runtime r = Runtime.getRuntime();
r.exec("chmod 775 " + fastboot.toString()); // Chmod the fastboot executable, so it is marked as executable.
Thread.sleep(2000); // Give the program some time to finish.
interrupt(); // Exit thread.
} catch (IOException | InterruptedException ex) {
// Enter your handling code here.
}
}
JOptionPane.showMessageDialog(null, "INFO: ADB has been installed to your system!", "SUCCESS", JOptionPane.INFORMATION_MESSAGE); // Display message dialog notifying user of success.
} catch (IOException | InterruptedException ex) {
// Enter your handling code here.
}
}

static void removeAdb() {
try {
if (adb.exists()) adb.delete(); // Delete adb binary if it exists.
if (fastboot.exists()) fastboot.delete(); // Delete fastboot binary if it exists.
JOptionPane.showMessageDialog(null, "INFO: ADB has been removed from your system!", "SUCCESS", JOptionPane.INFORMATION_MESSAGE); // Display message dialog notifiying user of success.
} catch (IOException ex) {
// Enter your handling code here.
}
}

/**
* This is where all the magic happens.
*/
public static short saveUrl(String filename, String urlString) throws MalformedURLException, IOException {
BufferedInputStream fileIn = null; // Defines a BufferedInputStream (Used to download the information/data)
FileOutputStream fileout = null; // Defines a FileOutputStream (Used to write the data to the file)
try {
fileIn = new BufferedInputStream(new URL(urlString).openStream()); // Creates a new instance of said BufferedInputStream, using parameters in the method head.
fileOut = new FileOutputStream(filename); // Creates a new instance of said FileOutputStream, using parameters in the method head.

byte data[] = new byte[1024]; // Creates a new variable of type byte.
int count; // Defines a new variable of type int.
while ((count = fileIn.read(data, 0, 1024)) != -1) { // Reads bytes from this byte-input stream into the specified byte array, starting at the given offset.
fileOut.write(data, 0, count); // Writes downloaded data to specified file.
}
} finally {
if (fileIn != null) {
fileIn.close(); // Closes (Disposes of) fileIn
}
if (fileOut != null) {
fileOut.close(); // Closes (Disposes of) fileOut
}
}
return 1; // Exits method with value code 1
}
}

Depending on your IDE, it should look very similar to this:


Note:
Depending on the operating system you're using, you might have to change the variables/add variables, add conditional statements and download more files.

After you've added all the code,
if should look similar to this when executing your program:
Controls:


Installation Success:


Installed Binaries:


Removal Success:


Removed Binaries:



The operating system used in this tutorial was Kubuntu Linux 13.10 64-bit.
The IDE used is NetBeans IDE 7.4 with Java JDK 7.

/** Disclaimer
* I am not responsible for any damage or similar that may have happened by following this tutorial.
* I have tested and used all the codes and binaries provided without any issues.
* Should the binaries not work, please make sure you downloaded the correct binaries.
* I typed all this code by hand instead of copy-pasting it from NetBeans, as my methods contain some custom code
* which would only confuse you.
* To view the full source code, check out my GitHub (Although it may take a few days to get on there, as I'm still doing major stuff to the program!)
*/


I hope you liked this post of mine and that it was helpful.
If you have any suggestions for this post, please let me know.

If you have anything to say about this post, please stay constructive. And bashing will be reported to the mods and handled accordingly.

Last edited by Beatsleigher; 19th January 2014 at 11:24 PM.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes