├── .gitignore ├── Readme.md ├── build.gradle.kts ├── buildSrc ├── .gitignore ├── build.gradle.kts └── src │ └── main │ ├── kotlin │ ├── AndroidModulePlugin.kt │ └── Versions.kt │ └── resources │ └── META-INF │ └── gradle-plugins │ └── dev.nikhi1.plugin.android.properties ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sampleapp ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── dev │ │ └── nikhi1 │ │ └── sampleapp │ │ ├── FirstFragmentTest.kt │ │ ├── MainActivityTest.kt │ │ └── SecondFragmentTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── dev │ │ │ └── nikhi1 │ │ │ └── sampleapp │ │ │ ├── FirstFragment.kt │ │ │ ├── MainActivity.kt │ │ │ ├── MainPresenter.kt │ │ │ └── SecondFragment.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── content_main.xml │ │ ├── fragment_first.xml │ │ └── fragment_second.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── navigation │ │ └── nav_graph.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── dev │ └── nikhi1 │ └── sampleapp │ └── MainPresenterTest.kt ├── samplelib ├── .gitignore ├── build.gradle.kts ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── dev │ │ └── nikhi1 │ │ └── samplelib │ │ └── LibFragmentTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── dev │ │ │ └── nikhi1 │ │ │ └── samplelib │ │ │ ├── LibFragment.kt │ │ │ └── MainPresenter.kt │ └── res │ │ └── layout │ │ └── fragment_lib.xml │ └── test │ └── java │ └── dev │ └── nikhi1 │ └── samplelib │ └── MainPresenterTest.kt ├── settings.gradle └── settings.gradle.kts /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .gradle 3 | local.properties 4 | *.iml 5 | build -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Multiple Module Dependency setup :package: 2 | 3 | The purpose of this repo to demonstrate the use of a custom **Gradle** plugin to centralize the dependency management in multi-module app setup. 4 | 5 | When you start breaking down your Android app into different modules you need to do the following steps for each one: 6 | 7 | * Define `compileSdkVersion`, `buildToolsVersion`, `minSdkVersion`, `targetSdkVersion` etc. 8 | * Copy the `dependencies` block even though you might be repeating yourself. This is specially true for common and test dependencies. 9 | * ~~Make sure each feature module depends on the `app` module or whatever base module you have.~~ Turn outs this is a bit of complex scenario to infer for simple use case. This has been removed from the `Plugin` implementation. 10 | 11 | I recently started working on a sample [project](https://github.com/nikhil-thakkar/eventbrite-clone) which demonstrate the use of `dynamic-feature` modules and found myself in a similar situation. 12 | This lead me to do some research on the topic and :money_mouth_face: found people already have a solution. 13 | There are a couple of blog posts that I found interesting (outlined below) and inspired me to dig further. 14 | 15 | # About :books: 16 | The repo contains two example android modules namely `sampleapp` and `samplelib`. These modules demonstrate the usage of the `Plugin` in their respective `build.gradle` files [here](https://github.com/nikhil-thakkar/multi-module-dependency-setup/blob/927ab581e25f7e30d524bd72a78104612dfe18c9/sampleapp/build.gradle.kts#L1-L4) and [here](https://github.com/nikhil-thakkar/multi-module-dependency-setup/blob/927ab581e25f7e30d524bd72a78104612dfe18c9/samplelib/build.gradle.kts#L1-L4). 17 | 18 | The, `AndroidModulePlugin`, plugin will configure the following for each of the modules: 19 | * `compileSdkVersion`, `buildToolsVersion`, `minSdkVersion`, `targetSdkVersion`, `compileOptions`, `testInstrumentationRunner` 20 | * Add common test dependencies like junit, mockk 21 | * Configure SonarQube and its properties 22 | * Configure Jacoco 23 | 24 | Note: You can still override properties which are set by this plugin, by just configuring them again using the android {} or other blocks :sunglasses:. 25 | 26 | 27 | # Use it in your project :cookie: 28 | The actual setup is pretty simple. The code is also pretty self-explanatory. All you have to do is copy the `buildSrc` folder to root of your app project. 29 | And click on **Gradle sync**![alt gradle sync icon](https://developer.android.com/studio/images/buttons/toolbar-sync-gradle.png) so that gradle can pick up the source and build the plugin and add it to build phase. 30 | 31 | After the project builds successfully the only step is to apply the plugin in your individual app/library/feature modules `build.gradle`. 32 | ``` 33 | apply plugin: 'dev.nikhi1.plugin.android' 34 | ``` 35 | Make sure to apply this plugin after either `application`, `library` and/or `dynamic-feature` plugin definition in their respective gradle files. 36 | 37 | # Why Jacoco? 38 | Jacoco is a tool to measure code coverage and currently the most widely used. 39 | 40 | > Code coverage in simple terms means how much of the production code that you wrote is being executed at runtime when a particular test suite runs. 41 | 42 | To measure this you write Unit/UI/Integration tests. And this is what Jacoco does under the hood, it hooks on to these tests while they are executing. In the process, it can see what code is executed as part of the tests and calculates its coverage. 43 | These coverages are helpful, for example, if you have miss handling an `else` branch in one of your test cases. 44 | 45 | Though on Android, the test execution data (.ec file) for UI test cases is not taken into account by Jacoco and hence we have to tweak the gradle task and make sure if also reads those files to give a complete code coverage across Unit and UI/Integration test cases. 46 | 47 | The task outputs xml reports per module which are uploaded to SonarQube for a nice looking dashboard :tada:. 48 | 49 | This example [repo](https://sonarcloud.io/dashboard?id=nikhil-thakkar_multi-module-dependency-setup) has 100% code coverage. Of course this doesn't mean the code is rock solid and is following all the SOLID principles of software engineering. It's more an indicator that code bases are lacking test cases and we should do something about it :smile:. 50 | 51 | If you are not ready with test cases yet then remove the method `configureJacoco` from the `AndroidModulePlugin` class. Every method is self-contained and could be added/removed on need basis. 52 | 53 | # Why SonarQube? 54 | SonarQube is the leading tool for continuously inspecting the Code Quality and Security of your codebases and guiding development teams during Code Reviews. 55 | 56 | These analyses are driven by automated Static Code Analysis rules. You can add your own rules or use [detekt](https://detekt.github.io/detekt/) rules for analysis as well. 57 | 58 | The `Plugin` configures the different properties required for SonarQube plugin to work properly. For example, the path of the Jacoco xml reports etc. Check [here](https://github.com/nikhil-thakkar/multi-module-dependency-setup/blob/927ab581e25f7e30d524bd72a78104612dfe18c9/buildSrc/src/main/kotlin/AndroidModulePlugin.kt#L120-L145). 59 | 60 | This repo uses [`sonarcloud.io`](https://sonarcloud.io) which is free for open-source projects and is a cloud hosted solution. But in most cases, there would be a private hosted SonarQube server running in the infra. Just configure the `Plugin` with correct values. 61 | 62 | Refer [this](https://github.com/nikhil-thakkar/eventbrite-clone/blob/master/.github/workflows/pull_request.yml) github action if you feel lost. 63 | 64 | # A word about CI :gear: 65 | Irrespective of any CI tool, in theory, we need to run some gradle tasks. These gradle tasks are for most cases either run Unit and/or UI tests. Post that some static code analysis which could be either `ktlint` or `detekt` or something on similar lines. 66 | 67 | Here is the minimum gradle tasks that needs to be run 68 | ``` 69 | ./gradlew clean connectedDebugAndroidTest jacocoTestDebugUnitTestReport sonarqube 70 | ``` 71 | Ofcourse you have to make sure that an emulator/device is up and running in order to run the UI test cases. 72 | 73 | If everything is set up properly, you should be able to see the analysis report on the configured SonarQube instance. 74 | 75 | # Minimum requirements 76 | * Gradle version: v6.x 77 | * Android Studio: v4.0 78 | 79 | # Known limitations 80 | * Currently there is no way to combine the jacoco reports across different modules. This [plugin](https://github.com/vanniktech/gradle-android-junit-jacoco-plugin) might help. 81 | * Cannot skip SonarQube analysis for a particular module. 82 | * Not tested with `Roboelectric` framework. 83 | 84 | # References 85 | * [Managing dependencies in multi-module setup](https://medium.com/wantedly-engineering/managing-android-multi-module-project-with-gradle-plugin-and-kotlin-4fcc126e7e49) 86 | * [buildSrc Trick](https://quickbirdstudios.com/blog/gradle-kotlin-buildsrc-plugin-android/) 87 | * [Modularization Tips](https://jeroenmols.com/blog/2019/06/12/modularizationtips/) 88 | * [Code coverage in practice](https://www.rallyhealth.com/coding/code-coverage-for-android-testing) 89 | * [Android Gradle Plugin Reference](https://google.github.io/android-gradle-dsl/current/index.html) - Not sure if this is being maintained 90 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | buildscript { 2 | 3 | repositories { 4 | google() 5 | jcenter() 6 | } 7 | } 8 | 9 | allprojects { 10 | repositories { 11 | google() 12 | jcenter() 13 | } 14 | } 15 | 16 | tasks.create("clean") { 17 | delete(rootProject.buildDir) 18 | } -------------------------------------------------------------------------------- /buildSrc/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .gradle/ 3 | *.iml 4 | -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | jcenter() 8 | google() 9 | maven { 10 | url = uri("https://plugins.gradle.org/m2/") 11 | } 12 | } 13 | 14 | dependencies { 15 | /* Depend on the kotlin plugin, since we want to access it in our plugin */ 16 | implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.71") 17 | 18 | /* Depend on the android gradle plugin, since we want to access it in our plugin */ 19 | implementation("com.android.tools.build:gradle:4.0.0") 20 | 21 | implementation("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.8.0.1969") 22 | 23 | implementation("org.jacoco:org.jacoco.core:0.8.5") 24 | 25 | implementation("com.hiya:jacoco-android:0.2") 26 | 27 | /* Depend on the default Gradle API's since we want to build a custom plugin */ 28 | implementation(gradleApi()) 29 | implementation(localGroovy()) 30 | } 31 | 32 | // Added to overcome https://github.com/mockk/mockk/issues/281 for now. 33 | // Seems to be fixed in mockk version 1.10.0 34 | // TODO: Remove this after testing 35 | allprojects { 36 | configurations.all { 37 | resolutionStrategy { 38 | force("org.objenesis:objenesis:2.6") 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/AndroidModulePlugin.kt: -------------------------------------------------------------------------------- 1 | import com.android.build.gradle.BaseExtension 2 | import com.hiya.plugins.JacocoAndroidUnitTestReportExtension 3 | import org.gradle.api.JavaVersion 4 | import org.gradle.api.Plugin 5 | import org.gradle.api.Project 6 | import org.gradle.api.tasks.testing.Test 7 | import org.gradle.kotlin.dsl.configure 8 | import org.gradle.kotlin.dsl.dependencies 9 | import org.gradle.kotlin.dsl.getByType 10 | import org.gradle.kotlin.dsl.withType 11 | import org.gradle.testing.jacoco.plugins.JacocoPluginExtension 12 | import org.gradle.testing.jacoco.plugins.JacocoTaskExtension 13 | import org.gradle.testing.jacoco.tasks.JacocoReport 14 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 15 | import org.sonarqube.gradle.SonarQubeExtension 16 | 17 | /*** 18 | * This plugin is instantiated every time when you apply this plugin to build.gradle in library/feature module 19 | * apply plugin: 'dev.nikhi1.plugin.android' 20 | * [Note] Don't apply this plugin to pure Java/Kotlin modules. Its a no-op. 21 | */ 22 | class AndroidModulePlugin : Plugin { 23 | 24 | override fun apply(project: Project) { 25 | if (project.hasProperty("android")) { 26 | with(project) { 27 | plugins.apply("kotlin-android") 28 | plugins.apply("kotlin-android-extensions") 29 | plugins.apply("kotlin-kapt") 30 | 31 | configureSonarqube() 32 | configureJacoco() 33 | configureAndroidBlock() 34 | configureCommonDependencies() 35 | configureTestDependencies() 36 | } 37 | } 38 | } 39 | } 40 | 41 | internal fun Project.configureAndroidBlock() { 42 | extensions.getByType().run { 43 | 44 | buildToolsVersion(Versions.buildTools) 45 | compileSdkVersion(Versions.compileSDK) 46 | 47 | defaultConfig { 48 | minSdkVersion(Versions.minSDK) 49 | targetSdkVersion(Versions.targetSDK) 50 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 51 | } 52 | 53 | compileOptions { 54 | sourceCompatibility = JavaVersion.VERSION_1_8 55 | targetCompatibility = JavaVersion.VERSION_1_8 56 | } 57 | 58 | 59 | tasks.withType(KotlinCompile::class.java).all { 60 | kotlinOptions { 61 | jvmTarget = JavaVersion.VERSION_1_8.toString() 62 | } 63 | } 64 | 65 | testOptions { 66 | unitTests.apply { 67 | isReturnDefaultValues = true 68 | } 69 | animationsDisabled = true 70 | } 71 | 72 | buildTypes { 73 | getByName("debug") { 74 | isTestCoverageEnabled = true 75 | } 76 | } 77 | } 78 | } 79 | 80 | internal fun Project.configureCommonDependencies() { 81 | 82 | extensions.getByType().run { 83 | dependencies { 84 | add("implementation", Libs.coreKts) 85 | add("implementation", Libs.appcompat) 86 | add("implementation", Libs.constraintLayout) 87 | add("implementation", Libs.navigator) 88 | add("implementation", Libs.material) 89 | add("implementation", Libs.fragment) 90 | add("implementation", Libs.fragmentKtx) 91 | } 92 | } 93 | } 94 | 95 | internal fun Project.configureTestDependencies() { 96 | extensions.getByType().run { 97 | dependencies { 98 | add("testImplementation", Libs.junit) 99 | add("testImplementation", Libs.mockk) 100 | add("testImplementation", Libs.coreTesting) 101 | add("testImplementation", Libs.kotlinJDK) 102 | add("debugImplementation", Libs.fragmentTesting) 103 | 104 | add("androidTestImplementation", Libs.testRunner) 105 | add("androidTestImplementation", Libs.testRules) 106 | add("androidTestImplementation", Libs.testKtx) 107 | add("androidTestImplementation", Libs.espressoCore) 108 | add("androidTestImplementation", Libs.navTesting) 109 | add("androidTestImplementation", Libs.truth) 110 | } 111 | } 112 | } 113 | 114 | /** 115 | * [SonarQube] is the leading tool for continuously inspecting the Code Quality and Security of your codebases and 116 | * guiding development teams during Code Reviews. 117 | * These analyses are driven by automated Static Code Analysis rules. You can add your own rules or use [detekt] rules for analysis as well. 118 | * This method will configure [SonarQube] at the root of the project. 119 | * Update the values for [sonar.projectKey], [sonar.organization], [sonar.host.url], [sonar.login] according to your project setup. 120 | */ 121 | internal fun Project.configureSonarqube() { 122 | val plugin = rootProject.plugins.findPlugin("org.sonarqube") 123 | if (plugin == null) { 124 | rootProject.plugins.apply("org.sonarqube") 125 | rootProject.extensions.getByType().run { 126 | properties { 127 | property("sonar.projectKey", "nikhil-thakkar_multi-module-dependency-setup") 128 | property("sonar.organization", "nikhil-thakkar") 129 | property("sonar.sources", "src/main/java") 130 | property("sonar.sources.coveragePlugin", "jacoco") 131 | property("sonar.host.url", "https://sonarcloud.io/") 132 | property("sonar.exclusions", "**/*.js,**/test/**, buildSrc/*") 133 | property("sonar.login", "") 134 | } 135 | } 136 | } 137 | 138 | extensions.getByType().run { 139 | properties { 140 | property( 141 | "sonar.coverage.jacoco.xmlReportPaths", 142 | "${buildDir}/jacoco/jacoco.xml" 143 | ) 144 | } 145 | } 146 | } 147 | 148 | /** 149 | * Jacoco is a tool to measure code coverage and currently the most widely used. 150 | * This method would apply [com.hiya.jacoco-android] plugin to each module in the project and their respective build variants. 151 | * The generated xml reports are available under [build/jacoco/jacoco.xml] for each module. 152 | * These xml reports are sent to [SonarQube] to be displayed under Coverage section on Dashboard. 153 | * @see Example 154 | */ 155 | internal fun Project.configureJacoco() { 156 | plugins.apply("com.hiya.jacoco-android") 157 | 158 | extensions.getByType().run { 159 | toolVersion = "0.8.5" 160 | } 161 | 162 | tasks.withType().run { 163 | all { 164 | configure() { 165 | isIncludeNoLocationClasses = true 166 | } 167 | } 168 | } 169 | 170 | //Exclude androidx databinding files 171 | extensions.getByType().run { 172 | excludes = excludes + listOf( 173 | "androidx/databinding/**/*.class", 174 | "**/androidx/databinding/*Binding.class", 175 | "**/**Bind**/**" 176 | ) 177 | } 178 | 179 | /* 180 | * The [com.hiya.jacoco-android] plugin doesn't add the code coverage execution data for Instrumentation tests which are generated by running 181 | * [connectedDebugAndroidTest] or [connectedAndroidTest] 182 | * Issue open https://github.com/autonomousapps/jacoco-android-gradle-plugin/issues/1 183 | * TODO: Remove this block once the issue is fixed 184 | */ 185 | afterEvaluate { 186 | tasks.withType().run { 187 | all { 188 | val tree = fileTree(buildDir) 189 | tree.include("**/*.ec") 190 | executionData(tree) 191 | } 192 | } 193 | } 194 | } -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Versions.kt: -------------------------------------------------------------------------------- 1 | 2 | 3 | internal object Versions { 4 | const val kotlin = "1.3.71" 5 | const val androidx = "1.1.0" 6 | const val coreKtx = androidx 7 | const val compileSDK = 29 8 | const val minSDK = 21 9 | const val targetSDK = compileSDK 10 | const val buildTools = "29.0.2" 11 | const val androidxArch = "2.1.0" 12 | const val navigation = "2.3.0-rc01" 13 | const val constrainLayout = "1.1.3" 14 | const val material = "1.1.0-rc02" 15 | const val fragment = "1.2.5" 16 | 17 | const val junit = "4.12" 18 | const val mockk = "1.9" 19 | const val coreTesting = androidxArch 20 | const val testRunner = "1.2.0" 21 | const val testKtx = "1.3.0-beta02" 22 | const val espressoCore = "3.1.0" 23 | const val testCore = "1.2.0" 24 | const val truth = "1.0.1" 25 | } 26 | 27 | object Libs { 28 | val kotlinJDK = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}" 29 | val appcompat = "androidx.appcompat:appcompat:${Versions.androidx}" 30 | val coreKts = "androidx.core:core-ktx:${Versions.coreKtx}" 31 | val constraintLayout = "androidx.constraintlayout:constraintlayout:${Versions.constrainLayout}" 32 | val navigator = "androidx.navigation:navigation-fragment-ktx:${Versions.navigation}" 33 | val material = "com.google.android.material:material:${Versions.material}" 34 | val fragment = "androidx.fragment:fragment:${Versions.fragment}" 35 | val fragmentKtx = "androidx.fragment:fragment-ktx:${Versions.fragment}" 36 | 37 | val junit = "junit:junit:${Versions.junit}" 38 | val coreTesting = "androidx.arch.core:core-testing:${Versions.coreTesting}" 39 | val mockk = "io.mockk:mockk:${Versions.mockk}" 40 | val testRunner = "androidx.test:runner:${Versions.testRunner}" 41 | val testRules = "androidx.test:rules:${Versions.testRunner}" 42 | val testKtx = "androidx.test:core-ktx:${Versions.testKtx}" 43 | val espressoCore = "androidx.test.espresso:espresso-core:${Versions.espressoCore}" 44 | val fragmentTesting = "androidx.fragment:fragment-testing:${Versions.fragment}" 45 | val navTesting = "androidx.navigation:navigation-testing:${Versions.navigation}" 46 | val truth = "com.google.truth:truth:${Versions.truth}" 47 | } -------------------------------------------------------------------------------- /buildSrc/src/main/resources/META-INF/gradle-plugins/dev.nikhi1.plugin.android.properties: -------------------------------------------------------------------------------- 1 | implementation-class=AndroidModulePlugin -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | 23 | org.gradle.parallel = true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nikhil-thakkar/multi-module-dependency-setup/6d18f589cfb693d4c07574a39bf54e37355e9937/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jun 09 19:34:21 CEST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /sampleapp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sampleapp/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("dev.nikhi1.plugin.android") 4 | } 5 | 6 | android { 7 | 8 | defaultConfig { 9 | applicationId = "dev.nikhi1.sampleapp" 10 | versionCode = 1 11 | versionName = "1.0" 12 | resConfigs("en") 13 | } 14 | } 15 | 16 | dependencies { 17 | implementation(project(":samplelib")) 18 | } -------------------------------------------------------------------------------- /sampleapp/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /sampleapp/src/androidTest/java/dev/nikhi1/sampleapp/FirstFragmentTest.kt: -------------------------------------------------------------------------------- 1 | package dev.nikhi1.sampleapp 2 | 3 | import androidx.fragment.app.testing.FragmentScenario 4 | import androidx.fragment.app.testing.FragmentScenario.launchInContainer 5 | import androidx.navigation.Navigation 6 | import androidx.navigation.testing.TestNavHostController 7 | import androidx.test.core.app.ApplicationProvider 8 | import androidx.test.espresso.Espresso.onView 9 | import androidx.test.espresso.action.ViewActions 10 | import androidx.test.espresso.matcher.ViewMatchers.withId 11 | import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner 12 | import com.google.common.truth.Truth.assertThat 13 | import org.junit.Before 14 | import org.junit.Test 15 | import org.junit.runner.RunWith 16 | 17 | /** 18 | * Instrumented test, which will execute on an Android device. 19 | * 20 | * See [testing documentation](http://d.android.com/tools/testing). 21 | */ 22 | @RunWith(AndroidJUnit4ClassRunner::class) 23 | class FirstFragmentTest { 24 | 25 | private lateinit var fragmentScenario: FragmentScenario 26 | private lateinit var navController: TestNavHostController 27 | 28 | @Before 29 | fun setUp() { 30 | fragmentScenario = launchInContainer(FirstFragment::class.java) 31 | navController = TestNavHostController( 32 | ApplicationProvider.getApplicationContext()) 33 | navController.setGraph(R.navigation.nav_graph) 34 | } 35 | 36 | @Test 37 | fun find_and_click_button() { 38 | fragmentScenario.onFragment { fragment -> 39 | Navigation.setViewNavController(fragment.requireView(), navController) 40 | } 41 | 42 | onView(withId(R.id.button_first)).perform(ViewActions.click()) 43 | assertThat(navController.currentDestination?.id).isEqualTo(R.id.SecondFragment) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sampleapp/src/androidTest/java/dev/nikhi1/sampleapp/MainActivityTest.kt: -------------------------------------------------------------------------------- 1 | package dev.nikhi1.sampleapp 2 | 3 | import androidx.test.core.app.ActivityScenario 4 | import androidx.test.core.app.ApplicationProvider 5 | import androidx.test.espresso.Espresso.onData 6 | import androidx.test.espresso.Espresso.onView 7 | import androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu 8 | import androidx.test.espresso.action.ViewActions 9 | import androidx.test.espresso.action.ViewActions.click 10 | import androidx.test.espresso.matcher.ViewMatchers.withId 11 | import androidx.test.espresso.matcher.ViewMatchers.withText 12 | import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner 13 | import org.junit.After 14 | import org.junit.Before 15 | import org.junit.Test 16 | import org.junit.runner.RunWith 17 | 18 | /** 19 | * Instrumented test, which will execute on an Android device. 20 | * 21 | * See [testing documentation](http://d.android.com/tools/testing). 22 | */ 23 | 24 | @RunWith(AndroidJUnit4ClassRunner::class) 25 | class MainActivityTest { 26 | 27 | lateinit var activityScenario: ActivityScenario 28 | 29 | @Before 30 | fun setUp() { 31 | activityScenario = ActivityScenario.launch(MainActivity::class.java) 32 | } 33 | 34 | @Test 35 | fun find_and_click_FAB() { 36 | onView(withId(R.id.fab)).perform(click()) 37 | } 38 | 39 | @Test 40 | fun open_menu_click_settings() { 41 | openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext()) 42 | onView(withText(R.string.action_settings)).perform(click()) 43 | } 44 | 45 | @Test 46 | fun open_menu_click_others() { 47 | openActionBarOverflowOrOptionsMenu(ApplicationProvider.getApplicationContext()) 48 | onView(withText(R.string.action_others)).perform(click()) 49 | } 50 | 51 | @After 52 | fun tearDown() { 53 | activityScenario.close() 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sampleapp/src/androidTest/java/dev/nikhi1/sampleapp/SecondFragmentTest.kt: -------------------------------------------------------------------------------- 1 | package dev.nikhi1.sampleapp 2 | 3 | import androidx.fragment.app.testing.FragmentScenario 4 | import androidx.navigation.Navigation 5 | import androidx.navigation.testing.TestNavHostController 6 | import androidx.test.core.app.ApplicationProvider 7 | import androidx.test.espresso.Espresso.onView 8 | import androidx.test.espresso.action.ViewActions 9 | import androidx.test.espresso.matcher.ViewMatchers 10 | import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner 11 | import com.google.common.truth.Truth 12 | import org.junit.Before 13 | import org.junit.Test 14 | import org.junit.runner.RunWith 15 | 16 | @RunWith(AndroidJUnit4ClassRunner::class) 17 | class SecondFragmentTest { 18 | 19 | private lateinit var fragmentScenario: FragmentScenario 20 | private lateinit var navController: TestNavHostController 21 | 22 | @Before 23 | fun setUp() { 24 | fragmentScenario = FragmentScenario.launchInContainer(SecondFragment::class.java) 25 | navController = TestNavHostController( 26 | ApplicationProvider.getApplicationContext()) 27 | navController.setGraph(R.navigation.nav_graph) 28 | navController.setCurrentDestination(R.id.SecondFragment) 29 | } 30 | 31 | @Test 32 | fun find_and_click_button() { 33 | fragmentScenario.onFragment { fragment -> 34 | Navigation.setViewNavController(fragment.requireView(), navController) 35 | } 36 | 37 | onView(ViewMatchers.withId(R.id.button_second)).perform(ViewActions.click()) 38 | Truth.assertThat(navController.currentDestination?.id).isEqualTo(R.id.FirstFragment) 39 | } 40 | } -------------------------------------------------------------------------------- /sampleapp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /sampleapp/src/main/java/dev/nikhi1/sampleapp/FirstFragment.kt: -------------------------------------------------------------------------------- 1 | package dev.nikhi1.sampleapp 2 | 3 | import android.os.Bundle 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import android.widget.Button 8 | import androidx.fragment.app.Fragment 9 | import androidx.navigation.fragment.findNavController 10 | 11 | /** 12 | * A simple [Fragment] subclass as the default destination in the navigation. 13 | */ 14 | class FirstFragment : Fragment() { 15 | 16 | override fun onCreateView( 17 | inflater: LayoutInflater, container: ViewGroup?, 18 | savedInstanceState: Bundle? 19 | ): View? { 20 | // Inflate the layout for this fragment 21 | return inflater.inflate(R.layout.fragment_first, container, false) 22 | } 23 | 24 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 25 | super.onViewCreated(view, savedInstanceState) 26 | 27 | view.findViewById