Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.2.5

* Upgrade Android build system to Gradle 8.14 and AGP 8.11.1
* Migrate Android build files from Groovy to Kotlin DSL (build.gradle.kts)
* Update Kotlin version to 2.2.20 and target Java 17
* Migrate example app Android build files to Kotlin DSL with new Flutter Gradle integration

## 1.2.4

* Relax rxdart version to allow library usage in FlutterFlow app builder
Expand Down
53 changes: 0 additions & 53 deletions android/build.gradle

This file was deleted.

65 changes: 65 additions & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
group = "com.sersoluciones.flutter_pos_printer_platform"
version = "1.0-SNAPSHOT"

buildscript {
val kotlinVersion = "2.2.20"
repositories {
google()
mavenCentral()
}

dependencies {
classpath("com.android.tools.build:gradle:8.11.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

plugins {
id("com.android.library")
id("kotlin-android")
}

android {
namespace = "com.sersoluciones.flutter_pos_printer_platform"

compileSdk = 36

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}

sourceSets {
getByName("main") {
java.srcDirs("src/main/kotlin")
}
getByName("test") {
java.srcDirs("src/test/kotlin")
}
}

defaultConfig {
minSdk = 24
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.21")
}
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 0 additions & 1 deletion android/settings.gradle

This file was deleted.

23 changes: 23 additions & 0 deletions android/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import org.gradle.api.initialization.resolve.RepositoriesMode

pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
plugins {
id("com.android.library") version "8.11.1"
id("org.jetbrains.kotlin.android") version "2.2.20"
}
}

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}

rootProject.name = "flutter_pos_printer_platform"
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,42 @@ class USBPrinterAdapter private constructor() {


private val mUsbDeviceReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val action = intent.action
if ((ACTION_USB_PERMISSION == action)) {
override fun onReceive(context: Context, intent: Intent?) {
if (intent == null) return

val action = intent.action ?: return

if (ACTION_USB_PERMISSION == action) {
synchronized(this) {
val usbDevice: UsbDevice? = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
if (usbDevice == null) {
Log.e(LOG_TAG, "USB_PERMISSION received but EXTRA_DEVICE was null")
return
}

val granted = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)
if (granted) {
Log.i(
LOG_TAG,
"Success get permission for device " + usbDevice!!.deviceId + ", vendor_id: " + usbDevice.vendorId + " product_id: " + usbDevice.productId
"Success get permission for device ${usbDevice.deviceId}, " +
"vendor_id: ${usbDevice.vendorId}, product_id: ${usbDevice.productId}"
)
mUsbDevice = usbDevice
} else {
Toast.makeText(
context, mContext?.getString(R.string.user_refuse_perm) + ": ${usbDevice!!.deviceName}",
context,
"${mContext?.getString(R.string.user_refuse_perm)}: ${usbDevice.deviceName ?: "Unknown"}",
Toast.LENGTH_LONG
).show()
}
}
} else if ((UsbManager.ACTION_USB_DEVICE_DETACHED == action)) {
} else if (UsbManager.ACTION_USB_DEVICE_DETACHED == action) {
if (mUsbDevice != null) {
Toast.makeText(context, mContext?.getString(R.string.device_off), Toast.LENGTH_LONG).show()
Toast.makeText(
context,
mContext?.getString(R.string.device_off) ?: "Device disconnected",
Toast.LENGTH_LONG
).show()
closeConnectionIfExists()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,52 @@ class USBPrinterService private constructor(private var mHandler: Handler?) {

private val mUsbDeviceReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val action = intent.action
if ((ACTION_USB_PERMISSION == action)) {
synchronized(this) {
val usbDevice: UsbDevice? = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
val action = intent.action ?: return

when (action) {
ACTION_USB_PERMISSION -> synchronized(this) {
val usbDevice: UsbDevice? =
intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)
if (usbDevice == null) {
Log.e(LOG_TAG, "USB_PERMISSION geldi ama EXTRA_DEVICE null")
state = STATE_USB_NONE
mHandler?.obtainMessage(STATE_USB_NONE)?.sendToTarget()
return
}

val granted = intent.getBooleanExtra(
UsbManager.EXTRA_PERMISSION_GRANTED, false
)
if (granted) {
Log.i(
LOG_TAG,
"Success get permission for device ${usbDevice?.deviceId}, vendor_id: ${usbDevice?.vendorId} product_id: ${usbDevice?.productId}"
"Permission granted for device id=${usbDevice.deviceId}, " +
"vendor=${usbDevice.vendorId}, product=${usbDevice.productId}"
)
mUsbDevice = usbDevice
state = STATE_USB_CONNECTED
mHandler?.obtainMessage(STATE_USB_CONNECTED)?.sendToTarget()
} else {
Toast.makeText(context, mContext?.getString(R.string.user_refuse_perm) + ": ${usbDevice!!.deviceName}", Toast.LENGTH_LONG).show()
val name = usbDevice.deviceName ?: "Unknown USB Device"
val title = mContext?.getString(R.string.user_refuse_perm)
?: "Permission denied"
Toast.makeText(context, "$title: $name", Toast.LENGTH_LONG).show()
state = STATE_USB_NONE
mHandler?.obtainMessage(STATE_USB_NONE)?.sendToTarget()
}
}
} else if ((UsbManager.ACTION_USB_DEVICE_DETACHED == action)) {

if (mUsbDevice != null) {
Toast.makeText(context, mContext?.getString(R.string.device_off), Toast.LENGTH_LONG).show()
closeConnectionIfExists()
state = STATE_USB_NONE
mHandler?.obtainMessage(STATE_USB_NONE)?.sendToTarget()

UsbManager.ACTION_USB_DEVICE_DETACHED -> {
if (mUsbDevice != null) {
val msg = mContext?.getString(R.string.device_off)
?: "Device disconnected"
Toast.makeText(context, msg, Toast.LENGTH_LONG).show()
closeConnectionIfExists()
mUsbDevice = null
state = STATE_USB_NONE
mHandler?.obtainMessage(STATE_USB_NONE)?.sendToTarget()
}
}

} else if ((UsbManager.ACTION_USB_DEVICE_ATTACHED == action)) {
// if (mUsbDevice != null) {
// Toast.makeText(context, "USB device has been turned off", Toast.LENGTH_LONG).show()
// closeConnectionIfExists()
// }
}
}
}
Expand Down
68 changes: 0 additions & 68 deletions example/android/app/build.gradle

This file was deleted.

Loading