Skip to content

Commit

Permalink
feat: update android plugin template with latest flutter changes (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomarra authored May 22, 2024
1 parent 18ab28b commit f7e6c45
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/.idea/libraries
.DS_Store
/build
/captures
/captures
.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ group '{{org_name.dotCase()}}'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
allprojects {
repositories {
google()
mavenCentral()
Expand All @@ -25,7 +25,11 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
if (project.android.hasProperty("namespace")) {
namespace '{{org_name.dotCase()}}'
}

compileSdk 34

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -38,13 +42,27 @@ android {

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
}

defaultConfig {
minSdkVersion 16
minSdkVersion 19
}

dependencies {
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'org.mockito:mockito-core:5.0.0'
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testOptions {
unitTests.all {
useJUnitPlatform()

testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package {{org_name.dotCase()}}

import android.content.Context
import androidx.annotation.NonNull

import io.flutter.embedding.engine.plugins.FlutterPlugin
Expand All @@ -11,24 +10,21 @@ import io.flutter.plugin.common.MethodChannel.Result

class {{project_name.pascalCase()}}Plugin : FlutterPlugin, MethodCallHandler {
private lateinit var channel: MethodChannel
private var context: Context? = null

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "{{project_name.snakeCase()}}_android")
channel.setMethodCallHandler(this)
context = flutterPluginBinding.applicationContext
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method == "getPlatformName") {
result.success("Android")
result.success("Android ${android.os.Build.VERSION.RELEASE}")
} else {
result.notImplemented()
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
context = null
}
}

0 comments on commit f7e6c45

Please sign in to comment.