Java 如何将一个 android studio 项目合并到另一个 android studio 项目中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33528400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to combine one android studio project into another android studio project
提问by Phoneswapshop
I have two separate android app projects that were made in android studio I am trying to combine project 1 into project 2 to make it all one app how would I go about doing this? I know how to do it in eclipse but not in android studio. Please note they are both of these projects are android applications none of them are android libraries.
我有两个独立的 android 应用程序项目,它们是在 android studio 中制作的,我正在尝试将项目 1 合并到项目 2 中,以使其成为一个应用程序,我该怎么做?我知道如何在 eclipse 中做到这一点,但在 android studio 中却不知道。请注意,这两个项目都是 android 应用程序,它们都不是 android 库。
Any help would be amazing!
任何帮助都会很棒!
When I import project 1 into project module I get this error on grade build:
当我将项目 1 导入项目模块时,我在等级构建时收到此错误:
Warning:Dependency School Tools Calc lib.gz:SchoolTools:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. File: /Users/chrisdebrodie/Documents/School Tools Calc lib.gz/SchoolTools/build/outputs/apk/SchoolTools-release-unsigned.apk
警告:Dependency School Tools Calc lib.gz:SchoolTools:unspecified on project app 解析为不支持作为编译依赖项的 APK 存档。文件:/Users/chrisdebrodie/Documents/School Tools Calc lib.gz/SchoolTools/build/outputs/apk/SchoolTools-release-unsigned.apk
采纳答案by Jim
You cannot have two "projects" as a single project in Android Studio.
您不能在 Android Studio 中将两个“项目”作为一个项目。
Convert one (or both) project into libraries. Then create a "shell" project to build each app. The shell project is basically empty, or it may have build specific value overrides. The advantage here is that you can modify the library and changes will be immediately reflected in both/all versions. The drawback is that you will have to fix any issues in all projects that result from any change to any library. But you can then create the "combined" project in a similar manner.
将一个(或两个)项目转换为库。然后创建一个“shell”项目来构建每个应用程序。shell 项目基本上是空的,或者它可能具有构建特定的值覆盖。这里的优点是您可以修改库,更改将立即反映在两个/所有版本中。缺点是您必须修复所有项目中因对任何库进行任何更改而导致的任何问题。但是您可以以类似的方式创建“组合”项目。
After you convert one or both to a library you can create an aar
file. This gives you the option to then include that aar
as a gradle dependency. Be careful to remember that you will need to re-build the aar
every time you modify that project - so if you have an indication as to which is the more stable codebase, go with that for the aar
. This gives you the ability to "version control" the main project dependency so that you can make changes to one project without impacting the stability of the other.
将一个或两个转换为库后,您可以创建一个aar
文件。这使您可以选择将其包含aar
为 gradle 依赖项。请注意,aar
每次修改该项目时都需要重新构建aar
. 这使您能够对主要项目依赖项进行“版本控制”,以便您可以对一个项目进行更改,而不会影响另一个项目的稳定性。
Additionally, you can write scripts and use tools like Bamboo or Jenkins to do real-time updates to the aar
- but that is like using a "snapshot" dependency. When you change the aar
it may compile, but it may break the build of the second project without you knowing it until you do a build on that project. (And yes, you can include a build on that project as a part of the Bamboo or Jenkins script, but it isn't easy.)
此外,您可以编写脚本并使用 Bamboo 或 Jenkins 之类的工具来实时更新aar
- 但这就像使用“快照”依赖项。当您更改aar
它时,它可能会编译,但它可能会在您不知道的情况下破坏第二个项目的构建,直到您对该项目进行构建。(是的,您可以将该项目的构建作为 Bamboo 或 Jenkins 脚本的一部分包含在内,但这并不容易。)
There may be other alternatives, but these seem to offer enough options to produce a wide variety of build options.
可能还有其他选择,但这些似乎提供了足够的选择来产生各种各样的构建选项。
回答by davehenry
回答by Hymans Gong
I write a repo to handle this staff safely and easily: Hymansgong/android-project-combine.
我编写了一个 repo 来安全轻松地处理这些员工:Hymansgong/android-project-combine。
Characteristics:
特征:
- Just a developing env wrapper, it can't modify projects, safe to use. Different Android projects develop together at the one Android Studio window.
- Find References and Jump into source code rather than .class file on jar package.
- Jump out of the each projects compile system and using the official compile system.
- Very light, very fast for each time you want to refresh combine project.
- 只是一个开发环境包装器,它不能修改项目,使用安全。不同的 Android 项目在一个 Android Studio 窗口中一起开发。
- 查找引用并跳转到源代码而不是 jar 包上的 .class 文件。
- 跳出各个项目编译系统,使用官方编译系统。
- 每次要刷新组合项目时都非常轻巧,速度非常快。