Skip to content
Snippets Groups Projects
Unverified Commit b679016f authored by pbad2's avatar pbad2 Committed by GitHub
Browse files

flutter_mobile_ble

parent deef3825
No related branches found
No related tags found
No related merge requests found
Showing
with 384 additions and 0 deletions
README.md 0 → 100644
# flutter_blue_app
A Flutter application that uses the `flutter_bluetooth_serial` package.
## Table of Contents
- [Overview](#overview)
- [Setting Up Flutter](#setting-up-flutter)
- [Installing Flutter on macOS](#installing-flutter-on-macos)
- [Installing Flutter on Windows](#installing-flutter-on-windows)
- [Running the Application](#running-the-application)
- [Building the APK](#building-the-apk)
- [Setting Up Android SDK (macOS)](#setting-up-android-sdk-macos)
- [Setting Up Android SDK (Windows)](#setting-up-android-sdk-windows)
- [Getting Started](#getting-started)
- [Additional Resources](#additional-resources)
## Overview
This project is a starting point for a Flutter application that integrates Bluetooth functionality using the `flutter_bluetooth_serial` package.
## Setting Up Flutter
### Installing Flutter on macOS
1. **Download Flutter**
```bash
curl -O https://storage.googleapis.com/flutter_infra_release/releases/stable/macos/flutter_macos_3.10.6-stable.zip
```
Extract the downloaded zip and move it to the desired location:
```bash
unzip flutter_macos_3.10.6-stable.zip
mv flutter ~/development/flutter
```
2. **Update Environment Variables**
Add Flutter to the PATH:
```bash
export PATH="$PATH:$HOME/development/flutter/bin"
```
To make this change permanent, add the line above to `~/.zshrc` or `~/.bashrc`, depending on your shell.
3. **Install Dependencies**
```bash
brew install cocoapods
flutter doctor
```
Follow any additional installation steps suggested by `flutter doctor`.
### Installing Flutter on Windows
1. **Download Flutter**
- Download the Flutter SDK from [Flutter Official Site](https://flutter.dev/docs/get-started/install/windows)
- Extract it to `C:\src\flutter`
2. **Update Environment Variables**
- Open **Edit environment variables** from the Start menu.
- Add `C:\src\flutter\bin` to the **Path** variable.
3. **Install Dependencies**
- Run:
```cmd
flutter doctor
```
- Install any missing dependencies reported by `flutter doctor`.
## Running the Application
1. **Add the Bluetooth Package Dependency**
In your project directory, run:
```bash
flutter pub add flutter_bluetooth_serial:^0.4.0
```
2. **Get Dependencies**
Fetch the package:
```bash
flutter pub get
```
3. **Create Necessary Files**
If needed, generate missing files:
```bash
flutter create .
```
4. **Run the App**
Launch the application:
```bash
flutter run
```
## Building the APK
1. **Set Up the Android SDK**
Follow the setup instructions below for your operating system.
2. **Clean and Build**
Once the SDK is configured, run:
```bash
flutter clean
flutter build apk --release
```
## Setting Up Android SDK (macOS)
1. **Install Android Command-Line Tools**
```bash
brew install android-commandlinetools
```
2. **Create the Android SDK Directory**
```bash
mkdir -p ~/Library/Android/sdk
```
3. **Install Essential SDK Packages**
```bash
sdkmanager --sdk_root=$HOME/Library/Android/sdk "platform-tools" "platforms;android-34" "build-tools;34.0.0" "cmdline-tools;latest"
```
4. **Configure Environment Variables**
Add these to `~/.zshrc` or `~/.bashrc`:
```bash
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$ANDROID_HOME/platform-tools:$PATH
```
5. **Verify Installation**
```bash
flutter doctor
```
## Setting Up Android SDK (Windows)
1. **Install Android Command-Line Tools**
- Download from [Android Developer](https://developer.android.com/studio#command-tools)
- Extract it to `C:\Android\cmdline-tools\latest`
2. **Install SDK Packages**
```cmd
cd C:\Android\cmdline-tools\latest\bin
sdkmanager "platform-tools" "platforms;android-34" "build-tools;34.0.0" "cmdline-tools;latest"
```
3. **Configure Environment Variables**
- Add `C:\Android\platform-tools` and `C:\Android\cmdline-tools\latest\bin` to **Path**.
4. **Verify Installation**
```cmd
flutter doctor
```
## Getting Started
This project is a great starting point for your Flutter application. If you're new to Flutter, check out these resources:
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
## Additional Resources
For more help with Flutter development, visit the [Flutter documentation](https://docs.flutter.dev/), which provides tutorials, samples, and a full API reference.
plugins {
id("com.android.application")
id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}
android {
namespace = "com.example.flutter_blue_app"
compileSdk = flutter.compileSdkVersion
ndkVersion = "27.0.12077973"
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.example.flutter_blue_app"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
}
}
}
flutter {
source = "../.."
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="flutter_blue_app"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>
package io.flutter.plugins;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import io.flutter.Log;
import io.flutter.embedding.engine.FlutterEngine;
/**
* Generated file. Do not edit.
* This file is generated by the Flutter tool based on the
* plugins that support the Android platform.
*/
@Keep
public final class GeneratedPluginRegistrant {
private static final String TAG = "GeneratedPluginRegistrant";
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
try {
flutterEngine.getPlugins().add(new io.github.edufolly.flutterbluetoothserial.FlutterBluetoothSerialPlugin());
} catch (Exception e) {
Log.e(TAG, "Error registering plugin flutter_bluetooth_serial, io.github.edufolly.flutterbluetoothserial.FlutterBluetoothSerialPlugin", e);
}
}
}
package com.example.flutter_blue_app
import io.flutter.embedding.android.FlutterActivity
class MainActivity : FlutterActivity()
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
android/app/src/main/res/mipmap-hdpi/ic_launcher.png

544 B

android/app/src/main/res/mipmap-mdpi/ic_launcher.png

442 B

android/app/src/main/res/mipmap-xhdpi/ic_launcher.png

721 B

android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png

1.01 KiB

android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png

1.41 KiB

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
allprojects {
repositories {
google()
mavenCentral()
}
}
val newBuildDir: Directory = rootProject.layout.buildDirectory.dir("../../build").get()
rootProject.layout.buildDirectory.value(newBuildDir)
subprojects {
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
project.layout.buildDirectory.value(newSubprojectBuildDir)
}
subprojects {
project.evaluationDependsOn(":app")
}
tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
File added
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment