PeripheralManagerService throws NoClassDefFoundError
Asked Answered
M

3

6

I have the following code in my app 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 app is now throwing 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 was working before, why has this started happening after the update?

Mihe answered 6/3, 2018 at 23:20 Comment(1)
That's a funny.... Using SO for your release notes... or as supplement anyhow. Makes sense, it's the first place people look.Tenebrous
M
13

Starting in Preview 7, Android Things API services are not constructed as new instances. They are instead accessed as singletons via getInstance() to be more in line with Android API paradigms. Some of the classes, such as PeripheralManagerService were also renamed.

Be sure to update your app to use the Preview 7 SDK:

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

Then modify your code to access the PeripheralManager instead:

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);
}

Review the Android Things API reference to verify if any of the other APIs you are calling have changed.

Mihe answered 6/3, 2018 at 23:20 Comment(1)
+1. This is documented in the release notes for 0.7-devpreviewPromising
S
1

Rather than using PeripheralManagerService service = new PeripheralManagerService(); use

PeripheralManager peripheralManager=PeripheralManager.getInstance();
Salvo answered 11/5, 2018 at 8:48 Comment(0)
C
0

I ran into the same issue but the above solution did not work for me. I was trying to create a alphanumeric display project by choosing new->project and choosing Android Things. The generated gradle build file looked like below. Note the driver for ht16k33 has version 0.3. This caused the problem. Once I changed it to 1.0 the ClassNotFound issue went away.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.google.android.things.contrib:driver-ht16k33:0.3'
    implementation 'com.android.support:support-v4:28.0.0-beta01'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compileOnly 'com.google.android.things:androidthings:+'

}

Crist answered 6/8, 2018 at 5:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.