如何将模块编译为 AAR 并在一次构建中将其包含在项目中?
How to compile a module as an AAR and include it in the project in one build?
我有一个应用程序模块和一个用作库的模块 -- 我仍在对库进行更改,因此未对其进行预编译。库模块有自己的 res 文件夹,我想将其与主应用程序的 res 文件夹分开。我相信这样做的唯一方法是在将库包含在主应用程序之前将其打包为 aar。如果我可以 运行 单个 Gradle 构建来打包库并包含它,那将很方便。这可能吗?
gradle.build 用于应用程序(编译 "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 我的图书馆:
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 文件夹的库模块。我的错误来自清单文件中的冲突。
我有一个应用程序模块和一个用作库的模块 -- 我仍在对库进行更改,因此未对其进行预编译。库模块有自己的 res 文件夹,我想将其与主应用程序的 res 文件夹分开。我相信这样做的唯一方法是在将库包含在主应用程序之前将其打包为 aar。如果我可以 运行 单个 Gradle 构建来打包库并包含它,那将很方便。这可能吗?
gradle.build 用于应用程序(编译 "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 我的图书馆:
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 文件夹的库模块。我的错误来自清单文件中的冲突。