Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android fixes #176

Merged
merged 7 commits into from
Oct 28, 2024
Merged
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
9 changes: 4 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: '12.x'
java-version: '17'

- name: Load certificate
run: |
Expand All @@ -45,15 +45,14 @@ jobs:
dart analyze
dart run msix:create

# Temporarily removed because Android builds are broken
# - name: Build APK
# run: flutter build apk
- name: Build APK
run: flutter build apk

- name: Create Release
uses: softprops/[email protected]
with:
# build/app/outputs/apk/release/app-release.apk
files: |
build/app/outputs/apk/release/app-release.apk
build/windows/x64/runner/Release/Dashboard.msix
name: ${{ github.ref_name }}
generate_release_notes: true
Expand Down
27 changes: 11 additions & 16 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) {
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
Expand All @@ -21,21 +22,19 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
namespace "com.example.dashboard"

compileSdkVersion 34
ndkVersion flutter.ndkVersion

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

kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}

sourceSets {
Expand All @@ -61,7 +60,3 @@ android {
flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
13 changes: 0 additions & 13 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
buildscript {
ext.kotlin_version = '1.8.21'
repositories {
google()
mavenCentral()
}

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

allprojects {
repositories {
google()
Expand Down
4 changes: 3 additions & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
30 changes: 22 additions & 8 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.4.2" apply false
id "org.jetbrains.kotlin.android" version "1.8.10" apply false
}

include ":app"
5 changes: 4 additions & 1 deletion lib/src/services/gamepad/gamepad.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "package:rover_dashboard/src/services/gamepad/mock.dart";

import "state.dart";
import "sdl.dart";

Expand All @@ -18,7 +20,8 @@ abstract class Gamepad extends Service {
Gamepad(this.controllerIndex);

/// Returns a functional instance of this class, or a mock on unsupported platforms.
factory Gamepad.forPlatform(int index) => DesktopGamepad(index);
factory Gamepad.forPlatform(int index) => isSdlSupported
? DesktopGamepad(index) : MockGamepad(index);

/// Gets the current state of the gamepad, or null if it's not connected.
GamepadState? getState();
Expand Down
12 changes: 12 additions & 0 deletions lib/src/services/gamepad/sdl.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import "dart:io";
import "package:flutter_sdl_gamepad/flutter_sdl_gamepad.dart" as sdl;

import "state.dart";
import "gamepad.dart";

/// Whether `package:sdl_gamepad` has been tested on this platform.
bool get isSdlSupported => Platform.isWindows || Platform.isLinux;

/// Initializes the SDL libraries.
void initSdl() {
if (!isSdlSupported) return;
if (!sdl.SdlLibrary.init()) {
throw StateError("Could not initialize SDL libraries");
}
}

/// A cross-platform implementation based on the `sdl_gamepad` package.
class DesktopGamepad extends Gamepad {
final sdl.SdlGamepad _sdl;
Expand Down
11 changes: 7 additions & 4 deletions lib/src/services/gamepad/service.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "package:flutter_sdl_gamepad/flutter_sdl_gamepad.dart";
import "package:rover_dashboard/src/services/gamepad/sdl.dart";

import "../service.dart";
import "gamepad.dart";
Expand All @@ -24,6 +25,10 @@ class GamepadService extends Service {
/// The maximum number of gamepads that will be connected.
static const maxGamepads = 3;

/// Gets a list of currently connected gamepads.
static Iterable<int> getConnectedGamepads() => isSdlSupported
? SdlGamepad.getConnectedGamepadIds() : [];

/// A list of gamepads that are currently connected.
///
/// Note that the index in this list does **not** correspond to [Gamepad.controllerIndex]. The
Expand All @@ -45,9 +50,7 @@ class GamepadService extends Service {

@override
Future<void> init() async {
if (!SdlLibrary.init()) {
throw StateError("Could not initialize SDL libraries");
}
if (isSdlSupported) initSdl();
gamepads = List.generate(maxGamepads, MockGamepad.new);
for (var i = 0; i < maxGamepads; i++) {
await connect(i);
Expand All @@ -69,7 +72,7 @@ class GamepadService extends Service {
return;
}
gamepads[operatorIndex] = MockGamepad(0);
for (final osIndex in SdlGamepad.getConnectedGamepadIds()) {
for (final osIndex in getConnectedGamepads()) {
if (osIndexes.contains(osIndex)) continue;
final gamepad = Gamepad.forPlatform(osIndex);
await gamepad.init();
Expand Down
Loading
Loading