我想通过 aar 在不同的项目中分享我的源代码。当前版本的 Android Studio 能够为库模块自动生成 aar 文件。但我有几个问题:
- 如何将aar文件输出到特定文件夹?
当前输出位于 build/outputs/aar 文件夹中。编译完成后可以自动移动文件吗?
- 库模块中的依赖项不会被应用模块继承。例如:
我的库模块(build.gradle):
apply plugin: 'com.android.library'
......
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.code.gson:gson:2.2.4'
}
我的应用模块:
apply plugin: 'com.android.application'
repositories {
mavenCentral()
flatDir {
dirs 'myaarfolder'
}
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.company.appid"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile(name:'mylib-release', ext:'aar')
}
我收到类似的错误:
错误:(3, 35) 错误: com.google.gson.annotations 包不存在
我必须在我的应用程序模块(build.gradle)的依赖项中添加compile 'com.google.code.gson:gson:2.2.4'
任何想法?谢谢