How can I convert an existing Android project into an Android library project in Android Studio? In Eclipse, that is possible.
如何将现有的Android项目转换为Android Studio的Android库项目?在Eclipse中,这是可能的。
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.
实际上,我想把一个旧的Android项目转换成一个Android库项目,这样我就可以使用那个Android项目的现有代码来构建一个新的Android项目,在Android Studio中做一些小小的改动。
5 个解决方案
#1
77
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
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.
注意,最近,“android”已经变成了“com.android”。而“android-library”则改为“com.android.library”。避免在新项目中使用旧名称。
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 will then update some files to indicate that the module is now a library; as this will be added into your .iml file:
然后Android Studio会更新一些文件,表明模块现在是一个库;因为这将被添加到你的。iml文件:
<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。
#2
3
Looking at this document http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup
查看此文档http://tools.android.com/techdocs/新建- system/userguide # toc - multiprojectsetup。
I think all you have to do is add this to your build.gradle file,
我认为你所要做的就是将它添加到你的构建中。gradle文件,
Creating a Library Project
创建一个库项目
apply plugin: 'android-library'
From the link
从链接
Creating a Library Project
创建一个库项目
A Library project is very similar to a regular Android project with a few differences.
一个库项目与一个普通的Android项目非常相似,有一些不同之处。
Since building libraries is different than building applications, a different plugin is used. Internally both plugins share most of the same code and they are both provided by the same com.android.tools.build.gradle jar.
由于构建库与构建应用程序不同,因此使用了不同的插件。在内部,两个插件共享大部分相同的代码,它们都由相同的com.android.tools.build提供。gradle jar。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 15
}
#3
0
open project in file explorer,open project.properties and try changing android.library=true in project.properties
在文件资源管理器中打开项目,打开项目。属性并尝试改变android。图书馆在project.properties = true
#4
0
This is a late response, but I've been trying to do the same thing. None of the above seem to have done the job for me, but I found this that I think works:
这是一个迟来的回复,但我一直在尝试做同样的事情。以上似乎都没有为我做过工作,但我发现我认为这是可行的:
Right click on the project name -> Mark Directory As (at bottom) -> Sources Root
右击项目名称->标记目录(在底部)->源根。
I don't know the difference between Resources Root and Sources Root, and a bit of googleing to turn up the answer, but hopefully that's right. I just know a Library isn't supposed to build an apk, and after setting this option, it's not able to so I'm assuming it works.
我不知道资源根和源根之间有什么区别,也不知道谷歌搜索是否能找到答案,但希望这是对的。我只知道一个库不应该构建一个apk,在设置了这个选项之后,它不能,所以我假设它可以工作。
If anybody else knows more than me, please say so!
如果有人知道的比我多,请说出来!
#5
0
If you make it with command line, like chanakya propose, you have to update it with:
如果您使用命令行(如chanakya所建议的)进行更新,则必须使用:
android update lib-project \
--target <target_ID> \
--path path/to/your/project
see: http://developer.android.com/tools/projects/projects-cmdline.html#ReferencingLibraryProject
见:http://developer.android.com/tools/projects/projects-cmdline.html ReferencingLibraryProject
That work for eclipse, but not for android-studio since that update the build.xml
.
这适用于eclipse,但不适用于android-studio,因为它更新了build.xml。
#1
77
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
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.
注意,最近,“android”已经变成了“com.android”。而“android-library”则改为“com.android.library”。避免在新项目中使用旧名称。
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 will then update some files to indicate that the module is now a library; as this will be added into your .iml file:
然后Android Studio会更新一些文件,表明模块现在是一个库;因为这将被添加到你的。iml文件:
<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。
#2
3
Looking at this document http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup
查看此文档http://tools.android.com/techdocs/新建- system/userguide # toc - multiprojectsetup。
I think all you have to do is add this to your build.gradle file,
我认为你所要做的就是将它添加到你的构建中。gradle文件,
Creating a Library Project
创建一个库项目
apply plugin: 'android-library'
From the link
从链接
Creating a Library Project
创建一个库项目
A Library project is very similar to a regular Android project with a few differences.
一个库项目与一个普通的Android项目非常相似,有一些不同之处。
Since building libraries is different than building applications, a different plugin is used. Internally both plugins share most of the same code and they are both provided by the same com.android.tools.build.gradle jar.
由于构建库与构建应用程序不同,因此使用了不同的插件。在内部,两个插件共享大部分相同的代码,它们都由相同的com.android.tools.build提供。gradle jar。
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 15
}
#3
0
open project in file explorer,open project.properties and try changing android.library=true in project.properties
在文件资源管理器中打开项目,打开项目。属性并尝试改变android。图书馆在project.properties = true
#4
0
This is a late response, but I've been trying to do the same thing. None of the above seem to have done the job for me, but I found this that I think works:
这是一个迟来的回复,但我一直在尝试做同样的事情。以上似乎都没有为我做过工作,但我发现我认为这是可行的:
Right click on the project name -> Mark Directory As (at bottom) -> Sources Root
右击项目名称->标记目录(在底部)->源根。
I don't know the difference between Resources Root and Sources Root, and a bit of googleing to turn up the answer, but hopefully that's right. I just know a Library isn't supposed to build an apk, and after setting this option, it's not able to so I'm assuming it works.
我不知道资源根和源根之间有什么区别,也不知道谷歌搜索是否能找到答案,但希望这是对的。我只知道一个库不应该构建一个apk,在设置了这个选项之后,它不能,所以我假设它可以工作。
If anybody else knows more than me, please say so!
如果有人知道的比我多,请说出来!
#5
0
If you make it with command line, like chanakya propose, you have to update it with:
如果您使用命令行(如chanakya所建议的)进行更新,则必须使用:
android update lib-project \
--target <target_ID> \
--path path/to/your/project
see: http://developer.android.com/tools/projects/projects-cmdline.html#ReferencingLibraryProject
见:http://developer.android.com/tools/projects/projects-cmdline.html ReferencingLibraryProject
That work for eclipse, but not for android-studio since that update the build.xml
.
这适用于eclipse,但不适用于android-studio,因为它更新了build.xml。