问题描述
我尝试导入一个项目(projLib)作为另一个项目(projAPK)的依赖项.
I tried to import a project(projLib) as dependency for another project(projAPK).
projAPK gradle 有这个:
projAPK gradle has this :
dependencies {
compile project(':libs:NewsAPI')
compile project(':projLib')
}
但是当我同步 gradle 时,它给出了这个错误:
but when i sync the gradle it gives this error:
错误:依赖 Android_2015:projLib:unspecified on project projAPK 解析为不支持作为编译依赖项的 APK 存档.文件:/Users/myname/Documents/Development/Android_2015/libs/projAPK/build/outputs/apk/projLib-release-unsigned.apk
所以我想有两种解决方案:
so I guess there are two solution to this:
- 不知何故让 gradle 认为 projLib 是一个不应编译为 apk 的库
- 以某种方式使 gradle 不显式编译 projLib
问题是,我找不到任何方法.如果你们能提供帮助,那就太棒了:)
The problem is, I couldn't find how to do any of that.Would be awesome if you guys can help :)
推荐答案
在 projLib 的 build.gradle 文件中,你会看到这样的声明:
In projLib's build.gradle file, you'll see a statement like this:
apply plugin: 'com.android.application'
告诉 Gradle 将其构建为应用程序,生成 APK.如果你改成这样:
which tells Gradle to build it as an application, generating an APK. If you change it to this:
apply plugin: 'com.android.library'
它将构建为一个库,生成一个 AAR,它应该可以工作.
it will build as a library, generating an AAR, and it should work.
如果您还需要 projLib 来生成单独的 APK,那么您必须进行一些重构以将您需要的公共代码提取到第三个库模块中,并使两个 APK 都依赖就可以了.
If you also need projLib to generate a separate APK, then you'll have to do some refactoring to pull the common code that you need out into a third library module, and have both APKs depend on it.
库不允许设置 applicationId
,因此如果您看到有关该效果的错误消息,请将其从库的构建脚本中删除.
Libraries aren't allowed to set an applicationId
, so if you see an error message to that effect, remove it from the library's build script.
这篇关于如何将 android 项目作为库导入而不是将其编译为 apk (Android studio 1.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!