From 4f633dfcf05fdfa0b18a5d29248159367153612c Mon Sep 17 00:00:00 2001 From: Pranav <122373207+pranavkonidena@users.noreply.github.com> Date: Sat, 23 Mar 2024 23:28:57 +0530 Subject: [PATCH] Dockerize NoticeBoard (#40) --- .devcontainer/devcontainer.json | 27 +++++++ .github/workflows/release.yml | 2 +- .github/workflows/workflow.yml | 2 +- Dockerfile | 55 ++++++++++++++ README.md | 42 +++++++++++ noticeboard/android/app/build.gradle | 72 ++++++++----------- .../noticeboard/MainActivity.kt | 0 noticeboard/android/build.gradle | 14 ---- .../gradle/wrapper/gradle-wrapper.properties | 2 +- noticeboard/android/settings.gradle | 31 +++++--- 10 files changed, 180 insertions(+), 67 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 Dockerfile rename noticeboard/android/app/src/main/kotlin/com/{example => img}/noticeboard/MainActivity.kt (100%) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..3344e69 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,27 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile +{ + "name": "Noticeboard Docker File", + "build": { + // Sets the run context to one level up instead of the .devcontainer folder. + "context": "..", + // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. + "dockerfile": "../Dockerfile" + }, + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [5037], + + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "cat /etc/os-release", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "devcontainer" + "dockerRun": {"runArgs": ["--privileged"]} +} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6399bcd..228bb81 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,4 +44,4 @@ jobs: - uses: actions/upload-artifact@v3 with: name: NoticeBoard - path: build/app/outputs/apk/release/NoticeBoardApp.apk + path: build/app/outputs/flutter-apk/app-release.apk diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4962127..c1337da 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -44,4 +44,4 @@ jobs: - uses: actions/upload-artifact@v3 with: name: NoticeBoard - path: build/app/outputs/apk/release/NoticeBoardApp.apk + path: build/app/outputs/flutter-apk/app-release.apk diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..58c77bd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +# Use ubuntu 22.04 LTS as Base Image +FROM ubuntu:22.04 + +# This sets up java in the container +RUN apt update && apt install -y curl git unzip xz-utils zip libglu1-mesa openjdk-8-jdk wget adb libjaxb-api-java + +# Set up new user +RUN useradd -ms /bin/bash developer +WORKDIR /home/developer + +# Prepare Android directories and system variables +RUN cd /home/developer +RUN mkdir -p Android/sdk +ENV ANDROID_SDK_ROOT /home/developer/Android/sdk +RUN mkdir -p .android && touch .android/repositories.cfg + +# Set up Android SDK and accept licenses +RUN wget -O sdk-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip +RUN unzip sdk-tools.zip && rm sdk-tools.zip +RUN cd /home/developer +RUN mv tools Android/sdk/tools +RUN cd Android/sdk/tools/bin && yes | ./sdkmanager --licenses +RUN cd /home/developer +RUN cd Android/sdk/tools/bin && touch /root/.android/repositories.cfg && ./sdkmanager "build-tools;29.0.2" "platform-tools" "platforms;android-29" "sources;android-29" "cmdline-tools;latest" +ENV PATH "$PATH:/home/developer/Android/sdk/platform-tools" + +# Download Flutter SDK and add flutter to path +RUN cd /home/developer +RUN wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.19.1-stable.tar.xz +RUN tar -xvf flutter_linux_3.19.1-stable.tar.xz +RUN git config --global --add safe.directory /home/developer/flutter +WORKDIR /home/developer +ENV PATH "$PATH:/home/developer/flutter/bin" + +# Run basic check to download Dark SDK +RUN flutter doctor + +# Install JavaDevelopment Kit +RUN apt install -y openjdk-17-jdk + +# Accept all Android-SDK licenses +RUN flutter doctor --android-licenses + +# Verify android toolchain is set up for development +RUN flutter doctor -v + +# Go to noticeboard-mobile directory +WORKDIR /workspaces/noticeboard-mobile-app/noticeboard + + +# Install dependencies +CMD [ "flutter" "pub" "get" ] + + + diff --git a/README.md b/README.md index efd66c8..0d7ee1b 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,48 @@ The official digital noticeboard of IITR. Provides easy access to the Channel i - Bookmark notices on the go! - Now after many demands from the iPhone users, noticeboard finally comes on the app store! +## Development Setup + +### Prerequisites +- Visual Studio Code +- Docker +- Android phone with USB debugging enabled + +### Installing VS Code Dev Container Extension +1. Open Visual Studio Code. +2. Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or by pressing Ctrl+Shift+X. +3. Search for "Remote - Containers" and click Install. + +### Opening the Project in a Dev Container +1. Clone the project repository. +2. Open the project folder in Visual Studio Code. +3. Press Cmd+Shift+P on Mac or Ctrl+Shift+P on Ubuntu/Windows to open the Command Palette. +4. Search for "Remote-Containers: Open Folder in Container" and select it. +5. Wait for the container to build (this may take some time, especially the first time). + +### Setting up Android Phone for Debugging +1. Ensure your phone and PC are connected to the same Wi-Fi network. +2. Enable USB debugging on your phone: + - Go to Settings > About phone > Software information. + - Tap "Build number" seven times to enable Developer options. + - Go back to the main Settings screen, and now you should see "Developer options". + - Open Developer options and enable USB debugging. +3. Enable wireless debugging on your phone: + - Connect your phone to your computer via USB cable. + - Run `adb usb` from inside the dev container. + - Run `adb tcpip 5037` from inside the dev container. + - Run `adb connect :5037` from inside the dev container. + - Disconnect the USB cable. + - Run `flutter run` + +### Running the App on Your Android Phone +1. After connecting your phone, wait for the app to build (this may take up to 15 minutes for the first build). +2. Once the build is complete, the app will be launched on your phone. +3. You can now make changes to the app and view updates in real-time on your phone. + +Please replace `` with the actual IP address of your phone. If you encounter any issues with the connection, try running `adb connect :5555` instead. + + ## Privacy Policy Link to privacy policy: https://docs.google.com/document/d/1vsbooZi9PIiVIMaLts2wv0tODEJafCaRT41zsENYN3I/edit diff --git a/noticeboard/android/app/build.gradle b/noticeboard/android/app/build.gradle index 6636fc1..6cff323 100644 --- a/noticeboard/android/app/build.gradle +++ b/noticeboard/android/app/build.gradle @@ -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()) { @@ -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' @@ -21,59 +22,46 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'com.google.gms.google-services' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" +android { + namespace 'com.img.noticeboard' + compileSdk 34 + ndkVersion flutter.ndkVersion -def keystoreProperties = new Properties() -def keystorePropertiesFile = rootProject.file('key.properties') -if (keystorePropertiesFile.exists()) { - keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) -} + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } -android { - compileSdkVersion 33 + kotlinOptions { + jvmTarget = '1.8' + } sourceSets { main.java.srcDirs += 'src/main/kotlin' } - lintOptions { - disable 'InvalidPackage' - } - defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.img.noticeboard" - minSdkVersion 19 - targetSdkVersion 31 + // You can update the following values to match your application needs. + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. + minSdkVersion 21 + targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } - signingConfigs { - release { - keyAlias keystoreProperties['keyAlias'] - keyPassword keystoreProperties['keyPassword'] - storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null - storePassword keystoreProperties['storePassword'] - } - } - - buildTypes { - release { - signingConfig signingConfigs.release - } - } - + 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.debug + } + } } flutter { source '../..' } -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation platform('com.google.firebase:firebase-bom:29.0.3') - implementation 'com.google.firebase:firebase-analytics' -} +dependencies {} \ No newline at end of file diff --git a/noticeboard/android/app/src/main/kotlin/com/example/noticeboard/MainActivity.kt b/noticeboard/android/app/src/main/kotlin/com/img/noticeboard/MainActivity.kt similarity index 100% rename from noticeboard/android/app/src/main/kotlin/com/example/noticeboard/MainActivity.kt rename to noticeboard/android/app/src/main/kotlin/com/img/noticeboard/MainActivity.kt diff --git a/noticeboard/android/build.gradle b/noticeboard/android/build.gradle index 2c56939..5869be3 100644 --- a/noticeboard/android/build.gradle +++ b/noticeboard/android/build.gradle @@ -1,17 +1,3 @@ -buildscript { - ext.kotlin_version = '1.9.23' - repositories { - google() - jcenter() - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.3.0' - classpath 'com.google.gms:google-services:4.3.14' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() diff --git a/noticeboard/android/gradle/wrapper/gradle-wrapper.properties b/noticeboard/android/gradle/wrapper/gradle-wrapper.properties index 6b66533..89e56bd 100644 --- a/noticeboard/android/gradle/wrapper/gradle-wrapper.properties +++ b/noticeboard/android/gradle/wrapper/gradle-wrapper.properties @@ -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.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip diff --git a/noticeboard/android/settings.gradle b/noticeboard/android/settings.gradle index 44e62bc..3613de8 100644 --- a/noticeboard/android/settings.gradle +++ b/noticeboard/android/settings.gradle @@ -1,11 +1,26 @@ -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.3.0" apply false + id "com.google.gms.google-services" version "4.3.14" apply false + id "org.jetbrains.kotlin.android" version "1.9.23" apply false +} + +include ":app"