Is there a way to have different modules in Intellij depends on my current working environment?
E.g.
Workspace:
Module A - Android App
Module B - Android Lib
Module C - Acceptance Tests
Module D - Feature Tests
Module E - Android Test App for libs
Configuration 1 - working on app and lib
Module A
Module B
Configuration 2 - working on tester app
Module A
Module B
Module E
Configuration 3 - tests
all modules
I'm using gradle building tool and I store my modules in settings.gradle.
I would be appreciate to be able to manipulate the list of modules in settings.gradle file from the Intellij however it could be some better way for it.
The only way (that I know of) to do this to create new blank IntelliJ projects for each configuration and then import the modules in which you are interested into each project.
EDIT: A second way that might work for you is to use the favourites. Open up the favourites windows and add 3 new favourites lists, one for each set up. Then go to a module in the project view and select "add to favourites" and select the relevant list. Repeat this for each module and list.
Again it's not quite what you want but might be good enough.
After few days looking into different solutions I finally found the way how to achieve it.
There is an option in Gradle project tool than gives you the opportunity to exclude not required modules. Select Project Data To Import lets you do the magic in IntelliJ.
Related
In 10 minutes, I created an empty android library and an empty android application in this git repository
https://github.com/deanhiller/compositeAndroid
As seen in my last commit, I quickly convert the android application do depend on the library via gradle's awesome composite build feature (We use this feature a TON in our monorepo so loading a project loads all the libraries source code that it uses as well). Our library is shared amongst a few projects.
I cd into compositeAndroid/MyApplication and run ./gradlew build and it fails with
* What went wrong:
Could not determine the dependencies of task ':app:mergeReleaseAssets'.
> Could not resolve all task dependencies for configuration ':app:releaseRuntimeClasspath'.
> Could not resolve com.tray.android:MyLib.
Required by:
project :app
> No matching configuration of project :MyLib was found. The consumer was configured to find a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.1.0' but:
- None of the consumable configurations have attributes.
I am not sure how to work around this. I have a work around to publish/consume but would much prefer composite builds as it brings the source of libraries into intellij cleanly.
Why is composite builds not working? Is there something special I have to do for android projects? The above repo I setup in 10 minutes with those 2 projects(brand new).
You can always clone and play with it yourself as well. (We will actually be releasing our monorepo open-source template however it is not working to well with android just yet).
After looking into the code under MyLib folder in the repository you shared here - it seems you've opened a regular project and intend to use it as a library
Can you please follow the steps required here and test it under a new module?
Hint: your build should result with an aar file
I'm coming from the Visual Studio world of solutions, where each solution can consist of multiple projects that can refer to each other.
What I want to do is create a modular Android project in Android Studio such that all my code doesn't live in one huge app project. However, it seems terribly difficult to do this, so much so that I am sure I am doing something wrong.
I created a blank project called MyProject. This creates a project with the name MyProject and a package com.sohum.myproject. There is a single app project contained within containing no source files.
I now want to add another module under the same namespace (e.g. com.sohum.myproject.library1). However, it seems when I try to add a new module via the menu, I can only do so into a com.sohum.library1 project. How do I get it to use the same package as the project?
My end goal is to have all my modules under the com.sohum.myproject package, referencing each other. For example:
com.sohum.myproject.application will be the entry point. It might depend on com.sohum.myproject.library1 and com.sohum.myproject.someotherlibrary. And I would like to see all of these modules when I open the MyProject file.
You can click File > New > New Module. Then choose Android Library and enter the details.
Reference: https://developer.android.com/studio/projects/android-library
Another way is to set up the project in a subpackage when creating it.
For example, create a project MyProject in a root directory. Call the application Application and rename the package to be com.sohum.myproject.app instead of just com.sohum.myproject. Now any new modules created will be added below the com.sohum.myproject package space.
I know this has been asked before but I haven't seen a working solution. I have two android studio (V 3.1.3) projects, MyAppBasic and MyAppPro. They each have 3 modules in common and one that is unique. My current implementation is duplicating the 3 common modules in each project. Obviously this is undesirable. What is the recommended way to implement these two apps and avoid code duplication? Thanks.
In case both of your project: MyAppBasic and MyAppPro, have almost a similar code, you can merge them and use build variant to differentiate between basic and pro app.
You also need to installing each module as a local library by using Gradle Android Maven plugin (you can see this answer for details: https://stackoverflow.com/a/33736043/4758255). Then you only need to maintain 3 common modules which is reusable as the libraries for both of your projects.
There is a problem with importing Cardboard SDK to my project.
I downloaded cardboard-java Github repository
then copied the files from it's library to my project's library folder and added the following dependencies:
compile project(':libraries-common')
compile project(':libraries-commonwidget')
compile project(':libraries-videowidget')
But it gives error saying:
Project with path ':libraries-common' could not be found in project
':app'.
Please help me to understand what I'm doing wrong, and tell me if there is another way of importing the SDK.
Thanks
The project syntax is used to describe a dependency on a separate subproject of your root Gradle project. Note that the example repository is aware of all the library subprojects. You probably need to update your own settings.gradle to similarly be aware of the library subprojects you have copied into your Android Studio project.
Alternatively, start over and make sure you follow every step from this Getting Started guide. In particular, using the New module import method should automatically update your settings.gradle file as you go:
First, grab all the required .AAR files from the libraries folder of the sdk. To determine which .AARs you need to depend on, you can examine the build.gradle files of the various sample apps. For example, samples/treasurehunt/build.gradle's dependency section has the following entries:
dependencies {
compile project(':libraries-audio')
compile project(':libraries-common')
compile project(':libraries-core')
}
This indicates that an application similar to the Treasure Hunt sample needs the audio, common, and core libraries.
Create new modules for each of these libraries. Using Android Studio's GUI, this can be done via File -> New -> New Module.... Select Import .JAR/.AAR Package. Locate one of the .AARs and import it.
Then add this new module as a dependency to your main app via File -> Project Structure -> Modules (on the left side's section list) -> YOUR APP's MODULE NAME -> Dependencies (on the right side's tab list) -> '+' -> Module Dependency.
I have an existing Node.js codebase, forked from GitHub. Now I want to import it to the Intellij IDEA 13 (ultimate version, which supports Node.js). When I simply try to import the project from the root folder of my existing code, IDEA doesn't add the 'lib' folder, where all the sources are. It should be simple, but I cannot figure it out. Any hints?
Well, I've figured out a workaround, but not sure if it's the best solution. One can just create a new project of type "Web", and point it to the directory containing the module's sources. Then IDEA understands the whole structure, and you can create run configurations with Node.js.
In order to get additional Node features, like Intellisense for standard Node APIs, you'll still want to configure the project to be a Node project:
Open the Preferences window
Click Languages & Frameworks → Node.js and NPM
In the section Coding Assistance you'll see if Node.js Core library is [not] enabled. If it is enabled, there's nothing more to do. If not click the Enable button
Leave For the whole project checked, and click Configure
The text should now change to Node.js Core library is enabled.
Another workaround:
If you have a version controlled Node app with no local changes, you could also create a new project of type "Node.js and NPM", point that to the directory. Then just use any standard settings.
After the project is created, you can just revert the files overwritten by IDEA (e.g. app.js and package.json), delete any new directories and files, and you will get the additional Node features in your project.
Intellij 15 Professional Edition:
Import a new project -> Select the base folder of the project -> choose import form existing source.
When Intellij is done it wont look correct so do the following:
1) Project Structure CMD + ;
2) Go to Modules
3) Add a new module and select Node/Npm (if you dont have it then add a new plugin)
4) Point the source of the project to the base folder and click apply.