AIDL接口找不到Parcelable类进口 [英] AIDL interface can't find import for Parcelable class

查看:1486
本文介绍了AIDL接口找不到Parcelable类进口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题似乎是类似<一个href=\"http://stackoverflow.com/questions/14263005/aidl-unable-to-find-the-definition-of-a-parcelable-class\">this问题和这一个但它是一个有点不同

我作出AIDL服务,是图书馆项目,并在我的应用程序使用它。我有一个类的车辆,是在我的应用程序,我已经parcelable,这样我可以在我的接口使用。 (我想从我的服务车辆列表是在图书馆我的应用程序)

我是否需要Vehicle.java在应用程序和库两者兼而有之?

我需要Vehicle.aidl两个?

我Vehicle.java和Vehicle.aidl在这两个应用程序和库,我​​开始运行到我的应用程序的一个问题,当我从我的界面称为日食的方法想让我把它定义为库类的车辆及不应用(尽管它们是相同的和两者parcelable)。

 公开名单&LT;汽车与GT; getVehicles(){... code ...}

在努力解决这个问题,我试图使它的应用程序的车辆类别,而不是我的IRemoteInterface.aidl图书馆的车辆类(在下面列出的变化,我得到一个错误,它找不到进口。在就像它是List和没有导入其他变体,它说未知的返回类型)。

 封装库;
进口LIBRARY.RelPoint;
进口LIBRARY.IRemoteServiceCallback;
进口LIBRARY.FleetStatus;
进口APPLICATION.Vehicle;
接口IRemoteInterface {    INT GETPID();    无效registerCallback(IRemoteServiceCallback回调);
    无效unregisterCallback(IRemoteServiceCallback回调);    清单&LT;汽车与GT; getVehicles();}

这是我parcelable汽车类从应用程序

 封装应用;进口java.util.Date;进口android.os.Parcel;
进口android.os.Parcelable;
公共类的车辆实现Parcelable {
    公共静态最后弦乐TAG =车辆;    长vehicleID;
    长的TrackID;
    串vehicleName;     公共静态最终Parcelable.Creator&LT;汽车与GT; CREATOR =新Parcelable.Creator&LT;车辆与GT;(){            公车createFromParcel(SRC地块){
                返回新车(SRC);
            }            大众汽车[] newArray(INT大小){
                返回新车【尺寸】;
            }        };        大众汽车(SRC地块){
            readFromParcel(SRC);
        }        公共无效writeToParcel(DEST包裹,INT标志){
            dest.writeLong(vehicleID);
            dest.writeLong(的TrackID);
            dest.writeString(vehicleName);
        }        公共无效readFromParcel(SRC地块){
            vehicleID = src.readLong();
            的TrackID = src.readLong();
            vehicleName = src.readString();        }        公众诠释describeContents(){
            // 没什么特别的
            返回0;
        }
    大众汽车(){    }    //下面我删除getter和setter方法}


解决方案

我相当肯定,你需要有两端在同一个包中的 Parcelable 类(这是通过使用从应用在库侧一端什么了,我只是做了周围的其他方法)。这个包有也可以在相应的 AIDL 文件中声明的之一。

我会建议使用像 com.example.interop 子包,使这个吸尘器(即在自己的包分开共享对象)。那么双方应该在声明它的包+一个 AIDL 文件中的Java文件。

My issue seems to be similar to this question and this one but it is a bit different.

I am making an AIDL service that is in a Library project and using it in my application. I have a class Vehicle that is in my application that I have made parcelable so that I can use it in my interface. (I would like to get a List of vehicles from my service that is in the library to my application)

Do I need a Vehicle.java in both the application and the library?

Do I need a Vehicle.aidl in both?

I had Vehicle.java AND Vehicle.aidl in both application and library and I began running into a problem in my application that when I called a method from my interface eclipse wanted me to define it as the Vehicle of the library class and not the application(although they are the same and both parcelable).

public List<Vehicle> getVehicles(){...code... }

In an effort to resolve this, I tried to make it the application's vehicle class rather than the library's vehicle class in my IRemoteInterface.aidl(in the listed variation below, i get an error that it can't find the import. In other variations like having it be List and no import, it says unknown return type).

  package LIBRARY;


import LIBRARY.RelPoint;
import LIBRARY.IRemoteServiceCallback;
import LIBRARY.FleetStatus;
import APPLICATION.Vehicle;


interface IRemoteInterface {

    int getPid();

    void registerCallback(IRemoteServiceCallback callback);
    void unregisterCallback(IRemoteServiceCallback callback);

    List<Vehicle> getVehicles();

}

Here is my parcelable Vehicle class from the application :

package APPLICATION;

import java.util.Date;

import android.os.Parcel;
import android.os.Parcelable;


public class Vehicle implements Parcelable {
    public static final String TAG = "Vehicle";

    long vehicleID;
    long trackID;
    String vehicleName;



     public static final Parcelable.Creator<Vehicle> CREATOR = new Parcelable.Creator<Vehicle>() {

            public Vehicle createFromParcel(Parcel src) {
                return new Vehicle(src);
            }

            public Vehicle[] newArray(int size) {
                return new Vehicle[size];
            }

        };



        public Vehicle(Parcel src) {
            readFromParcel(src);
        }

        public void writeToParcel(Parcel dest, int flags) {
            dest.writeLong(vehicleID);
            dest.writeLong(trackID);
            dest.writeString(vehicleName);
        }

        public void readFromParcel(Parcel src) {
            vehicleID = src.readLong();
            trackID   = src.readLong();
            vehicleName = src.readString();

        }

        public int describeContents() {
            // nothing special
            return 0;
        }


    public Vehicle() {

    }

    //getter and setter methods below that I removed



}

解决方案

I'm reasonably certain you need to have the Parcelable classes in the same package on both ends (which is what you end up with by using the one from APPLICATION on the library side, I would just do it the other way around). This package has to also be the one declared in the corresponding aidl file.

I'd suggest to use a subpackage like com.example.interop to make this cleaner (i.e., separate the shared objects in their own package). Both sides should then have a Java file in that package + an aidl file that declares it.

这篇关于AIDL接口找不到Parcelable类进口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆