0

I have a service with several AIDL files. To one, I just added a custom object that I defined in a .java file as part of the interface as an "in" parameter, and included the .aidl for it with the parcelable declaration.

The build fails with an error stating that the custom Parcelable java class is undefined.

Any idea why Android Studio (or gradle from the command line) would be ignoring the java class definition? The java class implements the Parcelable interface as well as the static CREATOR.

The build process generates the java files from the aidl files, but the original java class is not copied into that directory. While I concede that this may not be how the Android Studio build process works, it is the way that the android-x86 project builds.

Surely someone else has seen where a Parcelable object is not being built by Android Studio, and found a solution...?

JCampy
  • 181
  • 1
  • 5
  • I was able to get this same code to work under an Android Eclipse project, and due to project deadlines, will migrate my development to that platform. However, if anyone knows the answer, it may be helpful to someone else. Incidentally, Eclipse does not copy over the Java file as I would have expected, but the proper class files are generated. – JCampy Mar 24 '15 at 00:57

2 Answers2

1

I have just compiled with parcelable class as follow.

  • Did not place java file with aidl file since studio auto create aidl folder separately.
  • Under aidl folder create package as with the same package path of Paracelable class.
  • Implement Parcelable.Creator & constructor with Parcel argument

For example,

app > java > com.sample.pojo.parcelable > Item.java

app > aidl > com.sample.pojo.parcelable > Interface.aidl

app > aidl > com.sample.pojo.parcelable > Item.aidl

Make sure that the Interface.aidl imports com.sample.pojo.parcelable.Item in code.

Jaekwan
  • 453
  • 1
  • 4
  • 7
  • I was not able to get this to work when I tried it before posting. The Java file was not seen by the aidl build. Further, I'd consider this to be a less-than-optimal solution as sharing the aidl between this and another project means you can't just share the aidl code - you have to hunt down and share specific java files from the java tree as well. This goes against the convention of having the Java file in the aidl tree. – JCampy Apr 15 '15 at 17:08
  • The android studio creates aidl folder in app>aidl in the project structure in studio by default. the structure was not manually manipulated and the both are still in the same project. if you browse with terminal, it creates under app/src/main/aidl/. Yes, this goes against the convention but easier to maintain java files since they are in different folders especially in the studio. – Jaekwan Apr 19 '15 at 07:25
  • This is the only solution that helped me solve my issue because I made a mistake of not keeping the same path for the parcelable class. – waseefakhtar May 09 '21 at 09:37
0

I had the similar issue with Android Studio, as @JCampy rightly said "Eclipse does not copy over the Java file as I would have expected". So to solve this, copy the AIDL files + Parcelable java source distributed by the other app/service and paste at the client project, e.g. under [project]/app/src/main/aidl. Now in the Client app's build.gradle add the following. So basically, you have pointed in your client's project the source path of the parcelable java classes of other app/service.

android {
    compileSdkVersion 29
    defaultConfig {
    ....
    }
    sourceSets { // <-- point to the right source path of AIDL
        main {
            java.srcDirs = ['src/main/java', 'src/main/aidl']
        }
    }
}
explorer
  • 39
  • 1
  • 9