@@ -37,8 +37,12 @@ android {
3737 applicationId = " dev.dimension.flare"
3838 minSdk = libs.versions.minSdk.get().toInt()
3939 targetSdk = libs.versions.compileSdk.get().toInt()
40- versionCode = System .getenv(" BUILD_NUMBER" )?.toIntOrNull() ? : fdroidProp.getProperty(" versionCode" )?.toIntOrNull() ? : 1
41- versionName = System .getenv(" BUILD_VERSION" )?.toString() ? : fdroidProp.getProperty(" versionName" )?.toString() ? : " 0.0.0"
40+ versionCode =
41+ System .getenv(" BUILD_NUMBER" )?.toIntOrNull() ? : fdroidProp.getProperty(" versionCode" )
42+ ?.toIntOrNull() ? : 1
43+ versionName =
44+ System .getenv(" BUILD_VERSION" )?.toString() ? : fdroidProp.getProperty(" versionName" )
45+ ?.toString() ? : " 0.0.0"
4246
4347 testInstrumentationRunner = " androidx.test.runner.AndroidJUnitRunner"
4448 vectorDrawables {
@@ -188,3 +192,57 @@ if (project.file("google-services.json").exists()) {
188192 uploadCrashlyticsMappingFileRelease.dependsOn(processDebugGoogleServices)
189193 }
190194}
195+
196+
197+ abstract class GenerateDeepLinkManifestTask : DefaultTask () {
198+ @get:InputFile
199+ @get:PathSensitive(PathSensitivity .RELATIVE )
200+ abstract val hostsFile: RegularFileProperty
201+ @get:OutputFile
202+ abstract val manifest: RegularFileProperty
203+
204+ @TaskAction
205+ fun run () {
206+ val hosts = hostsFile.get().asFile.readLines()
207+ .map { it.trim() }
208+ .filter { it.isNotEmpty() && ! it.startsWith(" #" ) }
209+ .distinct()
210+ val dataTags = hosts.joinToString(" \n " ) { host ->
211+ """ <data android:host="$host " />"""
212+ }
213+
214+ manifest.get().asFile.writeText(
215+ """
216+ <?xml version="1.0" encoding="utf-8"?>
217+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
218+ <application>
219+ <activity android:name="dev.dimension.flare.MainActivity">
220+ <intent-filter android:autoVerify="false">
221+ <action android:name="android.intent.action.VIEW"/>
222+ <category android:name="android.intent.category.DEFAULT"/>
223+ <category android:name="android.intent.category.BROWSABLE"/>
224+ <data android:scheme="https" />
225+ $dataTags
226+ </intent-filter>
227+ </activity>
228+ </application>
229+ </manifest>
230+ """ .trimIndent()
231+ )
232+ }
233+ }
234+
235+ extensions.getByType(com.android.build.api.variant.AndroidComponentsExtension ::class .java)
236+ .onVariants { variant: com.android.build.api.variant.Variant ->
237+ val t = tasks.register(
238+ " generate${variant.name.replaceFirstChar { it.uppercase() }} DeepLinkManifest" ,
239+ GenerateDeepLinkManifestTask ::class .java
240+ ) {
241+ hostsFile = project.layout.projectDirectory.file(" deeplink.txt" )
242+ }
243+
244+ variant.sources.manifests.addGeneratedManifestFile(
245+ t,
246+ GenerateDeepLinkManifestTask ::manifest
247+ )
248+ }
0 commit comments