Create multiple projects in Android Studio

南楼画角 提交于 2019-12-08 02:21:19

问题


What I want to do:
Create Three android project in android studio
1)Common Project or Library Project(This is a independent project)
2)Project1 which uses library project
3)Project2 which uses library project

What is the problem?
It is easily possible in eclipse but not in android studio. I can't open three project in single window in android studio.I tried to achieve this using modules but it does not fit my requirement,it just add an module in existing project and has a circular dependency problem.

What I tried?
1)http://www.philosophicalhacker.com/2014/10/02/an-alternative-multiproject-setup-for-android-studio/ -It is a lengthy manual process and Android Studio does not support it directly

2)Modules -It adds modules in existing project Please Help me.I am quite new in android studio.


回答1:


You can't have multiple projects in a single window in Android Studio. But you can create two projects and share the common library.

In settings.gradle of project add

include ':commonLibrary'
project(':commonLibrary').projectDir= new File('../path_to_your_library_module')

In build.gradle add compile project(':commonLibrary').

Do this in both projects and the common library will be added as module in both projects. Any changes you make in this library will reflect in both windows




回答2:


You can create two flavors of your Main Project i-e flavor 1 and flavor 2 with different/shared or common codebase,resources,settings or configurations.

Gradle Build System uses a Build Variant and combination of product flavors to generate different apps with shared/common code base and resources.

As per Android Developer Reference Site:

The build system uses product flavors to create different product versions of your app. Each product version of your app can have different features or device requirements. The build system also uses build types to apply different build and packaging settings to each product version. Each product flavor and build type combination forms a build variant. The build system generates a different APK for each build variant of your app. Now one can have two or more product flavors e.g (paid flavor, free/demo flavor) etc for one single project with same code base.

For more information See Build Variants & Product Flavors Doc



来源:https://stackoverflow.com/questions/32862237/create-multiple-projects-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!