-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I132c211a6ac55d62b36b14ed622703a50e0d0605
- Loading branch information
1 parent
800d794
commit 51aa000
Showing
54 changed files
with
2,134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
/.idea | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Android architecture starter template | ||
================== | ||
|
||
This template is compatible with the latest **stable** version of Android Studio. | ||
|
||
## Features | ||
|
||
* Room Database | ||
* Hilt | ||
* ViewModel, read+write | ||
* UI in Compose, list + write (Material3) | ||
* Navigation | ||
* Repository and data source | ||
* Kotlin Coroutines and Flow | ||
* Unit tests | ||
* UI tests using fake data with Hilt | ||
|
||
## Usage | ||
|
||
1. Clone the repository | ||
2. Run the customizer script: | ||
|
||
``` | ||
./customizer.sh your.package.name DataItemType [MyApplication] | ||
``` | ||
|
||
Where `your.package.name` is your app ID (should be lowercase) and `DataItemType` is used for the | ||
name of the screen, exposed state and data base entity (should be PascalCase). | ||
|
||
# License | ||
|
||
Now in Android is distributed under the terms of the Apache License (Version 2.0). See the | ||
[license](LICENSE) for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright (C) 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
@Suppress("DSL_SCOPE_VIOLATION") // Remove when fixed https://youtrack.jetbrains.com/issue/KTIJ-19369 | ||
plugins { | ||
alias(libs.plugins.android.application) | ||
alias(libs.plugins.kotlin.android) | ||
alias(libs.plugins.kotlin.kapt) | ||
alias(libs.plugins.hilt.gradle) | ||
alias(libs.plugins.ksp) | ||
} | ||
|
||
android { | ||
namespace = "android.template" | ||
compileSdk = 33 | ||
|
||
defaultConfig { | ||
applicationId = "android.template" | ||
minSdk = 21 | ||
targetSdk = 33 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
testInstrumentationRunner = "android.template.HiltTestRunner" | ||
vectorDrawables { | ||
useSupportLibrary = true | ||
} | ||
|
||
// Enable room auto-migrations | ||
ksp { | ||
arg("room.schemaLocation", "$projectDir/schemas") | ||
} | ||
} | ||
|
||
buildTypes { | ||
getByName("release") { | ||
isMinifyEnabled = false | ||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
|
||
buildFeatures { | ||
compose = true | ||
aidl = false | ||
buildConfig = false | ||
renderScript = false | ||
shaders = false | ||
} | ||
|
||
composeOptions { | ||
kotlinCompilerExtensionVersion = libs.versions.androidxComposeCompiler.get() | ||
} | ||
|
||
packagingOptions { | ||
resources { | ||
excludes += "/META-INF/{AL2.0,LGPL2.1}" | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
// Core Android dependencies | ||
implementation(libs.androidx.core.ktx) | ||
implementation(libs.androidx.lifecycle.runtime.ktx) | ||
implementation(libs.androidx.activity.compose) | ||
|
||
// Hilt Dependency Injection | ||
implementation(libs.hilt.android) | ||
kapt(libs.hilt.compiler) | ||
// Hilt and instrumented tests. | ||
androidTestImplementation(libs.hilt.android.testing) | ||
kaptAndroidTest(libs.hilt.android.compiler) | ||
// Hilt and Robolectric tests. | ||
testImplementation(libs.hilt.android.testing) | ||
kaptTest(libs.hilt.android.compiler) | ||
|
||
// Arch Components | ||
implementation(libs.androidx.lifecycle.viewmodel.compose) | ||
implementation(libs.androidx.navigation.compose) | ||
implementation(libs.androidx.hilt.navigation.compose) | ||
implementation(libs.androidx.room.runtime) | ||
implementation(libs.androidx.room.ktx) | ||
ksp(libs.androidx.room.compiler) | ||
|
||
// Compose | ||
implementation(libs.androidx.compose.ui) | ||
implementation(libs.androidx.compose.ui.tooling.preview) | ||
implementation(libs.androidx.compose.material3) | ||
// Tooling | ||
debugImplementation(libs.androidx.compose.ui.tooling) | ||
// Instrumented tests | ||
androidTestImplementation(libs.androidx.compose.ui.test.junit4) | ||
debugImplementation(libs.androidx.compose.ui.test.manifest) | ||
|
||
// Local tests: jUnit, coroutines, Android runner | ||
testImplementation(libs.junit) | ||
testImplementation(libs.kotlinx.coroutines.test) | ||
|
||
// Instrumented tests: jUnit rules and runners | ||
|
||
androidTestImplementation(libs.androidx.test.core) | ||
androidTestImplementation(libs.androidx.test.ext.junit) | ||
androidTestImplementation(libs.androidx.test.runner) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
40 changes: 40 additions & 0 deletions
40
app/schemas/android.template.data.local.database.AppDatabase/1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "8bebd6aab64557ab1de14693ec7b4103", | ||
"entities": [ | ||
{ | ||
"tableName": "MyModel", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`name` TEXT NOT NULL, `uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "name", | ||
"columnName": "name", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "uid", | ||
"columnName": "uid", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"uid" | ||
], | ||
"autoGenerate": true | ||
}, | ||
"indices": [], | ||
"foreignKeys": [] | ||
} | ||
], | ||
"views": [], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '8bebd6aab64557ab1de14693ec7b4103')" | ||
] | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/androidTest/java/android/template/HiltTestRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package android.template | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import androidx.test.runner.AndroidJUnitRunner | ||
import dagger.hilt.android.testing.HiltTestApplication | ||
|
||
/** | ||
* A custom runner to set up the instrumented application class for tests. | ||
*/ | ||
class HiltTestRunner : AndroidJUnitRunner() { | ||
|
||
override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application { | ||
return super.newApplication(cl, HiltTestApplication::class.java.name, context) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/androidTest/java/android/template/testdi/TestDatabaseModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package android.template.testdi | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.components.SingletonComponent | ||
import dagger.hilt.testing.TestInstallIn | ||
import android.template.data.MyModelRepository | ||
import android.template.data.di.DataModule | ||
import android.template.data.di.FakeMyModelRepository | ||
|
||
@Module | ||
@TestInstallIn( | ||
components = [SingletonComponent::class], | ||
replaces = [DataModule::class] | ||
) | ||
interface FakeDataModule { | ||
|
||
@Binds | ||
abstract fun bindRepository( | ||
fakeRepository: FakeMyModelRepository | ||
): MyModelRepository | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/androidTest/java/android/template/ui/NavigationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2022 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package android.template.ui | ||
|
||
import androidx.compose.ui.test.junit4.createAndroidComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import dagger.hilt.android.testing.HiltAndroidRule | ||
import dagger.hilt.android.testing.HiltAndroidTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import android.template.data.di.fakeMyModels | ||
|
||
@HiltAndroidTest | ||
class NavigationTest { | ||
|
||
@get:Rule(order = 0) | ||
var hiltRule = HiltAndroidRule(this) | ||
|
||
@get:Rule(order = 1) | ||
val composeTestRule = createAndroidComposeRule<MainActivity>() | ||
|
||
@Test | ||
fun test1() { | ||
// TODO: Add navigation tests | ||
composeTestRule.onNodeWithText(fakeMyModels.first(), substring = true).assertExists() | ||
} | ||
} | ||
|
Oops, something went wrong.