Android Things PeripheralManager错误

时间:2018-07-19 19:29:25

标签: android android-studio-3.0 android-things android-things-console

我编写了一个简单的代码,使用Android的东西在raspberry pi 3上获取gpio列表,但是遇到了很多错误。

这是我的代码

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    PeripheralManager pioManager = PeripheralManager.getInstance();
    Log.d(TAG, "Available GPIO: " + pioManager.getGpioList());
}

清单文件-

<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO"/>
<uses-permission android:name="com.google.android.things.permission.MANAGE_INPUT_DRIVERS" />


<application>

    <uses-library android:name="com.google.android.things"/>

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <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>

渐变构建-

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    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:+'

}

现在是错误-

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: yashkushwaha.co.in.my, PID: 7725
                  java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/pio/PeripheralManager;
                      at yashkushwaha.co.in.my.MainActivity.onCreate(MainActivity.java:38)
                      at android.app.Activity.performCreate(Activity.java:7000)
                      at android.app.Activity.performCreate(Activity.java:6991)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                      at android.os.Handler.dispatchMessage(Handler.java:106)
                      at android.os.Looper.loop(Looper.java:164)
                      at android.app.ActivityThread.main(ActivityThread.java:6494)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
                   Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.things.pio.PeripheralManager" on path: DexPathList[[zip file "/system/framework/com.google.android.things.jar", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/base.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_dependencies_apk.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_resources_apk.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_slice_0_apk.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_slice_1_apk.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_slice_2_apk.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_slice_3_apk.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_slice_4_apk.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_slice_5_apk.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_slice_6_apk.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_slice_7_apk.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_slice_8_apk.apk", zip file "/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/lib/arm, /system/lib, /vendor/lib]]
                      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                      at yashkushwaha.truckit.co.in.my.MainActivity.onCreate(MainActivity.java:38) 
                      at android.app.Activity.performCreate(Activity.java:7000) 
                      at android.app.Activity.performCreate(Activity.java:6991) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
                      at android.app.ActivityThread.-wrap11(Unknown Source:0) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
                      at android.os.Handler.dispatchMessage(Handler.java:106) 
                      at android.os.Looper.loop(Looper.java:164) 
                      at android.app.ActivityThread.main(ActivityThread.java:6494) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 
                    Suppressed: java.io.IOException: No original dex files found for dex location /data/app/yashkushwaha.truckit.co.in.my-mnuUZ4TWOU0_pLFPgHW6NQ==/split_lib_resources_apk.apk
                      at dalvik.system.DexFile.openDexFileNative(Native Method)
                      at dalvik.system.DexFile.openDexFile(DexFile.java:353)
                      at dalvik.system.DexFile.<init>(DexFile.java:100)
                      at dalvik.system.DexFile.<init>(DexFile.java:74)
                      at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
                      at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
                      at dalvik.system.DexPathList.<init>(DexPathList.java:157)
                      at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
                      at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
                      at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
                      at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
                      at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
E/AndroidRuntime:     at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:35)
                      at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:693)
                      at android.app.LoadedApk.getClassLoader(LoadedApk.java:727)
                      at android.app.LoadedApk.getResources(LoadedApk.java:954)
                      at android.app.ContextImpl.createAppContext(ContextImpl.java:2270)
                      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5639)
                      at android.app.ActivityThread.-wrap1(Unknown Source:0)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
                            ... 6 more

请帮我解决这个问题,因为我是android Things开发的新手,顺便说一句,我的Android Things版本是1.0.2,Android Studio版本是3.1.3

谢谢!

1 个答案:

答案 0 :(得分:0)

更改应用级build.gradle文件:

compileOnly 'com.google.android.things:androidthings:+'

implementation 'com.google.android.things:androidthings:+'