使用 Android Studio 的 Android 库项目 [英] Android Library Project using Android Studio

查看:26
本文介绍了使用 Android Studio 的 Android 库项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题可能在某处得到了回答,但找不到合适的.

This question might have been answered somewhere but couldn't find the appropriate one.

我想知道如何在 Android Studio 中创建通用实用程序库项目.我想在其中编写一些常用类和一些常用方法,以便在 Android 应用程序项目中使用.可能就像 Windows 世界中的 .dll 一样 - 一组可以在多个使用者之间共享的通用方法.

I want to know how can I create a common utility library project in Android Studio. I want to write some common classes and some common methods within them to use in Android app projects. Probably like how .dll are in Windows world - a set of common methods that can be shared among multiple consumers.

提前致谢.

推荐答案

最简单的方法:

  1. 右键单击您在 Android Studio 中打开的项目,然后选择 New >模块

在左侧窗格中选择 Android 库并点击下一步.

In the left Pane choose Android Library and click on next.

输入所有详细信息,如果不需要,请取消勾选创建活动、主题和所有内容.

Enter all details, untick Create Activity, Theme and all if not required.

选择与您的项目相同的 API 级别,然后选择 Next、Next、Next.

Choose API level same as your project and Next, Next, Next .

现在你会在你的项目中看到另一个目录,build.gradle for library 将自动为你配置.

Now you will see an another directory inside your project, build.gradle for library will be automatically configured for you.

如果您的模块/库名称是 "mylibrary"

If your module/library name is "mylibrary",

include ':mylibrary' 

将自动添加到项目根目录下的 settings.gradle 文件中.

will be automatically added in settings.gradle file inside root directory of your project.

现在打开你的主模块并在依赖块中插入这一行:

Now open your main module and insert this line in dependency block :

compile project(':mylibrary')

如果您想在其他项目中使用相同的库,您必须使用 File Explore 将库模块复制到该特定项目,并且必须配置 settings.gradle 和主模块的 build.gradle.gradle 手动.

If you want to use same library in other projects, you have to copy the library module to that particular project using File Explore and have to configure settings.gradle and main module's build.gradle manually.

这篇关于使用 Android Studio 的 Android 库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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