我有一个应用程序模块和一个用作库的模块 - 我仍在对库进行更改,因此它没有预编译。库模块有自己的 res 文件夹,我想将其与主应用程序的 res 文件夹分开。我相信做到这一点的唯一方法是在将其包含在主应用程序中之前将库打包为 aar。如果我可以运行单个 Gradle 构建来打包库并包含它,那将很方便。这可能吗?
gradle.build for app(编译"my-library"(:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.app.id"
minSdkVersion 18
targetSdkVersion 25
versionCode 5
versionName "1.4"
}
sourceSets {
main {
assets.srcDirs = [project.ext.ASSET_DIR]
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile project(':my-library')
}
gradle.build for my-library:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 18
targetSdkVersion 25
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
事实证明,Android Studio 足够聪明地处理带有 res 文件夹的库模块。我的错误来自清单文件中的冲突。