当前位置:首页 > 云服务器

Android Thing 设备 API 的正确引入方式与依赖配置指南

游戏科技网2026年09月14日 21:26云服务器20
描述:android things 已于 2020 年正式停止维护,其核心库 `com.google.android.things`(含 `device` 等子包)仅适用于旧版 android things os 设备开发,不可用于常规 android 应用;正确依赖应为 `com.google.andr…

Android Thing 设备 API 的正确引入方式与依赖配置指南

android things 已于 2020 年正式停止维护,其核心库 `com.google.android.things`(含 `device` 等子包)仅适用于旧版 android things os 设备开发,不可用于常规 android 应用;正确依赖应为 `com.google.android.things:androidthings:1.0`,且需配置 google maven 仓库并注意平台兼容性限制。

Android Things 是 Google 曾推出的面向物联网嵌入式设备的操作系统(基于 Android),专为树莓派、NXP i.MX7D 等硬件设计。其 SDK 提供了 com.google.android.things.device 等专用 API(如 PeripheralManager、UartDevice、Gpio),用于直接控制硬件外设。但需明确:该库并非普通 Android 应用可用的通用工具包,而是 Android Things OS 运行时环境的系统级 API

✅ 正确依赖配置(仅限 Android Things 项目)

若你正在开发运行于 Android Things OS 的固件应用(targetSdkVersion ≤ 27,minSdkVersion = 24),请按以下步骤配置:

  1. 在项目级 build.gradle 中添加 Google Maven 仓库

    Android Thing 设备 API 的正确引入方式与依赖配置指南
    C++

    "空空如也"

    下载

    1

    2

    3

    4

    5

    6

    7

    // build.gradle (Project)

    allprojects {

     repositories {

         google()  // 即 https://maven.google.com

         mavenCentral()

     }

    }

  2. 在模块级 build.gradle 中声明正确依赖

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    // build.gradle (Module: app)

    android {

     compileSdk 27  // 必须为 27 或更低(Android Things 1.0 对应 Android 8.1)

     

     defaultConfig {

         minSdkVersion 24

         targetSdkVersion 27

         // 注意:Android Things 应用必须声明 uses-library

         manifestPlaceholders = [thingssdk: "com.google.android.things"]

     }

    }

dependencies {implementation com.google.android.things:androidthings:1.0}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

3. **在 `AndroidManifest.xml` 中声明系统库依赖**:

```xml

<application ...>

    <uses-library

        android:name="com.google.android.things"

        android:required="true" />

 

    <!-- 主 Activity 需声明为 Launcher,并指定 Android Things category -->

    <activity

        android:name=".MainActivity"

        android:exported="true">

        <intent-filter>

            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.IOT_LAUNCHER" />

            <category android:name="android.intent.category.DEFAULT" />

        </intent-filter>

    </activity>

</application>

⚠️ 重要注意事项

  • ❌ implementation com.google.android.things:device:1.0 是错误的坐标——该 artifact 从未发布,Maven 仓库中不存在。唯一有效 artifact 是 com.google.android.things:androidthings:1.0。
  • ? 不支持常规 Android 手机/平板:此库无法在标准 Android 设备上运行,调用 PeripheralManager.getInstance() 将抛出 UnsupportedOperationException 或 SecurityException。
  • ? 项目已终止维护:Google 自 2020 年 1 月起停止 Android Things 的更新与支持,不再提供新功能、安全补丁或云服务(Cloud IoT Core 集成已下线)。新项目请转向 Raspberry Pi OS + libgpiod、ESP-IDF、Arduino 或 Android’s modern Jetpack libraries(如 androidx.core:core-splashscreen 不相关,硬件交互推荐使用厂商 SDK 或 HAL 层封装)。
  • ? 若你在文档中看到 com.google.android.things.device.* 包,它属于 androidthings-1.0.aar 内部结构,无需单独引入子模块——androidthings:1.0 已完整包含全部 API。

✅ 替代方案建议(2024 年起)

场景推荐方案
树莓派 GPIO/I²C/UART 控制使用 libgpiod(C/C++/Python)或 Pi4J v2(Java)
跨平台嵌入式开发ESP-IDF(ESP32)、Zephyr RTOS、Rust embedded-hal
Android 设备有限硬件访问android.hardware.usb(USB Host)、android.bluetooth.le(BLE)、厂商定制 HAL(如 Qualcomm QCA4020 SDK)

总之,请确认你的目标平台是否为已刷写 Android Things 1.0 固件的开发板;否则,引入该依赖不仅无法编译通过,更会在运行时失败。技术选型前务必查阅 Android Things 官方停更公告 及当前活跃的开源 IoT 生态。

“Android Thing 设备 API 的正确引入方式与依赖配置指南” 的相关文章

5元云服务器:入门级新手首选

5元云服务器:入门级新手首选 我是一名刚毕业的大学生,对编程充满了热情,但现实总是骨感一些。刚踏入职场,我梦想着能独立开发一个网站或应用,却苦于没有足够的资源。买一台实体服务器太贵,租个虚拟空间又觉得…

6元服务器租用,高性价比VPS主机推荐

6元服务器租用,高性价比VPS主机推荐 记得去年我刚开始创业,做了一个小型网站来展示我的产品。那时,我手头紧,预算有限,却急着需要一个可靠的服务器来托管网站。作为一个普通上班族,我对技术懂得不多,但我…

2021年云服务器优惠套餐推荐

2021年云服务器优惠套餐推荐 嗨,朋友们!你是否曾经在深夜里,面对一堆代码和服务器错误,感叹说:“为什么我的项目老是卡顿?”如果是这样的话,那你可能正在寻找2021年云服务器优惠套餐的解决方案。作为…

云服务器市场增长

云服务器市场增长 大家好,作为一个每天依赖云服务器的开发者,我亲身感受到市场的飞速膨胀。想象一下,几年前我还得在办公室的老旧电脑前苦苦挣扎,处理数据时总是卡顿不堪,但现在,只需轻轻一点,就能在云端获得…

1元买走一台云服务器,这种天上掉馅饼的事存在吗?

1元买走一台云服务器,这种天上掉馅饼的事存在吗? 那天,我在咖啡馆里刷手机,偶然看到一个广告:“只需1元,就能买走一台高性能云服务器!容量无限,稳定快速,适合创业和学习。”我的心跳突然加速了。作为一个…

云服务器10元月:经济型服务价格新记录

云服务器10元/月:经济型服务价格新记录 最近,云服务器的价格被推向了一个新低,10元一个月的方案让许多人惊喜不已。这不仅仅是数字上的变化,更是科技服务普惠化的一个标志。云服务器作为一种基于云计算的虚…