本地aar共享Android studio源代码
我想通过aar在不同的项目之间共享我的源代码。当前版本的Android studio能够为库模块自动生成aar文件。但我有几个问题:本地aar共享Android studio源代码,android,android-studio,aar,Android,Android Studio,Aar,我想通过aar在不同的项目之间共享我的源代码。当前版本的Android studio能够为库模块自动生成aar文件。但我有几个问题: 如何将aar文件输出到特定文件夹 当前,输出位于build/outputs/aar文件夹中。编译完成后,我可以自动移动文件吗 应用程序模块不会继承库模块中的依赖项。例如: 我的库模块(build.gradle): 我的应用程序模块: apply plugin: 'com.android.application' repositories { mavenC
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)的依赖项中添加编译'com.google.code.gson:gson:2.2.4'
有什么想法吗?感谢AAR文件没有将其依赖项烘焙到其中,因此,如果您包括这样的裸AAR,则需要在父模块中手动添加依赖项。要做您想要做的事情,您需要将AAR打包到Maven工件中,并在POM中指定其依赖项。快速搜索Google会发现这个链接,看起来它是针对旧版本的Android Gradle插件,但它可能会让你继续,或者你可以自己搜索更好的资源: 如果您想处理输出文件的名称,您可以从这个问题中获得灵感,该问题重命名了输出: 本质上,它涉及一个构建脚本块,如下所示:
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, /* calculate new path here */)
}
}
谢谢你的回复。实际上我知道你提到的方法。但因为新的Android Studio(1.0.0)能够在编译期间生成aar。所以我认为我们可能不需要Maven方法。问题是我不知道如何将aar文件输出到一个特定的目录。不过,我的答案是——如果您直接包括AAR,则需要向父项目添加依赖项。我得到了以下错误:“错误:(23,0)在com.android.build.gradle.LibraryExtension上找不到属性'applicationVariants'_Decorated@5f0a7d2c.“我应该在哪里添加此脚本?谢谢
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, /* calculate new path here */)
}
}