Skip to content

Commit ea1da2b

Browse files
committed
[multi_module]: Project setup for multi-module
1 parent f5860b8 commit ea1da2b

File tree

186 files changed

+5109
-1442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+5109
-1442
lines changed

.editorconfig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
13+
[*.{java,kt,kts,scala,rs,xml,kt.spec,kts.spec}]
14+
indent_size = 4
15+
disabled_rules=no-wildcard-imports
16+
17+
[*.{kt,kts}]
18+
ktlint_code_style = ktlint_official
19+
ktlint_ignore_back_ticked_identifier = true
20+
21+
ktlint_standard = enabled
22+
23+
# Experimental rules run by default run on the ktlint code base itself. Experimental rules should not be released if
24+
# we are not pleased ourselves with the results on the ktlint code base.
25+
ktlint_experimental = enabled
26+
27+
[*.md]
28+
trim_trailing_whitespace = false

YTemplate.sh

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
#!/bin/bash
2-
#
3-
# Copyright (C) 2022 The Android Open Source Project
4-
#
5-
# Licensed under the Apache License, Version 2.0 (the "License");
6-
# you may not use this file except in compliance with the License.
7-
# You may obtain a copy of the License at
8-
#
9-
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# Unless required by applicable law or agreed to in writing, software
12-
# distributed under the License is distributed on an "AS IS" BASIS,
13-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
# See the License for the specific language governing permissions and
15-
# limitations under the License.
16-
#
172

183
# Verify bash version. macOS comes with bash 3 preinstalled.
194
if [[ ${BASH_VERSINFO[0]} -lt 4 ]]
@@ -25,34 +10,26 @@ fi
2510
# exit when any command fails
2611
set -e
2712

28-
if [[ $# -lt 2 ]]; then
29-
echo "Usage: bash customizer.sh my.new.package MyNewDataModel [ApplicationName]" >&2
13+
if [[ $# -lt 1 ]]; then
14+
echo "Usage: bash YTemplate.sh my.new.package [ApplicationName]" >&1
3015
exit 2
3116
fi
3217

3318
PACKAGE=$1
34-
DATAMODEL=$2
35-
APPNAME=$3
19+
APPNAME=$2
3620
SUBDIR=${PACKAGE//.//} # Replaces . with /
3721

38-
for n in $(find . -type d \( -path '*/app/src/androidTest' -or -path '*/app/src/main' -or -path '*/app/src/test' \) )
22+
# Creating package name directory under java folder
23+
for n in $(find . -type d \( -path '*/src/androidTest' -or -path '*/src/main' -or -path '*/src/test' \) )
3924
do
4025
echo "Creating $n/java/$SUBDIR"
4126
mkdir -p $n/java/$SUBDIR
4227
echo "Moving files to $n/java/$SUBDIR"
43-
mv $n/java/ytemplate/android/* $n/java/$SUBDIR
44-
echo "Removing old $n/java/ytemplate/android/"
28+
mv $n/java/ytemplate/android/* $n/java/$SUBDIR || echo "No such file or directory found"
29+
echo "Removing old $n/java/ytemplate/android/" || echo "File not found"
4530
rm -rf mv $n/java/ytemplate
4631
done
4732

48-
# Jacoco Dependancies
49-
echo "Creating buildSrc/src/main/java/$SUBDIR/build"
50-
mkdir -p buildSrc/src/main/java/$SUBDIR/build
51-
echo "Moving files to buildSrc/src/main/java/$SUBDIR/build"
52-
mv buildSrc/src/main/java/ytemplate/android/build/* buildSrc/src/main/java/$SUBDIR/build
53-
echo "Removing old buildSrc/src/main/java/ytemplate/android"
54-
rm -rf mv buildSrc/src/main/java/ytemplate
55-
5633
# Rename package and imports
5734
echo "Renaming packages to $PACKAGE"
5835
find ./ -type f -name "*.kt" -exec sed -i.bak "s/package ytemplate.android/package $PACKAGE/g" {} \;
@@ -64,28 +41,14 @@ find ./ -type f -name "*.kts" -exec sed -i.bak "s/ytemplate.android/$PACKAGE/g"
6441
# Manifest files
6542
find ./ -type f -name "*.xml" -exec sed -i.bak "s/ytemplate.android/$PACKAGE/g" {} \;
6643

67-
# Rename model
68-
echo "Renaming model to $DATAMODEL"
69-
find ./ -type f -name "*.kt" -exec sed -i.bak "s/MyModel/${DATAMODEL^}/g" {} \; # First upper case
70-
find ./ -type f -name "*.kt" -exec sed -i.bak "s/myModel/${DATAMODEL,}/g" {} \; # First lower case
71-
find ./ -type f -name "*.kt*" -exec sed -i.bak "s/mymodel/${DATAMODEL,,}/g" {} \; # All lowercase
44+
# Rename ytemplate.android
45+
echo "Renaming ytemplate.android to $PACKAGE"
46+
find ./ -type f -name "*.kt" -exec sed -i.bak "s/ytemplate.android/$PACKAGE/g" {} \;
7247

48+
#Cleaning Up .bak files
7349
echo "Cleaning up"
7450
find . -name "*.bak" -type f -delete
7551

76-
# Rename files
77-
echo "Renaming files to $DATAMODEL"
78-
find ./ -name "*MyModel*.kt" | sed "p;s/MyModel/${DATAMODEL^}/" | tr '\n' '\0' | xargs -0 -n 2 mv
79-
# module names
80-
if [[ -n $(find ./ -name "*-mymodel") ]]
81-
then
82-
echo "Renaming modules to $DATAMODEL"
83-
find ./ -name "*-mymodel" -type d | sed "p;s/mymodel/${DATAMODEL,,}/" | tr '\n' '\0' | xargs -0 -n 2 mv
84-
fi
85-
# directories
86-
echo "Renaming directories to $DATAMODEL"
87-
find ./ -name "mymodel" -type d | sed "p;s/mymodel/${DATAMODEL,,}/" | tr '\n' '\0' | xargs -0 -n 2 mv
88-
8952
# Renaming YTemplateTheme
9053
echo "Renaming YTemplateTheme to $APPNAME"
9154
find ./ -type f -name "*.kt" -exec sed -i.bak "s/YTemplateTheme/${APPNAME}Theme/g" {} \;
@@ -101,8 +64,5 @@ fi
10164

10265
# Remove additional files
10366
echo "Removing additional files"
104-
rm -rf .google/
105-
# rm -rf .github/
106-
# rm -rf CONTRIBUTING.md LICENSE README.md customizer.sh
107-
# rm -rf .git/
67+
rm -rf .git/
10868
echo "Done!"

app/build.gradle.kts

Lines changed: 20 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,33 @@
1+
@Suppress("DSL_SCOPE_VIOLATION") // scope violation issue: work around suggested from: https://github.com/gradle/gradle/issues/22797
12
plugins {
2-
id("com.android.application")
3-
id("org.jetbrains.kotlin.android")
4-
kotlin("kapt")
5-
alias(versionCatalogLibs.plugins.hilt.plugin)
6-
id("jacoco-reports")
7-
id("org.jetbrains.kotlin.plugin.serialization")
3+
id("ytemplate.android.application")
4+
id("ytemplate.android.application.jacoco")
5+
id("ytemplate.android.application.compose")
6+
id("ytemplate.android.hilt")
87
}
98

109
android {
11-
namespace ="ytemplate.android"
12-
compileSdk = versionCatalogLibs.versions.compile.sdk.get().toInt()
13-
10+
namespace = "ytemplate.android"
1411
defaultConfig {
15-
applicationId="ytemplate.android"
16-
minSdk = versionCatalogLibs.versions.min.sdk.get().toInt()
17-
targetSdk = versionCatalogLibs.versions.target.sdk.get().toInt()
12+
applicationId = "ytemplate.android"
1813
versionCode = 1
1914
versionName = "1.0"
20-
21-
testInstrumentationRunner = "ytemplate.android.HiltTestRunner"
22-
vectorDrawables {
23-
useSupportLibrary = true
24-
}
25-
}
26-
buildTypes {
27-
getByName("release"){
28-
isMinifyEnabled = false
29-
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
30-
}
31-
getByName("debug") {
32-
isMinifyEnabled = false
33-
enableUnitTestCoverage = true
34-
enableAndroidTestCoverage = true
35-
}
36-
}
37-
compileOptions {
38-
sourceCompatibility = JavaVersion.VERSION_11
39-
targetCompatibility = JavaVersion.VERSION_11
40-
}
41-
kotlinOptions {
42-
jvmTarget = versionCatalogLibs.versions.kotlin.jvm.target.get()
43-
}
44-
buildFeatures {
45-
compose = true
46-
}
47-
composeOptions {
48-
kotlinCompilerExtensionVersion = versionCatalogLibs.versions.compose.compiler.get()
49-
}
50-
packagingOptions {
51-
resources {
52-
excludes += "/META-INF/{AL2.0,LGPL2.1}"
53-
}
5415
}
5516
}
5617

5718
dependencies {
58-
//Compose
59-
implementation (versionCatalogLibs.bundles.compose)
60-
androidTestImplementation(versionCatalogLibs.compose.nav.test)
61-
//ktx
62-
implementation (versionCatalogLibs.bundles.ktx)
63-
//hilt
64-
implementation(versionCatalogLibs.bundles.hilt)
65-
kapt(versionCatalogLibs.hilt.compiler)
66-
androidTestImplementation(versionCatalogLibs.hilt.test)
67-
kaptAndroidTest(versionCatalogLibs.hilt.compiler)
68-
//coroutine
69-
implementation(versionCatalogLibs.coroutine)
70-
testImplementation(versionCatalogLibs.bundles.coroutine.test)
71-
//Room
72-
implementation(versionCatalogLibs.bundles.room)
73-
annotationProcessor(versionCatalogLibs.room.compiler)
74-
kapt(versionCatalogLibs.room.compiler)
75-
testImplementation(versionCatalogLibs.room.test)
76-
//Ktor
77-
implementation (versionCatalogLibs.bundles.ktor)
78-
testImplementation(versionCatalogLibs.ktor.client.mock)
79-
androidTestImplementation(versionCatalogLibs.ktor.client.mock)
80-
//Android Testing
81-
androidTestImplementation (versionCatalogLibs.bundles.android.test)
82-
testImplementation (versionCatalogLibs.junit)
83-
debugImplementation (versionCatalogLibs.bundles.android.debug.test)
19+
implementation(versionCatalogLibs.hilt.nav.compose)
20+
implementation(versionCatalogLibs.androidx.lifecycle.viewModelCompose)
8421

85-
androidTestImplementation(project(mapOf("path" to ":app")))
22+
implementation(project(mapOf("path" to ":core:ui")))
23+
implementation(project(mapOf("path" to ":feature:post")))
8624

87-
}
25+
androidTestImplementation(versionCatalogLibs.androidx.test.core)
26+
androidTestImplementation(versionCatalogLibs.androidx.test.core.ktx)
27+
androidTestImplementation(versionCatalogLibs.androidx.test.ext)
28+
androidTestImplementation(versionCatalogLibs.androidx.test.runner)
29+
androidTestImplementation(versionCatalogLibs.androidx.test.rules)
30+
31+
debugImplementation("androidx.compose.ui:ui-test-manifest:${versionCatalogLibs.versions.compose}")
32+
androidTestImplementation(project(mapOf("path" to ":core:test")))
33+
}

app/proguard-rules.pro

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
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.kts.
4-
#
5-
# For more details, see
6-
# http://developer.android.com/guide/developing/tools/proguard.html
1+
# Keep `Companion` object fields of serializable classes.
2+
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
3+
-if @kotlinx.serialization.Serializable class **
4+
-keepclassmembers class <1> {
5+
static <1>$Companion Companion;
6+
}
77

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-
#}
8+
# Keep `serializer()` on companion objects (both default and named) of serializable classes.
9+
-if @kotlinx.serialization.Serializable class ** {
10+
static **$* *;
11+
}
12+
-keepclassmembers class <2>$<3> {
13+
kotlinx.serialization.KSerializer serializer(...);
14+
}
1415

15-
# Uncomment this to preserve the line number information for
16-
# debugging stack traces.
17-
#-keepattributes SourceFile,LineNumberTable
16+
# Keep `INSTANCE.serializer()` of serializable objects.
17+
-if @kotlinx.serialization.Serializable class ** {
18+
public static ** INSTANCE;
19+
}
20+
-keepclassmembers class <1> {
21+
public static <1> INSTANCE;
22+
kotlinx.serialization.KSerializer serializer(...);
23+
}
1824

19-
# If you keep the line number information, uncomment this to
20-
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
25+
# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
26+
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ytemplate.android
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import org.junit.Assert.assertTrue
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
/**
10+
* Application test
11+
*
12+
* @constructor Create empty Application test
13+
*/
14+
@RunWith(AndroidJUnit4::class)
15+
class ApplicationTest {
16+
/**
17+
* Test app context
18+
*
19+
*/
20+
@Test
21+
fun testAppContext() {
22+
// Context of the app under test.
23+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
24+
assertTrue(appContext.packageName.contains("ytemplate.android"))
25+
}
26+
}
Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,56 @@
11
package ytemplate.android
22

3+
import androidx.compose.ui.test.junit4.createAndroidComposeRule
4+
import androidx.lifecycle.Lifecycle
5+
import androidx.test.core.app.launchActivity
6+
import androidx.test.ext.junit.rules.activityScenarioRule
7+
import androidx.test.ext.junit.runners.AndroidJUnit4
8+
import androidx.test.platform.app.InstrumentationRegistry
39
import dagger.hilt.android.testing.HiltAndroidRule
410
import dagger.hilt.android.testing.HiltAndroidTest
11+
import org.junit.Assert
512
import org.junit.Rule
13+
import org.junit.Test
14+
import org.junit.runner.RunWith
615

16+
/**
17+
* Main activity test
18+
*
19+
* @constructor Create empty Main activity test
20+
*/
721
@HiltAndroidTest
22+
@RunWith(AndroidJUnit4::class)
823
class MainActivityTest {
9-
@get:Rule
24+
@get:Rule(order = 0)
1025
var hiltRule = HiltAndroidRule(this)
11-
}
26+
27+
@get:Rule(order = 1)
28+
var activityScenarioRule = activityScenarioRule<MainActivity>()
29+
30+
@get:Rule(order = 2)
31+
val composeTestRule = createAndroidComposeRule<MainActivity>()
32+
33+
/**
34+
* Use app context
35+
*
36+
*/
37+
@Test
38+
fun useAppContext() {
39+
// Context of the app under test.
40+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
41+
Assert.assertTrue(appContext.packageName.contains("ytemplate.android"))
42+
}
43+
44+
/**
45+
* Check launched
46+
*
47+
*/
48+
@Test
49+
fun checkLaunched() {
50+
launchActivity<MainActivity>().use { scenario ->
51+
Assert.assertEquals(Lifecycle.State.RESUMED, scenario.state)
52+
scenario.moveToState(Lifecycle.State.CREATED)
53+
scenario.close()
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)