Android: AIDL refusing to generate code from aidl file defining parcelable

社会主义新天地 提交于 2019-12-10 21:42:09

问题


I am trying to build a library with aidls.

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test

LOCAL_SRC_FILES := $(call all-java-files-under, java) \
java/com/testapp/Istudent.aidl \
java/com/testapp/Itest.aidl \

LOCAL_PREBUILT_JAVA_LIBRARY := framework.jar
include $(BUILD_JAVA_LIBRARY)

I am trying to refer the Istudent in Itest.

Istudent.aidl

package com.testapp;

parcelable Istudent;

Istudent.java

public class Istudent implements Parcelable{}

Itest.aidl

package com.testapp;

import  com.testapp.Istudent;

interface IAP2InterfaceBase {}

But error I receive is E 07-11 20:05:37 71066 71066 aidl.cpp:580] refusing to generate code from aidl file defining parcelable

Kindly let me know what we mean by "refusing to generate code from aidl file defining parcelable" ? And what wrong I am doing here..


回答1:


Reason for Error can be understood as per below source code of aidl:

https://github.com/debian-pkg-android-tools/android-platform-system-tools-aidl/blob/master/aidl.cpp Line:536

if (!interface) {
    LOG(ERROR) << "refusing to generate code from aidl file defining "
                  "parcelable";
    return AidlError::FOUND_PARCELABLE;
  }

Also the aidl file that declares your parcelable class is not supposed to be included in build as mentioned on https://developer.android.com/guide/components/aidl.html under 'Passing Objects over IPC'. Below snippet copied from the website.

Finally, create an .aidl file that declares your parcelable class (as shown for the Rect.aidl file, below). If you are using a custom build process, do not add the .aidl file to your build. Similar to a header file in the C language, this .aidl file isn't compiled.




回答2:


Don't know whether you have resolved this issue. I encountered the same problem, resolved it by downgrade Android SDK build tool to an earlier version, the build tool versions below 24 should be working, I used version 23.0.3




回答3:


In your android.mk file replace

LOCAL_SRC_FILES := $(call all-java-files-under, java) \
    java/com/testapp/Istudent.aidl \
    java/com/testapp/Itest.aidl \

with-----------

LOCAL_SRC_FILES := $(call all-java-files-under, java) $(call all-Iaidl-files-under, java)
LOCAL_AIDL_INCLUDES := $(call all-Iaidl-files-under, java)



回答4:


I encountered the same issue with you. The $(call all-java-files-under, java) command will find all aidl files whose name start with "I" (I*.aidl), but the parcelable class should not be included. Two solutions:

(1) Change the parcelable class name, do not start with "I":

parcelable Student;

(2) Move Istudent.aidl from LOCAL_SRC_FILES to LOCAL_AIDL_INCLUDES

LOCAL_SRC_FILES := $(call all-java-files-under, java) \
    java/com/testapp/Itest.aidl

LOCAL_AIDL_INCLUDES := java/com/testapp/Istudent.aidl


来源:https://stackoverflow.com/questions/45043696/android-aidl-refusing-to-generate-code-from-aidl-file-defining-parcelable

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