如何导入Android项目的库但不将其编译为APK(Android的工作室1.0) [英] How to import android project as library and NOT compile it as apk (Android studio 1.0)

查看:132
本文介绍了如何导入Android项目的库但不将其编译为APK(Android的工作室1.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个项目(projLib)导入为依赖于另一个项目(projAPK)。

I tried to import a project(projLib) as dependency for another project(projAPK).

projAPK摇篮有这样的:

projAPK gradle has this :

dependencies {
    compile project(':libs:NewsAPI')
    compile project(':projLib')
}

但是当我同步的摇篮它给这个错误:

but when i sync the gradle it gives this error:

错误:依赖Android_2015:projLib:未指定项目projAPK解析为不支持作为一个编译依赖的APK档案。文件: /Users/myname/Documents/Development/Android_2015/libs/projAPK/build/outputs/apk/projLib-release-unsigned.apk

Error:Dependency Android_2015:projLib:unspecified on project projAPK resolves to an APK archive which is not supported as a compilation dependency. File: /Users/myname/Documents/Development/Android_2015/libs/projAPK/build/outputs/apk/projLib-release-unsigned.apk

所以我想有两个解决方案,以这样的:

so I guess there are two solution to this:

  1. 在以某种方式使摇篮认为projLib是不应该被编译为APK
  2. 在以某种方式使摇篮没有明确编译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'

它告诉摇篮建立它作为一个应用程序,生成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,那么你就必须做一些重构拉,你需要出到第三个库模块共同code,并有双方的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的工作室1.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆