java - 用于aidl的Android自定义类依赖
问题描述
所以我有以下项目结构:
.
├── Central
│ ├── app
│ │ ├── build.gradle
│ │ └── src
│ ├── build.gradle
│ ├── gradle.properties
│ └── settings.gradle
└── Client
├── app
│ ├── build.gradle
│ └── src
├── build.gradle
├── gradle.properties
└── settings.gradle
在 Central 应用程序中,我定义了一个服务以及一个 AIDL 接口。在 AIDL 中,其中一个函数返回一个自定义对象(扩展 Parcelable)。在客户端应用程序中,我放置了完全相同的 AIDL 文件(在src/aidl
目录中的同一包下)。我尝试通过声明对 Central 应用程序的 gradle 依赖项来导入自定义类。
这是客户端的settings.grade
rootProject.name='Client'
include ':app'
include ":Central"
project(":Central").projectDir = file('../Central/app')
客户的 app/build.grade:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.Patel.Cli3n5"
minSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(path: ':Central', configuration: 'default')
}
和aidl文件(存在于两个应用程序中):
package com.Patel.Central;
import android.graphics.Bitmap;
parcelable Info;
interface MusicCentral {
List<Info> getAllSongsInfo();
Bitmap getSongImage(int songNum);
}
请注意,Info 类是在包中定义的com.Patel.Central
。
当我尝试构建客户端应用程序时,我收到以下错误:
error: cannot find symbol
@Override public java.util.List<com.Patel.Central.Info> getAllSongsInfo() throws android.os.RemoteException
总之,问题在于有一个自定义类,我需要从另一个目录中的应用程序导入。
解决方案
您需要定义这两个文件
Info.java
和
Info.aidl
Info.javaaidl
的单独文件
在客户端和远程应用程序中具有相同的包名称。
意味着包应该有
MusicCentral.aidl
Info.java
Info.aidl
在com.Patel.Central
包装中。
推荐阅读
- c++ - 当我在 codechef 中遇到错误答案时该怎么办
- scala - 我在scala中尝试冒泡排序程序,因为我在线程“main”java.lang.ArrayIndexOutOfBoundsException中遇到了异常:8
- javascript - 不变违规:在突变后更新 apollo 时找不到字段 XXX
- linq - 如何使用实体框架核心检索插入实体的 ID?
- node.js - 如何从后端监听套接字?
- c++ - 删除文件有什么问题?
- python - 如何将不同版本的二进制文件发布到 pypi.org?
- r - R删除名称并按频率排序ggplot
- proxy - Squid - 允许本地网络访问特定网站
- python - 为什么应用 xlrd.xldate_as_datetime() 函数不会按预期更新数据帧的子集?