0

I am teaching myself binder for c++ and there is barely any documentation, so I'm hoping someone can help me figure out why my aidl file isn't compiling for my custom c++ class.

Here is my class header:

1 #include <binder/Parcel.h>
  2 #include <binder/Parcelable.h>
  3 #include <binder/Status.h>
  4 #include <string>
  5 
  6 class CustomType : public android::Parcelable {
  7     public:
  8         bool mem1;
  9         std::string mem2;
 10         int mem3;
 11 
 12         CustomType();
 13         virtual ~CustomType();
 14 
 15         virtual android::status_t writeToParcel(android::Parcel* parcel) const 
    override;
 16         virtual android::status_t readFromParcel(android::Parcel* const parcel) 
    override;
 17 }

Here is its implementation:

1 #include <vector>
  2 #include <customDataType/CustomType.h>
  3 
  4 CustomType::CustomType(){
  5     mem1 = false;
  6     mem2 = "test";
  7     mem3 = 10;
  8 }
  9 
 10 ~CustomType();
 11 
 12 android::status_t CustomType::writeToParcel(android::Parcel* parcel) const{
 13     android::status_t status = OK;
 14     if(status = parcel->write(&mem1, sizeof(bool); status != OK) return status;
 15     if(status = parcel->wwriteString8(mem2); status != OK) return status;
 16     if(status = parcel->writeInt32(mem3); status != OK) return status;
 17 
 18     return status;
 19 }
 20 
 21 android::status_t ustomType::readFromParcel(const android::Parcel* parcel) {
 22     android::status_t status = OK;
 23     if(status = parcel->read(&mem1, sizeof(bool)); status  != OK) return status;
 24     mem2 = parcel->readString8();
 25     if(status = parcel->readInt32(&mem3); status != OK) return status;
 26 
 27     return status;
 28 }

Here is the aidl file defining the Parcelable:

  1 package customDataType;
  2 parcelable CustomType cpp_header "customDataType/CustomType.h";

Here is the aidl file defining the interface:

  1 package customDataType;
  2 
  3 import customDataType.CustomType;
  4 
  5 interface ICustomDataType {
  6     boolean printMemsToScreen(in CustomType data);
  7 }

I'm not sure what order I compile the aidl files in and whether or not I need to compile the c++ files first.

I have tried these two aidl-cpp commands: aidl-cpp ICustomType.aidl . ICustomType.cpp aidl-cpp ICustomDataType.aidl . ICustomDataType.cpp

The first gives me "refusing to generate code from aidl file defining parcelable" and the second gives me "couldn't find import for class customDataType.CustomType"

Thank you for your help!

jkr
  • 1
  • 1
  • 2
    Tactical note: Adding line numbers to code examples is annoying to folks who want to take your code and drop it into their tools to build and experiment. It's usually better to mark lines of interest with a comment. – user4581301 Apr 19 '22 at 17:10
  • `~CustomType();` in the implementation file is odd because it doesn't implement anything. – user4581301 Apr 19 '22 at 17:12

0 Answers0