【问题标题】:Android custom class dependency for aidl用于aidl的Android自定义类依赖
【发布时间】:2020-04-29 05:59:42
【问题描述】:

所以我有以下项目结构:

.
├── 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.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

总而言之,问题是有一个自定义类,我需要从另一个目录中的应用程序导入。

【问题讨论】:

    标签: java android gradle aidl


    【解决方案1】:

    你需要定义这两个文件

    Info.java

    Info.aidl 单独的 aidl Info.java 文件

    在客户端和远程应用程序中使用相同的包名。

    表示包应该有

    MusicCentral.aidl
    Info.java
    Info.aidl
    

    com.Patel.Central 包中。

    【讨论】:

    • 我为什么需要 Info.aidl? Info 是一个类(实现 parcelable)?此外,我正在尝试通过 gradle 依赖项导入类实现。我不想复制 Info 类的实现。
    • 通过aidl文件设置的客户端和远程共享相同的合同。
    • 是的,合约由客户端和远程共享。但是客户端需要自定义类实现作为依赖。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-30
    • 1970-01-01
    • 2022-01-14
    • 2016-06-22
    • 1970-01-01
    相关资源
    最近更新 更多