Skip to content

Commit

Permalink
Merge pull request #243 from sliverappbar/build-android
Browse files Browse the repository at this point in the history
build: refine Android build system and update dependencies
  • Loading branch information
violet-dev authored Oct 14, 2023
2 parents 938c1b1 + e774807 commit bdebda8
Show file tree
Hide file tree
Showing 14 changed files with 518 additions and 402 deletions.
10 changes: 5 additions & 5 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (keystorePropertiesFile.exists()) {
}

android {
compileSdkVersion 33
compileSdkVersion Math.max(flutter.compileSdkVersion, 33)
ndkVersion flutter.ndkVersion

compileOptions {
Expand All @@ -51,11 +51,11 @@ android {
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "xyz.project.violet"

// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 23
minSdkVersion Math.max(flutter.minSdkVersion, 23)
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down Expand Up @@ -89,6 +89,6 @@ flutter {
}

dependencies {
implementation 'androidx.work:work-runtime:2.7.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.work:work-runtime:2.8.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
62 changes: 38 additions & 24 deletions android/app/src/main/kotlin/xyz/project/violet/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,73 +1,87 @@
package xyz.project.violet

import android.app.Activity
import android.net.VpnService
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.view.KeyEvent
import android.view.View
import android.view.WindowManager
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterFragmentActivity() {
private val CHANNEL = "xyz.project.violet/dpitunnel"
class MainActivity : FlutterFragmentActivity() {
private val VOLUME_CHANNEL = "xyz.project.violet/volume"
private val NATIVELIBDIR_CHANNEL = "xyz.project.violet/nativelibdir";
private var sink: EventChannel.EventSink? = null;
private val NATIVELIBDIR_CHANNEL = "xyz.project.violet/nativelibdir"
private val EXTERNAL_STORAGE_DIRECTORY_CHANNEL = "xyz.project.violet/externalStorageDirectory"

private val EXTERNAL_STORAGE_DIRECTORY_METHODS = mapOf(
"getExternalStorageDirectory" to MethodCallHandler { call, result ->
result.success(Environment.getExternalStorageDirectory().path)
},
"getExternalStorageDownloadsDirectory" to MethodCallHandler { call, result ->
result.success(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path)
},
)

private var sink: EventChannel.EventSink? = null

//
// Source code from https://github.com/tommy351/eh-redux/commit/0f63f6090c91e06c4ef7241847fad173b4afad86
//
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && this is Activity)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
window.isNavigationBarContrastEnforced = false
}

override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)

EventChannel(flutterEngine.dartExecutor.binaryMessenger, VOLUME_CHANNEL).setStreamHandler(object : EventChannel.StreamHandler {
override fun onListen(arguments: Any?, eventSink: EventChannel.EventSink?) {
sink = eventSink;
sink = eventSink
}

override fun onCancel(arguments: Any?) {
sink = null
}
})

MethodChannel(flutterEngine.dartExecutor.binaryMessenger, NATIVELIBDIR_CHANNEL).setMethodCallHandler {
call, result ->
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, NATIVELIBDIR_CHANNEL).setMethodCallHandler { call, result ->
// Note: this method is invoked on the main thread.
if (call.method == "getNativeDir") {
result.success(getApplicationContext().getApplicationInfo().nativeLibraryDir);
result.success(applicationContext.applicationInfo.nativeLibraryDir)
} else {
result.notImplemented()
}
}

MethodChannel(flutterEngine.dartExecutor.binaryMessenger, EXTERNAL_STORAGE_DIRECTORY_CHANNEL).setMethodCallHandler { call, result ->
val method = EXTERNAL_STORAGE_DIRECTORY_METHODS[call.method]
if (method != null) {
method.onMethodCall(call, result)
} else {
result.notImplemented()
}
}
}

override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP)
{
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
sink?.success(if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) "down" else "up")
return true;
return true
}

return super.onKeyDown(keyCode, event)
Expand Down
9 changes: 5 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.7.21'

repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
classpath 'com.google.gms:google-services:4.4.0'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
}
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
Loading

0 comments on commit bdebda8

Please sign in to comment.