Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

SweetBlue

> 编程语言
Open source

BLE on Android, the easy way. THIS IS NOW DEPRECATED. Please visit website for info on new versions.

358 stars0 likes1 views
WebsiteGitHub

About

BLE on Android, the easy way. THIS IS NOW DEPRECATED. Please visit website for info on new versions.

With the release of SweetBlue v3 (https://sweetblue.io), this project is no longer being actively developed. Consider this project as abandoned.

| Why? | Features | Getting Started | Licensing | Wiki | Toolbox

Why?

Android's BLE stack has some...issues...

  • https://github.com/iDevicesInc/SweetBlue/wiki/Android-BLE-Issues
  • https://code.google.com/p/android/issues/detail?id=58381
  • http://androidcommunity.com/nike-blames-ble-for-their-shunning-of-android-20131202/
  • http://stackoverflow.com/questions/17870189/android-4-3-bluetooth-low-energy-unstable

SweetBlue is a blanket abstraction that shoves all that troublesome behavior behind a clean interface and gracefully degrades when the underlying stack becomes too unstable for even it to handle.

It’s built on the hard-earned experience of several commercial BLE projects and provides so many transparent workarounds to issues both annoying and fatal that it’s frankly impossible to imagine writing an app without it. It also supports many higher-level constructs, things like atomic transactions for coordinating authentication handshakes and firmware updates, flexible scanning configurations, read polling, transparent retries for transient failure conditions, and, well, the list goes on. The API is dead simple, with usage dependence on a few plain old Java objects and link dependence on standard Android classes. It offers conveniences for debugging and analytics and error handling that will save you months of work - last mile stuff you didn't even know you had to worry about.

Features

  • Full-coverage API documentation: http://idevicesinc.com/sweetblue/docs/api
  • Sample applications.
  • Battle-tested in commercial apps.
  • Plain old Java with zero API-level dependencies.
  • Rich, queryable state tracking that makes UI integration a breeze.
  • Automatic service discovery.
  • Full support for server role including advertising.
  • Easy RSSI tracking with built-in polling and caching, including distance and friendly signal strength calculations.
  • Highly configurable scanning with min/max time limits, periodic bursts, advanced filtering, and more.
  • Continuous scanning mode that saves battery and defers to more important operations by stopping and starting as needed under the hood.
  • Atomic transactions for easily coordinating authentication handshakes, initialization, and firmware updates.
  • Automatic striping of characteristic writes greater than MTU size of 20 bytes.
  • Undiscovery based on last time seen.
  • Clean leakage of underlying native stack objects in case of emergency.
  • Wraps Android API level checks that gate certain methods.
  • Verbose logging that outputs human-readable thread IDs, UUIDs, status codes and states instead of alphabet soup.
  • Wrangles a big bowl of thread spaghetti behind a nice asynchronous API - make a call on main thread, get a callback on main thread a short time later.
  • Internal priority job queue that ensures serialization of all operations so native stack doesn’t get overloaded and important stuff gets done first.
  • Optimal coordination of the BLE stack when connected to multiple devices.
  • Detection and correction of dozens of BLE failure conditions.
  • Numerous manufacturer-specific workarounds and hacks all hidden from you.
  • Built-in polling for read characteristics with optional change-tracking to simulate notifications.
  • Transparent retries for transient failure conditions related to connecting, getting services, and scanning.
  • Comprehensive callback system with clear enumerated reasons when something goes wrong like connection or read/write failures.
  • Distills dozens of lines of boilerplate, booby-trapped, native API usages into single method calls.
  • Transparently falls back to Bluetooth Classic for certain BLE failure conditions.
  • On-the-fly-configurable reconnection loops started automatically when random disconnects occur, e.g. from going out of range.
  • Retention and automatic reconnection of devices after BLE off->on cycle or even complete app reboot.
  • One convenient method to completely unwind and reset the Bluetooth stack.
  • Detection and reporting of BLE failure conditions that user should take action on, such as restarting the Bluetooth stack or even the entire phone.
  • Runtime analytics for tracking average operation times, total elapsed times, and time estimates for long-running operations like firmware updates.

Getting Started

  1. If using Android Studio or Gradle...
  2. Download the latest release to a subfolder of your project such as MyApp/src/main/lib/. This ZIP contains several samples, precompiled JARS, and API docs and is preferable to downloading from GitHub, which only contains the raw source.
  3. Open the app module's build.gradle file.
  4. If building with source, your gradle file should look something like this:
```

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.3'
    
    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 25
        ...
    }

    sourceSets {
        main.java.srcDirs += 'src/main/lib/sweetblue/src'
        main.res.srcDirs += 'src/main/lib/sweetblue/res'
        ...
    }
    ...
}

```
  1. If you're building with source from github, the sourceSet path is a bit different:
```
  
  android {
      compileSdkVersion 25
      buildToolsVersion '25.0.3'
      
      defaultConfig {
          minSdkVersion 18
          targetSdkVersion 25
          ...
      }
  
      sourceSets {
          main.java.srcDirs += 'src/main/lib/sweetblue/library/src/main/java'              
          main.res.srcDirs += 'src/main/lib/sweetblue/library/src/main/res'
          ...
      }
      ...
  }
  
  ```
  1. Else if building with JAR, it should look something like this:
```

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.3'
    
    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 25
        ...
    }

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
        ...
    }
    ...
}

```
  1. Now add these to the root of MyApp/AndroidManifest.xml:

    
    
    
    
    
    
    
    
    
    
  2. From your Activity or Service or Application instance, this is all it takes to discover a device, connect to it, and read a characteristic:

…

Licensing

SweetBlue is released here under the GPLv3. Please visit https://sweetblue.io for SweetBlue v3, as v2 is no longer licensable for commercial applications. In a nutshell, if you're developing a for-profit commercial app you may use this library for free for evaluation purposes, but most likely your use case will require purchasing a proprietary license before you can release your app to the public. See the FAQ for more details and https://tldrlegal.com/license/gnu-general-public-license-v3-%28gpl-3%29 for a general overview of the GPL.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javaandroid-libraryblebluetoothjava

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言