PeripheralManagerService throws a NoClassDefFoundError

I have the following code in my application to access PeripheralManagerService:

PeripheralManagerService service = new PeripheralManagerService();
Gpio ledGpio;
try {
    ledGpio = service.openGpio("BCM6");
    ledGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
} catch (IOException e) {
    Log.e(TAG, "Error configuring GPIO pins", e);
}

After updating to the latest Android Things (Developer Preview 7), my application now throws a NoClassDefFoundError:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/pio/PeripheralManagerService;
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.things.pio.PeripheralManagerService" on path: DexPathList[...]

This code worked before, why did it happen after the update?

+4
source share
1 answer

Starting with Preview 7, the Android Things API services are not built as new instances. Instead, they gain access in the form of singles through getInstance() more in accordance with the Android API paradigms. Some of the classes, for example, have PeripheralManagerServicealso been renamed.

Be sure to update the application to use the Preview 7 SDK:

dependencies {
    compileOnly 'com.google.android.things:androidthings:0.7-devpreview'
}

, PeripheralManager:

PeripheralManager manager = PeripheralManager.getInstance();
Gpio ledGpio;
try {
    ledGpio = manager.openGpio("BCM6");
    ledGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
} catch (IOException e) {
    Log.e(TAG, "Error configuring GPIO pins", e);
}

Android Things API , - API-, .

+9

Source: https://habr.com/ru/post/1694555/


All Articles