PeripheralManagerService throws NoClassDefFoundError

心不动则不痛 提交于 2019-11-28 13:42:51

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.

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

PeripheralManager peripheralManager=PeripheralManager.getInstance();

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:+'

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!