Android thing: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/pio/PeripheralManager;

杀马特。学长 韩版系。学妹 提交于 2019-12-23 13:56:07

问题


Android thing run time exception:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/pio/PeripheralManager;

Manifest file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androidthings.simplepio">

    <application android:allowBackup="true" android:icon="@android:drawable/sym_def_app_icon"
        android:name="android.support.multidex.MultiDexApplication"
        android:label="@string/app_name">
        <uses-library android:name="com.google.android.things"/>
        <activity android:name=".BlinkActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <!-- Launch activity automatically on boot -->
            <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>

</manifest>

Error logcat:

    01-01 00:00:53.293 1326-1326/com.example.androidthings.simplepio E/AndroidRuntime: FATAL EXCEPTION: main
   Process: com.example.androidthings.simplepio, PID: 1326
   java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/things/pio/PeripheralManager;
       at com.example.androidthings.simplepio.BlinkActivity.onCreate(BlinkActivity.java:51)
       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/com.example.androidthings.simplepio-y-kMOBHPpOQbWFdWf4QeXw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.androidthings.simplepio-y-kMOBHPpOQbWFdWf4QeXw==/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 com.example.androidthings.simplepio.BlinkActivity.onCreate(BlinkActivity.java:51) 
       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(ZygoteIncode,807) 
    01-01 00:00:53.446 1326-1326/com.example.androidthings.simplepio I/Process: Sending signal. PID: 1326 SIG: 9

This is my code, I got this from this Link, I just clone it nothing changed.

public class BlinkActivity extends Activity {
private static final String TAG = BlinkActivity.class.getSimpleName();
private static final int INTERVAL_BETWEEN_BLINKS_MS = 1000;

private Handler mHandler = new Handler();
private Gpio mLedGpio;
private boolean mLedState = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "Starting BlinkActivity");

    try {
        String pinName = BoardDefaults.getGPIOForLED();
        mLedGpio = PeripheralManager.getInstance().openGpio(pinName);
        mLedGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
        Log.i(TAG, "Start blinking LED GPIO pin");
        // Post a Runnable that continuously switch the state of the GPIO, blinking the
        // corresponding LED
        mHandler.post(mBlinkRunnable);
    } catch (IOException e) {
        Log.e(TAG, "Error on PeripheralIO API", e);
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    // Remove pending blink Runnable from the handler.
    mHandler.removeCallbacks(mBlinkRunnable);
    // Close the Gpio pin.
    Log.i(TAG, "Closing LED GPIO pin");
    try {
        mLedGpio.close();
    } catch (IOException e) {
        Log.e(TAG, "Error on PeripheralIO API", e);
    } finally {
        mLedGpio = null;
    }
}

private Runnable mBlinkRunnable = new Runnable() {
    @Override
    public void run() {
        // Exit Runnable if the GPIO is already closed
        if (mLedGpio == null) {
            return;
        }
        try {
            // Toggle the GPIO state
            mLedState = !mLedState;
            mLedGpio.setValue(mLedState);
            Log.d(TAG, "State set to " + mLedState);

            // Reschedule the same runnable in {#INTERVAL_BETWEEN_BLINKS_MS} milliseconds
            mHandler.postDelayed(mBlinkRunnable, INTERVAL_BETWEEN_BLINKS_MS);
        } catch (IOException e) {
            Log.e(TAG, "Error on PeripheralIO API", e);
        }
    }
};
}

If any solve this problem, Please help me.


回答1:


I solved this issue by updating my Android Things. I used the new setup utility tool to flash my Android Things: https://partner.android.com/things/console/u/1/#/tools




回答2:


I don't know if this may help, but i resolved it by founding out that in my build.gradle com.google.android.things:androidthings:+ was only set as a dependency to compile (compileOnly) and not to be redistributed. I fixed it by changing it in implementation 'com.google.android.things:androidthings:+'.



来源:https://stackoverflow.com/questions/49206052/android-thing-java-lang-noclassdeffounderror-failed-resolution-of-lcom-google

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