现有项目转换为在Android的工作室库项目项目、转换为、工作室、Android

2023-09-04 10:48:24 作者:千纸鹤

我怎样才能将现有的Andr​​oid项目将在Android的Studio中的Andr​​oid库项目? 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" />

正如你可能已经知道了,你将无法运行(现在的)库项目 - you需要将它包含到一个应用程序的项目。

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.