Step 1 : Create the Module
Creating a new module is pretty easy. Just do File->New Module. In the dialog choose the library option:
On the next screen, just name your module and give it a package name:
In the next dialog select "No Activity" and press finish. Once done it will construct the module, complete with the unit test directories for you.
If you haven't used a Library Module before, you will want to review the rules for library modules at the Android Development Blog. In general, they are incredibly convenient and useful, but be sure to follow the rules for them.
The commit is https://github.com/fsk-software/mynotes/commit/ee19fcfbc168a54ebf3d222fcaa931cb7b280029
Step 2 : Modify the Module
I want my library project to use the same unit test framework as my main project so I am updating its gradle file to include Mockito and Hamcrest as well (See my previous blog entry for how to do that).
The library project comes with some extra stuff that I don't want so I am going to remove the following resources:
- ic_launcher.png from the various drawable folders
- strings.xml from the values folder.
I also modified the CommonLibrary manifest.xml to remove the label and icon attributes from the application element.
The commit is at https://github.com/fsk-software/mynotes/commit/4002903759d580b380b588cf02b1fc146675c211
The last step is to add a dependency between the MyNotes Module and the CommonLibrary module. The steps are:
This will automatically update the MyNotes modules build.gradle filewith the module dependency.
The commit is at https://github.com/fsk-software/mynotes/commit/a92ab9e9bb77d4c340f71e1c5e17a327f2c409eb
The commit is at https://github.com/fsk-software/mynotes/commit/4002903759d580b380b588cf02b1fc146675c211
Step 3: Add the Library Module Dependency
The last step is to add a dependency between the MyNotes Module and the CommonLibrary module. The steps are:
- File->Project Structure...
- Select the module that will receive the dependency (MyNotes)
- Open the Dependency Tab
- Click the green "+" sign
- Select "Module Dependency" and select the module (CommonLibrary)
It will look like this afterward:
This will automatically update the MyNotes modules build.gradle filewith the module dependency.
The commit is at https://github.com/fsk-software/mynotes/commit/a92ab9e9bb77d4c340f71e1c5e17a327f2c409eb
No comments :
Post a Comment