android - 在 Android Studio 中将现有项目转换为库项目

标签 android android-studio android-library

如何在 Android Studio 中将现有的 Android 项目转换为 Android 库项目? In Eclipse, that is possible.

实际上,我想将一个旧的 Android 项目转换为一个 Android 库项目,这样我就可以使用该 Android 项目的现有代码在 Android Studio 中构建一个新的 Android 项目。

最佳答案

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

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”。避免在新项目中使用旧名称。

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

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

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

您可能已经知道,您将无法运行(现在)库项目 -- you will need to include it into an app project .

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 - 在 Android Studio 中将现有项目转换为库项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17614250/

相关文章:

安卓包管理器 : check if a library APK has been installed

android - 风格没有得到应用

java - 将字符串保存到内部存储并检索它时,换行符会丢失。如何保留换行符?

java - 为什么我的 AndroidHttpClient 在我调用 Execute 时不发送参数?

android - 如何在 gradle 中获取当前选择的构建变体?

android - 在模块(android 库)中使用改造 2.4.0 时出现 NoClassDefFoundError

java - 当子类在另一个包中时无法覆盖父类(super class)的抽象方法

android - 如何使用 SQLite 在 Android 中将整个数据库表数据显示到 TextView 中

java - 如何修复错误: cannot find symbol in android studio SQLite database

android - 启动画面不首先显示在应用程序上