Java 在 Android Studio 上将模块或项目作为库导入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20745210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:02:40  来源:igfitidea点击:

Import module or project as Library on Android Studio

javaandroidandroid-studiointellij-idea

提问by joao Beno

I want to use HoloEverywhere (HE) Preferences AddOn with my live wallpaper project. The project is almost done, i just need it to look the same from android 2.3 to 4.4, so i went on and followed the guide to get HE from GitHub.

我想在我的动态壁纸项目中使用 HoloEverywhere (HE) Preferences AddOn。该项目几乎完成,我只需要它从 android 2.3 到 4.4 看起来都一样,所以我继续按照指南从 GitHub 获取 HE。

After the checkout and the successful test of the "Demo" module, i went back to my project, but i can only createa new module, not importone, and of i try to set the new project to the module's folder (library and addons in my case) Android Studio as me if i want to rewrite the module settings, if i do, it create the folder, but it will not compile and the import org.holoeverywherewill not work.

结帐并成功测试“演示”模块后,我回到了我的项目,但我只能创建一个新模块,不能导入一个,并且我尝试将新项目设置到模块的文件夹(库和插件在我的情况下)Android Studio,如果我想重写模块设置,如果我这样做,它会创建文件夹,但它不会编译并且导入 org.holoeverywhere将不起作用。

采纳答案by Helin Wang

Importing modules works correctly in Android Studio 0.5.5

导入模块在 Android Studio 0.5.5 中正常工作

回答by Scott Barta

There isn't an import module command yet; you'll have to do it manually. The high-level overview is that you'll need to set up a build.gradlefile for your library module, include the library module in your project's settings.gradlefile, and add a dependency from your app to the library project (which you can do by hand or through the Project Structure UI).

还没有导入模块命令;你必须手动完成。高级概述是,您需要build.gradle为库模块设置文件,将库模块包含在项目settings.gradle文件中,并将应用程序的依赖项添加到库项目(您可以手动或通过项目结构 UI)。

To set up the library module and include it, you can either author the relevant changes from scratch, or you can go through the Add ModuleUI to create a blank module, and then copy the files from the library into the template. If you want instructions on how to do the latter to include the Facebook library, see this: using facebook sdk in android studioand modify as necessary for holoeverywhere.

要设置库模块并包含它,您可以从头开始创作相关更改,也可以通过添加模块UI 创建一个空白模块,然后将库中的文件复制到模板中。如果您需要有关如何执行后者以包含 Facebook 库的说明,请参阅此内容:在 android studio 中使用 facebook sdk并根据需要进行修改以适用于 holoeverywhere。

回答by Stefano

You can set external module in this way

您可以通过这种方式设置外部模块

In global setting.gradle file add this line

在全局 setting.gradle 文件中添加这一行

def projectDialogsDir = file('path_of_the_module')
def rootProjectDescriptor = settings.rootProject
settings.createProjectDescriptor(rootProjectDescriptor, 'yourModule', projectDialogsDir)
include(':yourModule')

Then in the build.gradle files of your app's module, you have just to add, under dependencies

然后在您的应用程序模块的 build.gradle 文件中,您只需在依赖项下添加

dependencies {
  compile project(':yourModule')
}