在android studio 2023.2中使用
1、在buidl.gradle增加以下配置,然后同步。不增加这些配置,创建aidl时显示为灰色,不能创建
buildFeatures {compose true// Disable unused AGP featuresbuildConfig falseaidl truerenderScript falseresValues falseshaders false}
2、在服务端创建aidl文件
在service项目上右键->new->AIDL->AIDL File->输入接口名字IServiceRemoteBindler
在IServiceRemoteBindler增加setData()方法
// IServiceRemoteBindler.aidl
package com.tjjingpan.study.aidlservice;// Declare any non-default types here with import statementsinterface IServiceRemoteBindler {/*** Demonstrates some basic types that you can use as parameters* and return values in AIDL.*/void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,double aDouble, String aString);void setData(String data);
}
注意将service app 生成的 IServiceRemoteBindler.java复制到client的aidl包下
3、重新生成项目reBuild项目
项目原代码:
aidltest: android aidl使用,学习 (gitee.com)