簡體   English   中英

Android 自定義 class 依賴於aidl

[英]Android custom class dependency for 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 接口。 在 AIDL 中,其中一個函數返回自定義 object(擴展 Parcelable)。 在客戶端應用程序中,我放置了完全相同的 AIDL 文件(在src/aidl目錄中的相同 package 下)。 我嘗試通過向 Central 應用程序聲明 gradle 依賴項來導入自定義 class。

這是客戶端的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);
}

請注意,信息 class 在 package com.Patel.Central中定義。

當我嘗試構建客戶端應用程序時,我收到以下錯誤:

error: cannot find symbol
    @Override public java.util.List<com.Patel.Central.Info> getAllSongsInfo() throws android.os.RemoteException

總之,問題是有一個自定義 class ,我需要從另一個目錄中的應用程序導入。

您需要定義這兩個文件

Info.java

Info.aidl用於aidl的單獨輔助文件

在客戶端和遠程應用程序中具有相同的 package 名稱。

意味着 package 應該有

MusicCentral.aidl
Info.java
Info.aidl

com.Patel.Central package 中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM