平台
Ubuntu 16.04 + AndroidStudio 3.5.3 + Gradle 4.1
问题
引入原有的部分AIDL文件, 又不想把AIDL放到默认的路径下, 如:
原AIDL路径(ModuleDir/src/main/aidl) 改为ModuleDir/src/main/java/com/myAidlDir
解决
操作如下: 右键模块 -> New -> Folder -> AIDL Folder
如图修改即可:
修改完后, 会在build.gradle中生效
build.gradle
apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "com.app.test" minSdkVersion 21 targetSdkVersion 28 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } //关键代码: sourceSets { main { aidl.srcDirs = ['src/main/aidl', 'src/main/java/com/myAidlDir'] } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) }
关键代码:sourceSets { main { aidl.srcDirs = [‘src/main/aidl’, ‘src/main/java/com/myAidlDir’] } }
参考
How to add aidl file to android studio