Skip to content

Commit f0b2e67

Browse files
authored
Add version catalog support (android#787)
* Add version catalog support * Use toml deps. * Bump Kotlin version. * Update Room and Hilt versions. * PR comments.
1 parent 13ffb7a commit f0b2e67

10 files changed

Lines changed: 375 additions & 273 deletions

File tree

app/build.gradle

Lines changed: 0 additions & 149 deletions
This file was deleted.

app/build.gradle.kts

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id("com.android.application")
19+
id("kotlin-android")
20+
id("kotlin-parcelize")
21+
id("kotlin-kapt")
22+
id("dagger.hilt.android.plugin")
23+
id("androidx.navigation.safeargs.kotlin")
24+
}
25+
26+
android {
27+
compileSdk = libs.versions.compileSdk.get().toInt()
28+
buildFeatures {
29+
dataBinding = true
30+
}
31+
defaultConfig {
32+
applicationId = "com.google.samples.apps.sunflower"
33+
minSdk = libs.versions.minSdk.get().toInt()
34+
targetSdk = libs.versions.targetSdk.get().toInt()
35+
testInstrumentationRunner = "com.google.samples.apps.sunflower.utilities.MainTestRunner"
36+
versionCode = 1
37+
versionName = "0.1.6"
38+
vectorDrawables.useSupportLibrary = true
39+
40+
// Consult the README on instructions for setting up Unsplash API key
41+
buildConfigField("String", "UNSPLASH_ACCESS_KEY", "\"" + getUnsplashAccess() + "\"")
42+
javaCompileOptions {
43+
annotationProcessorOptions {
44+
arguments["dagger.hilt.disableModulesHaveInstallInCheck"] = "true"
45+
}
46+
}
47+
}
48+
buildTypes {
49+
release {
50+
isMinifyEnabled = true
51+
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
52+
}
53+
create("benchmark") {
54+
initWith(getByName("release"))
55+
signingConfig = signingConfigs.getByName("debug")
56+
isDebuggable = false
57+
proguardFiles(
58+
getDefaultProguardFile("proguard-android-optimize.txt"),
59+
"proguard-rules-benchmark.pro"
60+
)
61+
}
62+
}
63+
compileOptions {
64+
sourceCompatibility = JavaVersion.VERSION_1_8
65+
targetCompatibility = JavaVersion.VERSION_1_8
66+
}
67+
68+
kotlinOptions {
69+
// work-runtime-ktx 2.1.0 and above now requires Java 8
70+
jvmTarget = "1.8"
71+
72+
// Enable Coroutines and Flow APIs
73+
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
74+
freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlinx.coroutines.FlowPreview"
75+
}
76+
buildFeatures {
77+
compose = true
78+
dataBinding = true
79+
}
80+
composeOptions {
81+
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
82+
}
83+
packagingOptions {
84+
// Multiple dependency bring these files in. Exclude them to enable
85+
// our test APK to build (has no effect on our AARs)
86+
resources.excludes += "/META-INF/AL2.0"
87+
resources.excludes += "/META-INF/LGPL2.1"
88+
}
89+
}
90+
91+
dependencies {
92+
kapt(libs.androidx.room.compiler)
93+
kapt(libs.hilt.android.compiler)
94+
implementation(libs.androidx.appcompat)
95+
implementation(libs.androidx.constraintlayout)
96+
implementation(libs.androidx.core.ktx)
97+
implementation(libs.androidx.fragment.ktx)
98+
implementation(libs.androidx.lifecycle.livedata.ktx)
99+
implementation(libs.androidx.lifecycle.viewmodel.ktx)
100+
implementation(libs.androidx.navigation.fragment.ktx)
101+
implementation(libs.androidx.navigation.ui.ktx)
102+
implementation(libs.androidx.paging.runtime.ktx)
103+
implementation(libs.androidx.room.ktx)
104+
implementation(libs.androidx.viewpager2)
105+
implementation(libs.androidx.work.runtime.ktx)
106+
implementation(libs.material)
107+
implementation(libs.gson)
108+
implementation(libs.okhttp3.logging.interceptor)
109+
implementation(libs.retrofit2.converter.gson)
110+
implementation(libs.retrofit2)
111+
implementation(libs.kotlinx.coroutines.android)
112+
implementation(libs.kotlinx.coroutines.core)
113+
implementation(libs.hilt.android)
114+
implementation(libs.androidx.profileinstaller)
115+
implementation(libs.androidx.tracing.ktx)
116+
117+
// Compose
118+
implementation(libs.androidx.activity.compose)
119+
implementation(libs.androidx.constraintlayout.compose)
120+
implementation(libs.androidx.compose.runtime)
121+
implementation(libs.androidx.compose.ui)
122+
implementation(libs.androidx.compose.foundation)
123+
implementation(libs.androidx.compose.foundation.layout)
124+
implementation(libs.androidx.compose.material)
125+
implementation(libs.androidx.compose.ui.viewbinding)
126+
implementation(libs.androidx.compose.ui.tooling.preview)
127+
implementation(libs.androidx.compose.runtime.livedata)
128+
implementation(libs.androidx.lifecycle.viewmodel.compose)
129+
implementation(libs.material.compose.theme.adapter)
130+
implementation(libs.coil.compose)
131+
debugImplementation(libs.androidx.compose.ui.tooling)
132+
133+
// Testing dependencies
134+
kaptAndroidTest(libs.hilt.android.compiler)
135+
androidTestImplementation(libs.androidx.arch.core.testing)
136+
androidTestImplementation(libs.androidx.espresso.contrib)
137+
androidTestImplementation(libs.androidx.espresso.core)
138+
androidTestImplementation(libs.androidx.espresso.intents)
139+
androidTestImplementation(libs.androidx.test.ext.junit)
140+
androidTestImplementation(libs.androidx.test.uiautomator)
141+
androidTestImplementation(libs.androidx.work.testing)
142+
androidTestImplementation(libs.truth)
143+
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
144+
androidTestImplementation(libs.hilt.android.testing)
145+
androidTestImplementation(libs.accessibility.test.framework)
146+
androidTestImplementation(libs.kotlinx.coroutines.test)
147+
testImplementation(libs.junit)
148+
}
149+
150+
fun getUnsplashAccess(): String? {
151+
return project.findProperty("unsplash_access_key") as? String
152+
}

app/proguard-rules.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# By default, the flags in this file are appended to flags specified
33
# in /usr/local/google/home/tiem/Android/Sdk/tools/proguard/proguard-android.txt
44
# You can edit the include path and order by changing the proguardFiles
5-
# directive in build.gradle.
5+
# directive in build.gradle.kts.
66
#
77
# For more details, see
88
# http://developer.android.com/guide/developing/tools/proguard.html
@@ -31,4 +31,4 @@
3131
# Most of volatile fields are updated with AFU and should not be mangled
3232
-keepclassmembernames class kotlinx.** {
3333
volatile <fields>;
34-
}
34+
}

0 commit comments

Comments
 (0)