Android的工作室:安装外部项目的模块 [英] Android Studio: Setup external project as module

查看:165
本文介绍了Android的工作室:安装外部项目的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用一个外部项目(ResuableProject),为在多个项目模块(其中之一是ProjectOne)。我到目前为止已经在这里做的是:

新增继ProjectOne的settings.gradle

 包括':ProjectOne',':ResuableProject
项目(':ResuableProject')PROJECTDIR =新的文件(settingsDir,'../ResuableProject/module')

在添加以下的build.gradle

  {相关性
    编制项目(':ResuableProject')
}

在没有任何错误,并在工程资源管理器模块gradle这个同步包含但是当我使用任何类从 ResuableProject 它给了我,类不能被发现,直到一个错误我点击类的名字,它给我一个选项,加上ResuableProject 依赖。当我选择该选项的类是可访问的,似乎一切工作的罚款。
但是,当我生成项目并尝试运行它给了我这样的:

 错误:执行失败的任务:ProjectOne:compileDevDebugJava。
>编译失败;详情请参见编译器错误输出。
错误:(10,30)错误:包装< ResuableProject的制造&gt包名;不存在

我缺少的东西还是我必须包括在ProjectOne ResuableProject的源目录,如果是该怎么办?

也有使用多个应用程序一个共同的项目更好的办法? (不罐子或Maven,因为我需要包括每一个项目和普通项目源将在一个单独的混帐回购协议被托管)

previously我使用的Eclipse(一个公共图书馆项目)的这种做法,包括它在多个应用程序。

更新:添加的文件系统结构

 工作区
---- ResuableProject(Android的共同的东西)
--------。混帐
--------模块
---- ProjectOne(Android应用程序一)
--------。混帐
-------- ProjectOne(模块)
------------的build.gradle
-------- settings.gradle
---- ProjectOne(Android应用程序的两个)
--------。混帐
-------- ProjectOne(模块)


解决方案

原来,你可以添加 ResuableProject ,但如果拥有的build.gradle价值不能用其源应用插件:'机器人'即项目的类型是应用程序

我改变了以应用插件:Android的图书​​馆即它必须是一个图书馆,现在一切工作正常。

I need to use an external project(ResuableProject) as module in multiple projects(one of which is ProjectOne). What I've done here so far is:

Added following in settings.gradle of ProjectOne

include ':ProjectOne', ':ResuableProject'
project(':ResuableProject').projectDir = new File(settingsDir, '../ResuableProject/module')

Added following in build.gradle

dependencies {
    compile project(':ResuableProject')
}

After that gradle sync without any error and in Project Explorer the module is included but when I use any class from ResuableProject it gives me an error that class cannot be found until I click on class name and it give me an option to add dependency on ResuableProject. When I select the option the class is accessible and it seems all working fine. But when I Build the project and try to run it gives me this:

Error:Execution failed for task ':ProjectOne:compileDevDebugJava'.
> Compilation failed; see the compiler error output for details.
Error:(10, 30) error: package <packagename of ResuableProject> does not exist

Am I missing something or do I have to include source directory of ResuableProject in ProjectOne, if yes the how?

Also is there a better way to use one common project across multiple apps? (not jar or maven cause I need to include source with every project and common project will be hosted in a separate git repo)

Previously I was using this approach with Eclipse (one common Library project) and including it in multiple apps.

UPDATE: Adding file system structure

workspace
----ResuableProject (Android Common stuff)
--------.git
--------module
----ProjectOne (Android App One)
--------.git
--------ProjectOne (module)
------------build.gradle
--------settings.gradle
----ProjectOne (Android App Two)
--------.git
--------ProjectOne (module)

解决方案

It turned out that you can add ResuableProject but cannot use its source if build.gradle has value apply plugin: 'android' i.e. the type of the project is application.

I changed that to apply plugin: 'android-library' i.e. it must be a library and now everything is working fine.

这篇关于Android的工作室:安装外部项目的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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