在 Android Studio 中将现有项目转换为库项目 [英] Convert existing project to library project in Android Studio

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

问题描述

如何在 Android Studio 中将现有的 Android 项目转换为 Android 库项目?在 Eclipse 中,这是可能的.

How can I convert an existing Android project into an Android library project in Android Studio? In Eclipse, that is possible.

实际上,我想将一个旧的 Android 项目转换为一个 Android 库项目,以便我可以使用该 Android 项目的现有代码来构建一个新的 Android 项目,并在 Android Studio 中稍作改动.

Actually, I want to convert an old Android project into an Android library project so that I can use existing code of that Android project to build a new Android project with minor changes in Android Studio.

推荐答案

在你模块的 build.gradle 文件(不是根项目,如果你使用模块!),只需替换:

In your module's build.gradle file (not the root project, if you use modules!), simply replace:

apply plugin: 'com.android.application'
// or, if you're on an old version
apply plugin: 'android' // note: this one is deprecated

...与:

apply plugin: 'com.android.library'
// or, if you're on an old version
apply plugin: 'android-library' // note: this one is deprecated

请注意,最近android"已更改为com.android.application",而android-library"已更改为com.android.library".避免在新项目中使用旧名称.

Note that recently, 'android' has changed to 'com.android.application', while 'android-library' has been changed to 'com.android.library'. Avoid using the old names in new projects.

更新您的 build.gradle 文件后,您应该将项目与 Gradle 文件同步(在工具栏中),因为不这样做可能 导致错误和工作不正常.

After updating your build.gradle file, you should Sync Project with Gradle files (which is in the toolbar), as not doing it might result in errors and things not working correctly.

Android Studio 然后会更新一些文件以表明该模块现在是一个库;因为这将被添加到您的 .iml 文件中:

Android Studio will then update some files to indicate that the module is now a library; as this will be added into your .iml file:

<option name="LIBRARY_PROJECT" value="true" />

您可能已经知道,您将无法运行(现在)库项目 -- 您需要将其包含到应用项目中.

As you might already know, you will not be able to run your (now) library project -- you will need to include it into an app project.

如果你重新使用 Android Studio 1.0 并且您收到库项目无法设置 applicationId",请确保您的 Gradle 构建文件中没有 applicationId.

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

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