JCampy
JCampy

Reputation: 191

Android Studio/Gradle fails to build due "missing" Parcelable class in java file

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...?

Upvotes: 0

Views: 1541

Answers (2)

explorer
explorer

Reputation: 39

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']
        }
    }
}

Upvotes: 0

Jaekwan
Jaekwan

Reputation: 473

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.

Upvotes: 1

Related Questions