我的应用中有以下代码可以访问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);
}
更新到最新的Android Things(开发者预览版7)后,我的应用程序正在抛出
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[...]
此代码之前有效,为什么在更新后才开始这样做?
答案 0 :(得分:13)
从预览7开始,Android Things API服务不会构建为新的
实例。它们通过getInstance()
作为单身人士访问
更符合Android API范例。一些类,如
PeripheralManagerService
也被重命名。
请务必更新您的应用以使用预览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内容API reference 验证您调用的任何其他API是否已更改。
答案 1 :(得分:0)
我遇到了同样的问题,但是上述解决方案对我不起作用。我试图通过选择new-> project并选择Android Things创建一个字母数字显示项目。生成的gradle构建文件如下所示。请注意ht16k33的驱动程序版本为0.3。这引起了问题。一旦将其更改为1.0,ClassNotFound问题就消失了。
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:+'
}