在 Android Studio 中,如何将应用项目更改为库? [英] in Android Studio, how can I change an app project to a library?

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

问题描述

我确定这很简单,但是因为我今天才开始使用Android Studio,所以找不到它.在过去的一个小时里,我也用谷歌搜索过,没有发现任何指定的帖子:

I'm sure this is simple, but since I just started using Android Studio today, I can't find it. I have also googled for the past hour and found no posts that specify:

如何将现有应用程序项目更改为库.

how to change an existing application project to a library.

我发现的一切都是关于如何创建一个新的库项目.不是如何转换一个.

Everything I found was about how to create a new library project. Not how to convert one.

一个子问题,是如何查看项目是配置为应用程序还是库?我希望这两个问题的答案是一样的.

A sub-question, is how can I see if a project is configured as an application or a library? I would hope that the answer to both of these questions is the same.

推荐答案

打开你的应用程序的build.gradle(在你的应用程序目录中)并修改:

Open your build.gradle of your app (inside your app directory) and modify :

apply plugin: 'com.android.application'

apply plugin: 'com.android.library'

如果你的 build.gradle 中有一个 applicationId 删除它:

If you have an applicationId in your build.gradle remove it :

defaultConfig {
     applicationId "com.your.application.id"
}

然后清理您的项目并重建或仅从 Android Studio 同步您的 gradle

then clean your project and rebuild or just sync your gradle from Android Studio

如果您添加了一些额外的 gradle 属性,例如 applicationVariants.all,则必须将其替换为 libraryVariants.all,如果将库转换为应用程序,则反之亦然

If you have added some extra gradle properties like applicationVariants.all you must replace with libraryVariants.all and vice-versa if you convert a library to application

如果您想在重新转换中添加一个新步骤,您可以将 Android-Studio 默认创建的模块名称app"更改为更适合库模块的名称.您可以使用 重命名目录应用程序.打开 settings.gradle 文件(在项目的根目录下)并将 app 替换为 .然后转到 Menu Build > Make module <your_module_name> 就这样,您的模块已重命名.

If you want to add a new step to your reconversion you can change the module name "app" created by default by Android-Studio with a name more adapted to a library module. You can rename the directory app with <your_module_name>. open settings.gradle file (at the root of your project) and replace app with <your_module_name>. Then Go to Menu Build > Make module <your_module_name> and there you are, your module is renamed.

这篇关于在 Android Studio 中,如何将应用项目更改为库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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