Skip to content

Instantly share code, notes, and snippets.

@DRSchlaubi
Last active April 14, 2024 15:00
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save DRSchlaubi/f42be0da6fbd8864565b043b3da3b8b2 to your computer and use it in GitHub Desktop.
Save DRSchlaubi/f42be0da6fbd8864565b043b3da3b8b2 to your computer and use it in GitHub Desktop.
Flutter Kotlin Gradle DSL
import java.util.Properties
import java.nio.file.Files
val localProperties = Properties()
val localPropertiesFile = rootProject.file("local.properties").toPath()
if (Files.exists(localPropertiesFile)) {
Files.newBufferedReader(localPropertiesFile).use { reader ->
localProperties.load(reader)
}
}
val flutterRoot = localProperties.getProperty("flutter.sdk")
?: throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
val flutterVersionCode = localProperties.getProperty("flutter.versionCode") ?: "1"
val flutterVersionName = localProperties.getProperty("flutter.versionName") ?: "1.0"
plugins {
id("com.android.application")
kotlin("android")
kotlin("android.extensions")
}
apply("$flutterRoot/packages/flutter_tools/gradle/flutter.gradle")
android {
compileSdkVersion(30)
lintOptions {
disable("InvalidPackage")
}
defaultConfig {
applicationId = "com.linkdesk.android.automator"
minSdkVersion(23)
targetSdkVersion(30)
versionCode = flutterVersionCode.toInt()
versionName = flutterVersionName
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
create("release") {
storeFile = file("<>")
storePassword = "<>"
keyAlias = "<>"
keyPassword = "<>"
}
}
buildTypes {
getByName("release") {
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("release")
}
}
buildToolsVersion = "29.0.3"
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
project.extensions.getByName("flutter").apply {
this::class.java.getMethod("source", String::class.java).invoke(this, "../..")
}
dependencies {
testImplementation("junit:junit:4.13")
androidTestImplementation("androidx.test.ext:junit:1.1.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.2.0")
implementation("androidx.core:core-ktx:1.3.1")
implementation(kotlin("stdlib-jdk7"))
}
apply(plugin = "io.fabric")
// Google Play services Gradle plugin
apply(plugin = "com.google.gms.google-services")
buildscript {
extra.set("kotlin_version", "1.3.72")
repositories {
google()
jcenter()
maven("https://maven.fabric.io/public")
}
dependencies {
classpath("com.android.tools.build:gradle:4.0.1")
classpath("com.google.gms:google-services:4.3.3") // Google Services plugin
classpath(kotlin("gradle-plugin", version = "1.3.72"))
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = file("../build")
subprojects {
project.buildDir = file("${rootProject.buildDir}/${project.name}")
project.evaluationDependsOn(":app")
}
tasks {
task<Delete>("clean") {
delete( rootProject.buildDir)
}
}
import java.nio.file.Files
import java.util.*
include(":app")
val flutterProjectRoot = rootDir.toPath().parent
val plugins = Properties()
val pluginsFile = flutterProjectRoot.resolve(".flutter-plugins")
if (Files.exists(pluginsFile)) {
Files.newBufferedReader(pluginsFile).use { plugins.load(it) }
}
plugins.forEach { name, path ->
val pluginDirectory = flutterProjectRoot.resolve(path as String).resolve("android")
include(":$name")
project(":$name").projectDir = pluginDirectory.toFile()
}
@vickyleu
Copy link

stuck infinity on 8.3.0-alpha03 + gradle-8.3-bin

> Configure project :app
Kotlin DSL property assignment is an incubating feature.

> Configure project :
Starting a Gradle Daemon, 19 busy and 97 stopped Daemons could not be reused, use --status for details

@jeiea
Copy link

jeiea commented Jan 30, 2024

flutter build appbundle caused this. (flutter 3.16.7)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It is being deprecated in favor of Android embedding v2. To migrate
your project, follow the steps at:

https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The detected reason was:

  No `/Users/jeiea/Documents/project/android/AndroidManifest.xml` file
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Build failed due to use of deprecated Android v1 embedding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment