java - Android自定义aidl类依赖

标签 java android gradle aidl

所以我有以下项目结构:

.
├── Central
│   ├── app
│   │   ├── build.gradle
│   │   └── src
│   ├── build.gradle
│   ├── gradle.properties
│   └── settings.gradle
└── Client
    ├── app
    │   ├── build.gradle
    │   └── src
    ├── build.gradle
    ├── gradle.properties
    └── settings.gradle

在 Central 应用程序中,我定义了一个服务以及一个 AIDL 接口(interface)。在 AIDL 中,其中一个函数返回一个自定义对象(它扩展了 Parcelable)。在客户端应用程序中,我放置了完全相同的 AIDL 文件(在 src/aidl 目录中的同一包下)。我尝试通过声明对 Central 应用程序的 gradle 依赖项来导入自定义类。

这是客户端的settings.gralde

rootProject.name='Client'
include ':app'

include ":Central"
project(":Central").projectDir = file('../Central/app')

客户端的app/build.gralde:

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.java 的单独 aidl 文件

在客户端和远程应用程序上具有相同的包名称。

表示包应该有

MusicCentral.aidl
Info.java
Info.aidl

com.Patel.Central包中。

关于java - Android自定义aidl类依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61495205/

相关文章:

java - 游戏循环中的 "Undo move"

java - 如何检查 IBAN 验证?

android - 在 Java 代码中获取自定义属性的值

android - Phonegap 安卓 : Load local html from hosted application

javascript - 无法解析 Gradle 依赖项

android - 指定的 Gradle 分布 'https://services.gradle.org/distributions/gradle-4.6-all.zip' 似乎不包含 Gradle 分布

找不到 Android gradle 定义方法

java - 如何在 bash 文件中添加依赖项?

java - Android如何计算网络使用数据包/数据

android - 推送通知不适用于 FCM