Home » Android » android – aidl oneway keyword error

android – aidl oneway keyword error

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am implementing an aidl interface, and for some reason, the following code gives me an error:

// IApkinsonCallback.aidl
package com.applications.philipp.apkinson.interfaces;

/** Interface implemented by Apkinson so plugins can give feedback */
oneway interface IApkinsonCallback {
    /** To be called by plugin after registration to setup data for result viewing
        Usage of this data:
        Intent intent = new Intent(intentActionName);
        intent.putExtra(bundleResultKey, result);
        startActivity(intent);
     */
    void onRegistered(String intentActionName, String bundleResultKey);
    /** To be called by plugin when result is ready after stopData() was called by Apkinson */
    void onResult(String result);
    /** Called if an error occured in the plugin and the call won't be successfully handled */
    void onError(String errorMsg);
}

ERROR:

<interface declaration>, <parcelable declaration>, AidlTokenType.import or AidlTokenType.package expected, got 'oneway'

When I remove the oneway keyword, everything works fine. But this cannot be the solution for my problem…

How to&Answers:

Summary:

Move the oneway keyword to the method level.

Explanation-
This is very weird problem that related to the /platform/frameworks/base/api/current.txt file inside the Android framework (Big txt file that contains every function and being used by Android Studio) .

Example-

/** Interface implemented by Apkinson so plugins can give feedback */
interface IApkinsonCallback {
    /** To be called by plugin after registration to setup data for result viewing
        Usage of this data:
        Intent intent = new Intent(intentActionName);
        intent.putExtra(bundleResultKey, result);
        startActivity(intent);
     */
    oneway void onRegistered(String intentActionName, String bundleResultKey);
    /** To be called by plugin when result is ready after stopData() was called by Apkinson */
    oneway void onResult(String result);
    /** Called if an error occured in the plugin and the call won't be successfully handled */
    oneway void onError(String errorMsg);
}

You will get the same result but without the error.