现有项目转换为在Android的工作室库项目 [英] Convert existing project to library project in Android Studio

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

问题描述

我怎样才能将现有的Andr​​oid项目将在Android的Studio中的Andr​​oid库项目? <一href="https://stackoverflow.com/questions/2959820/convert-existing-project-into-android-project-in-eclipse">In Eclipse中,这是可能的。

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

其实,我想一个旧的Andr​​oid项目转换成一个Android库项目,这样我可以使用Android项目的现有code建立在Android的工作室小的改动一个新的Andr​​oid项目。

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

...有:

...with:

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

请注意,近日,机器人已改为com.android.application,而机器人库已改为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 文件后,你应该的同步工程与摇篮文件的(这是在工具栏中),因为不这样做的可能的造成的错误,事情不能正常工作。

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.

机器人工作室然后将更新的一些文件,指示模块现在是一个文库;因为这将被添加到您的.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" />

正如你可能已经知道了,你将无法运行(现在的)库项目 - <一个href="https://stackoverflow.com/questions/16588064/how-do-i-add-a-library-project-to-the-android-studio?rq=1">you需要将它包含到一个应用程序的项目。

<一个href="https://stackoverflow.com/questions/27374933/android-studio-1-0-and-error-library-projects-cannot-set-applicationid/27375066#27375066">If你使用的是Android工作室1.0和您收到库项目不能设置的applicationID,确保你没有的applicationID 在摇篮构建文件。

If you're using Android Studio 1.0 and you are getting "Library projects cannot set applicationId", make sure you do not have applicationId in your Gradle build file.

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

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