使用AS建立ADIL文件時AS會在main文件夾下給咱們生成一個aidl文件夾和一個相同包名的包,一般咱們會把全部和ADIL相關的類或文件放在這個包下,可是若是存在自定義的類時,程序編譯時沒法經過,提示找不到自定義的包。解決辦法以下,在啓動Module的build.gradle中加入以下代碼:java
sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' java.srcDirs = ['src/main/java', 'src/main/aidl'] resources.srcDirs = ['src/main/java', 'src/main/aidl'] aidl.srcDirs = ['src/main/aidl'] res.srcDirs = ['src/main/res'] assets.srcDirs = ['src/main/assets'] } }
加入以後完整的build.gradle文件內容以下:android
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "aidl.aidl.demo" minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1.0" } sourceSets { main { manifest.srcFile 'src/main/AndroidManifest.xml' java.srcDirs = ['src/main/java', 'src/main/aidl'] resources.srcDirs = ['src/main/java', 'src/main/aidl'] aidl.srcDirs = ['src/main/aidl'] res.srcDirs = ['src/main/res'] assets.srcDirs = ['src/main/assets'] } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' }
sourceSets中主要是把把src/main/aidl文件也做爲java.srcDirs, resources.srcDirs,這樣當編譯程序時,AIDL中自定義類就能找到了。app