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

查看:624
本文介绍了在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.

推荐答案

打开你的版本。 gradle 您的应用程序(在您的应用程序目录中)并修改:

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

apply plugin: 'com.android.application'

with

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,其名称更适合库模块。您可以使用< your_module_name> 重命名目录应用程序。打开 settings.gradle 文件(在项目的根目录下)并将应用程序替换为< your_module_name> 。然后转到菜单构建>生成模块< 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天全站免登陆