├── .github
└── workflows
│ └── ci.yml
├── .gitignore
├── .idea
├── .gitignore
├── .name
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── compiler.xml
├── deploymentTargetDropDown.xml
├── gradle.xml
├── jarRepositories.xml
├── kotlinc.xml
├── migrations.xml
├── misc.xml
└── vcs.xml
├── LICENSE.md
├── README.md
├── android_elixir.png
├── app.png
├── app
├── .gitignore
├── .tool-versions
├── build.gradle
├── libs
│ └── erlang.jar
├── proguard-rules.pro
├── run_mix
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ ├── arm64-v8a-nif-exqlite.zip
│ ├── arm64-v8a-runtime.zip
│ ├── armeabi-v7a-nif-exqlite.zip
│ ├── armeabi-v7a-runtime.zip
│ ├── x86_64-nif-exqlite.zip
│ └── x86_64-runtime.zip
│ ├── cpp
│ ├── CMakeLists.txt
│ └── native-lib.cpp
│ ├── ic_launcher-playstore.png
│ ├── java
│ └── io
│ │ └── elixirdesktop
│ │ └── example
│ │ ├── Bridge.kt
│ │ └── MainActivity.kt
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── values-night
│ └── themes.xml
│ ├── values
│ ├── colors.xml
│ ├── ic_launcher_background.xml
│ ├── strings.xml
│ └── themes.xml
│ └── xml
│ └── provider_paths.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── icon.jpg
└── settings.gradle
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: Android CI
2 |
3 | on: ["push", "pull_request"]
4 |
5 | jobs:
6 | build:
7 |
8 | runs-on: ubuntu-latest
9 |
10 | steps:
11 | - uses: actions/checkout@v1
12 | - name: Install asdf, erlang, elixir
13 | run: |
14 | sudo apt install curl git
15 | git clone https://github.com/asdf-vm/asdf.git $HOME/.asdf --branch v0.10.2
16 | . $HOME/.asdf/asdf.sh
17 | asdf plugin-add erlang
18 | asdf plugin-add elixir
19 |
20 | cd app
21 | asdf install
22 | mix local.hex --force
23 | mix local.rebar --force
24 |
25 | - name: Set up JDK 17
26 | uses: actions/setup-java@v1
27 | with:
28 | java-version: 17
29 |
30 | - name: Build with Gradle
31 | run: |
32 | . $HOME/.asdf/asdf.sh
33 | ./gradlew assembleDebug --stacktrace
34 |
35 | - name: Upload APK
36 | uses: actions/upload-artifact@v1
37 | with:
38 | name: app
39 | path: app/build/outputs/apk/debug/app-debug.apk
40 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /app/release
4 | /local.properties
5 | /.idea/caches
6 | /.idea/misc.xml
7 | /.idea/libraries
8 | /.idea/modules.xml
9 | /.idea/workspace.xml
10 | /.idea/navEditor.xml
11 | /.idea/assetWizardSettings.xml
12 | .DS_Store
13 | /build
14 | /captures
15 | .externalNativeBuild
16 | .cxx
17 | local.properties
18 | /app/elixir-app
19 | /app/src/main/assets/app.zip
20 | /app/src/main/assets/app.zip.xz
21 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | TodoApp
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | xmlns:android
18 |
19 | ^$
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | xmlns:.*
29 |
30 | ^$
31 |
32 |
33 | BY_NAME
34 |
35 |
36 |
37 |
38 |
39 |
40 | .*:id
41 |
42 | http://schemas.android.com/apk/res/android
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | .*:name
52 |
53 | http://schemas.android.com/apk/res/android
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | name
63 |
64 | ^$
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | style
74 |
75 | ^$
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | .*
85 |
86 | ^$
87 |
88 |
89 | BY_NAME
90 |
91 |
92 |
93 |
94 |
95 |
96 | .*
97 |
98 | http://schemas.android.com/apk/res/android
99 |
100 |
101 | ANDROID_ATTRIBUTE_ORDER
102 |
103 |
104 |
105 |
106 |
107 |
108 | .*
109 |
110 | .*
111 |
112 |
113 | BY_NAME
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetDropDown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/migrations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # MIT License
2 |
3 | Copyright (c) 2021 Dominic Letz
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TodoApp Android: An Android Sample App
2 |
3 | This Android Studio project wraps the [Desktop Sample App](https://github.com/elixir-desktop/desktop-example-app) to run on an Android phone.
4 |
5 | ## Runtime Notes
6 |
7 | The pre-built Erlang runtime for Android ARM/ARM64/x86 is embedded in this example git repository. These native runtime files include Erlang OTP and the exqlite nif to use SQLite on the mobile. These runtimes are generated using the CI of the [Desktop Runtime](https://github.com/elixir-desktop/runtimes) repository.
8 |
9 | Because Erlang OTP has many native hooks for networking and cryptographics the Erlang version used to compile your App must match the pre-built binary release that is embedded. In this example that is Erlang OTP 25.0.4. This sample is shipping with a `.tool-versions` file that `asdf` will automatically use to automate this requirement.
10 |
11 | ## How to build & run
12 |
13 | 1. Install [Android Studio](https://developer.android.com/studio) + NDK.
14 | 1. Install git, npm, asdf
15 |
16 | ```
17 | sudo apt install git npm curl
18 | git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.2
19 | echo ". $HOME/.asdf/asdf.sh" >> ~/.bashrc
20 | echo ". $HOME/.asdf/completions/asdf.bash" >> ~/.bashrc
21 | . $HOME/.asdf/asdf.sh
22 | ```
23 |
24 | 1. Install Erlang-OTP (with openssl) in the same version 26.2.5 as the bundled runtime edition:
25 |
26 | ```
27 | asdf install erlang 26.2.5
28 | asdf install elixir 1.17.2-otp-26
29 | ```
30 |
31 | 1. Go to "Files -> New -> Project from Version Control" and enter this URL: https://github.com/elixir-desktop/android-example-app/
32 |
33 | 1. Start the App
34 |
35 |
36 | ## Customize app name and branding
37 |
38 | Update these places with your package name:
39 |
40 | 1) App name in [strings.xml](app/src/main/res/values/strings.xml#L2) and [settings.gradle](settings.gradle)
41 | 1) Package names in [Bridge.kt:1](app/src/main/java/io/elixirdesktop/example/Bridge.kt#L1) and [MainActivity.kt:1](app/src/main/java/io/elixirdesktop/example/MainActivity.kt#L1) (rename `package io.elixirdesktop.example` -> `com.yourapp.name` or use the Android Studios refactor tool)
42 | 1) App icon: [ic_launcher_foreground.xml](app/src/main/res/drawable-v24/ic_launcher_foreground.xml) and [ic_launcher-playstore.png](app/src/main/ic_launcher-playstore.png)
43 | 1) App colors: [colors.xml](app/src/main/res/values/colors.xml) and launcher background [ic_launcher_background.xml](app/src/main/res/values/ic_launcher_background.xml)
44 |
45 | ## Known todos
46 |
47 | ### Initial Startup could be faster
48 |
49 | Running the app for the first time will extract the full Elixir & App runtime at start. On my Phone this takes around 10 seconds. After that a cold app startup takes ~3-4 seconds.
50 |
51 | ### Menus and other integration not yet available
52 |
53 | This sample only launch the elixir app and shows it in an Android WebView. There is no integration yet with the Android Clipboard, sharing or other OS capabilities. They can though easily be added to the `Bridge.kt` file when needed.
54 |
55 | ## Other notes
56 |
57 | - Android specific settings, icons and metadata are all contained in this Android Studio wrapper project.
58 |
59 | - `Bridge.kt` and the native library are doing most of the wrapping of the Elixir runtime.
60 |
61 | ## Screenshots
62 |
63 | 
64 | 
65 |
66 | ## Architecture
67 |
68 | 
69 |
70 | The Android App is initializing the Erlang VM and starting it up with a new environment variable `BRIDGE_PORT`. This environment variable is used by the `Bridge` project to connect to a local TCP server _inside the android app_. Through this new TCP communication channel all calls that usually would go to `wxWidgets` are now redirected. The Android side of things implements handling in `Bridge.kt`.
71 |
--------------------------------------------------------------------------------
/android_elixir.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/android_elixir.png
--------------------------------------------------------------------------------
/app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/app.png
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/.tool-versions:
--------------------------------------------------------------------------------
1 | erlang 26.2.5
2 | elixir 1.17.2-otp-26
3 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | }
5 |
6 | android {
7 | namespace 'io.elixirdesktop.example'
8 | compileSdk 33
9 |
10 | task buildNum(type: Exec, description: 'Update Elixir App') {
11 | commandLine './run_mix', 'package.mobile'
12 | }
13 |
14 | tasks.withType(JavaCompile) {
15 | compileTask -> compileTask.dependsOn buildNum
16 | }
17 |
18 |
19 | defaultConfig {
20 | applicationId "io.elixirdesktop.example"
21 | minSdk 29
22 | targetSdk 33
23 | versionCode 1
24 | versionName "1.0"
25 |
26 | ndk {
27 | abiFilters "armeabi-v7a", "arm64-v8a" , "x86_64"
28 | }
29 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
30 | externalNativeBuild {
31 | cmake {
32 | cppFlags ''
33 | }
34 | }
35 | }
36 |
37 | buildTypes {
38 | release {
39 | minifyEnabled true
40 | shrinkResources true
41 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
42 | }
43 | }
44 | compileOptions {
45 | sourceCompatibility JavaVersion.VERSION_1_8
46 | targetCompatibility JavaVersion.VERSION_1_8
47 | }
48 | kotlinOptions {
49 | jvmTarget = '1.8'
50 | }
51 | externalNativeBuild {
52 | cmake {
53 | path file('src/main/cpp/CMakeLists.txt')
54 | version '3.22.1'
55 | }
56 | }
57 | buildFeatures {
58 | viewBinding true
59 | }
60 | packagingOptions {
61 | jniLibs {
62 | useLegacyPackaging = true
63 | }
64 | }
65 | }
66 |
67 | dependencies {
68 | implementation fileTree(dir: "libs", include: '*.jar')
69 |
70 | implementation 'androidx.core:core-ktx:1.9.0'
71 | implementation 'androidx.appcompat:appcompat:1.6.1'
72 | implementation 'com.google.android.material:material:1.8.0'
73 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
74 | testImplementation 'junit:junit:4.13.2'
75 | androidTestImplementation 'androidx.test.ext:junit:1.1.5'
76 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
77 | }
--------------------------------------------------------------------------------
/app/libs/erlang.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/app/libs/erlang.jar
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
23 | -dontskipnonpubliclibraryclasses
24 | -dontobfuscate
25 | -forceprocessing
26 | -optimizationpasses 5
27 |
28 | -keep class * extends android.app.Activity
29 | -assumenosideeffects class android.util.Log {
30 | public static *** d(...);
31 | public static *** v(...);
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/app/run_mix:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | . ~/.asdf/asdf.sh
3 | set -e
4 |
5 | BASE=`pwd`
6 | APP_FILE="$BASE/src/main/assets/app.zip"
7 | export MIX_ENV=prod
8 | export MIX_TARGET=android
9 |
10 | if [ ! -d "elixir-app" ]; then
11 | git clone https://github.com/elixir-desktop/desktop-example-app.git elixir-app
12 | fi
13 |
14 | # using the right runtime versions
15 | cp .tool-versions elixir-app/
16 | cd elixir-app
17 |
18 | if [ ! -d "deps/desktop" ]; then
19 | mix local.hex --force
20 | mix local.rebar
21 | mix deps.get
22 | fi
23 |
24 | if [ ! -d "assets/node_modules" ]; then
25 | cd assets && npm i && cd ..
26 | fi
27 |
28 | if [ -f "$APP_FILE" ]; then
29 | rm "$APP_FILE"
30 | fi
31 |
32 | mix assets.deploy && \
33 | mix release --overwrite && \
34 | cd "_build/${MIX_TARGET}_${MIX_ENV}/rel/default_release" && \
35 | zip -9r "$APP_FILE" lib/ releases/ --exclude "*.so"
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
18 |
19 |
24 |
27 |
28 |
29 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/assets/arm64-v8a-nif-exqlite.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/app/src/main/assets/arm64-v8a-nif-exqlite.zip
--------------------------------------------------------------------------------
/app/src/main/assets/arm64-v8a-runtime.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/app/src/main/assets/arm64-v8a-runtime.zip
--------------------------------------------------------------------------------
/app/src/main/assets/armeabi-v7a-nif-exqlite.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/app/src/main/assets/armeabi-v7a-nif-exqlite.zip
--------------------------------------------------------------------------------
/app/src/main/assets/armeabi-v7a-runtime.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/app/src/main/assets/armeabi-v7a-runtime.zip
--------------------------------------------------------------------------------
/app/src/main/assets/x86_64-nif-exqlite.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/app/src/main/assets/x86_64-nif-exqlite.zip
--------------------------------------------------------------------------------
/app/src/main/assets/x86_64-runtime.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/app/src/main/assets/x86_64-runtime.zip
--------------------------------------------------------------------------------
/app/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # For more information about using CMake with Android Studio, read the
2 | # documentation: https://d.android.com/studio/projects/add-native-code.html
3 |
4 | # Sets the minimum version of CMake required to build the native library.
5 |
6 | cmake_minimum_required(VERSION 3.10.2)
7 |
8 | # Declares and names the project.
9 |
10 | project("example")
11 |
12 | # Creates and names a library, sets it as either STATIC
13 | # or SHARED, and provides the relative paths to its source code.
14 | # You can define multiple libraries, and CMake builds them for you.
15 | # Gradle automatically packages shared libraries with your APK.
16 |
17 | add_library(native-lib SHARED native-lib.cpp)
18 |
19 | # Searches for a specified prebuilt library and stores the path as a
20 | # variable. Because CMake includes system libraries in the search path by
21 | # default, you only need to specify the name of the public NDK library
22 | # you want to add. CMake verifies that the library exists before
23 | # completing its build.
24 |
25 | find_library(log-lib log)
26 |
27 | # Specifies libraries CMake should link to your target library. You
28 | # can link multiple libraries, such as libraries you define in this
29 | # build script, prebuilt third-party libraries, or system libraries.
30 |
31 | target_link_libraries(native-lib ${log-lib})
32 |
--------------------------------------------------------------------------------
/app/src/main/cpp/native-lib.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | std::string jstring2string(JNIEnv *env, jstring jStr);
8 | int start_logger();
9 | static void logger_func();
10 | static std::string log_file;
11 | void (*startfun)(int argc, char **argv);
12 |
13 | void ensure_slash(std::string& str)
14 | {
15 | if (!str.empty() && str[str.size()-1] != '/') {
16 | str.append("/");
17 | }
18 | }
19 |
20 | void test_nif(std::string nif)
21 | {
22 | void* lib = dlopen(nif.c_str(), RTLD_NOW);
23 | if (!lib) {
24 | printf("Failed opening %s: %s\n", nif.c_str(), dlerror());
25 | return;
26 | }
27 |
28 | void* sym = dlsym(lib, "nif_init");
29 | printf("%s: nif_init() => %lx\n", nif.c_str(), sym);
30 |
31 | // dlclose(lib);
32 | }
33 |
34 | #define ERROR(x) { printf(x); return x; }
35 |
36 | const char* startErlang(std::string root_dir, std::string log_dir)
37 | {
38 | ensure_slash(root_dir);
39 | ensure_slash(log_dir);
40 | log_file = log_dir + "elixir.log";
41 |
42 | std::string boot_file = root_dir + "releases/start_erl.data";
43 | FILE *fp = fopen(boot_file.c_str(), "rb");
44 | if (!fp) ERROR("Could not locate start_erl.data");
45 |
46 | char line_buffer[128];
47 | size_t read = fread(line_buffer, 1, sizeof(line_buffer) - 1, fp);
48 | fclose(fp);
49 | line_buffer[read] = 0;
50 |
51 | char* erts_version = strtok(line_buffer, " ");
52 | if (!erts_version) ERROR("Could not identify erts version in start_erl.data file");
53 |
54 | char* app_version = strtok(0, " ");
55 | if (!app_version) ERROR("Could not idenfity app version in start_erl.data file");
56 |
57 |
58 | std::string bin_dir = getenv("BINDIR");
59 | // keeping it static to keep the environment variable alive
60 | char *path = getenv("PATH");
61 | // keeping it static to keep the environment variable alive
62 | static std::string env_path = std::string("PATH=").append(path).append(":").append(bin_dir);
63 |
64 | chdir(root_dir.c_str());
65 | putenv((char *)env_path.c_str());
66 |
67 | start_logger();
68 |
69 | std::string liberlang = getenv("LIBERLANG");
70 |
71 | // RTLD_GLOBAL does not work on android
72 | // https://android-ndk.narkive.com/iNWj05IV/weak-symbol-linking-when-loading-dynamic-libraries
73 | // https://android.googlesource.com/platform/bionic/+/30b17e32f0b403a97cef7c4d1fcab471fa316340/linker/linker_namespaces.cpp#100
74 | void* lib = dlopen(liberlang.c_str(), RTLD_NOW | RTLD_GLOBAL);
75 | if (!lib) ERROR("Failed opening liberlang.so\n")
76 |
77 | // std::string nif = root_dir + "lib/exqlite-0.5.1/priv/sqlite3_nif.so";
78 | // test_nif(nif);
79 |
80 | startfun = (void (*)(int, char**)) dlsym(lib, "erl_start");
81 | if (!startfun) ERROR("Failed loading erlang startfun\n")
82 |
83 | std::string config_path = root_dir + "releases/" + app_version + "/sys";
84 | std::string boot_path = root_dir + "releases/" + app_version + "/start";
85 | std::string lib_path = root_dir + "lib";
86 | std::string home_dir;
87 | if (const char* h = getenv("HOME")) {
88 | home_dir = h;
89 | } else {
90 | home_dir = root_dir + "home";
91 | }
92 | std::string update_dir;
93 | if (const char *u = getenv("UPDATE_DIR")) {
94 | update_dir = u;
95 | } else {
96 | update_dir = root_dir + "update";
97 | }
98 |
99 | const char *args[] = {
100 | "test_main",
101 | "-sbwt",
102 | "none",
103 | // Reduced literal super carrier to 10mb because of spurious error message on 9th gen iPads
104 | // "erts_mmap: Failed to create super carrier of size 1024 MB"
105 | "-MIscs",
106 | "10",
107 | "--",
108 | // "-init_debug",
109 | "-root",
110 | root_dir.c_str(),
111 | "-progname",
112 | "erl",
113 | "--",
114 | "-home",
115 | home_dir.c_str(), // Was without slash / at the end
116 | "--",
117 | "-kernel",
118 | "shell_history",
119 | "enabled",
120 | "--",
121 | // "-heart",
122 | "-pa",
123 | update_dir.c_str(),
124 | "-start_epmd",
125 | "false",
126 | //"-kernel",
127 | //"inet_dist_use_interface",
128 | //"{127,0,0,1}",
129 | "-elixir",
130 | "ansi_enabled",
131 | "true",
132 | "-noshell",
133 | "-s",
134 | "elixir",
135 | "start_cli",
136 | "-mode",
137 | "interactive",
138 | "-config",
139 | config_path.c_str(),
140 | "-boot",
141 | boot_path.c_str(),
142 | "-bindir",
143 | bin_dir.c_str(),
144 | "-boot_var",
145 | "RELEASE_LIB",
146 | lib_path.c_str(),
147 | "--",
148 | "--",
149 | "-extra",
150 | "--no-halt",
151 | };
152 |
153 | // std::thread erlang(run_erlang);
154 | // erlang.detach();
155 | startfun(sizeof(args) / sizeof(args[0]), (char **)args);
156 | return "ok";
157 | }
158 |
159 | extern "C" JNIEXPORT jstring JNICALL
160 | Java_io_elixirdesktop_example_Bridge_startErlang(
161 | JNIEnv* env,
162 | jobject /* this */, jstring release_dir, jstring log_dir) {
163 |
164 | std::string home = jstring2string(env, release_dir);
165 | std::string logs = jstring2string(env, log_dir);
166 | return env->NewStringUTF(startErlang(home, logs));
167 | }
168 |
169 | std::string jstring2string(JNIEnv *env, jstring jStr) {
170 | if (!jStr)
171 | return "";
172 |
173 | const jclass stringClass = env->GetObjectClass(jStr);
174 | const jmethodID getBytes = env->GetMethodID(stringClass, "getBytes", "(Ljava/lang/String;)[B");
175 | const jbyteArray stringJbytes = (jbyteArray) env->CallObjectMethod(jStr, getBytes, env->NewStringUTF("UTF-8"));
176 |
177 | size_t length = (size_t) env->GetArrayLength(stringJbytes);
178 | jbyte* pBytes = env->GetByteArrayElements(stringJbytes, NULL);
179 |
180 | std::string ret = std::string((char *)pBytes, length);
181 | env->ReleaseByteArrayElements(stringJbytes, pBytes, JNI_ABORT);
182 |
183 | env->DeleteLocalRef(stringJbytes);
184 | env->DeleteLocalRef(stringClass);
185 | return ret;
186 | }
187 |
188 |
189 | #include
190 |
191 | static int pfd[2];
192 | static const char *tag = "BEAM";
193 |
194 | int start_logger()
195 | {
196 | /* make stdout line-buffered and stderr unbuffered */
197 | setvbuf(stdout, 0, _IOLBF, 0);
198 | setvbuf(stderr, 0, _IONBF, 0);
199 |
200 | /* create the pipe and redirect stdout and stderr */
201 | pipe(pfd);
202 | dup2(pfd[1], 1);
203 | dup2(pfd[1], 2);
204 |
205 | std::thread logger(logger_func);
206 | logger.detach();
207 | return 0;
208 | }
209 |
210 | static void logger_func()
211 | {
212 | static FILE* fp = 0;
213 | //if (!fp) fp = fopen("erlang.log", "wb");
214 | if (!fp) fp = fopen(log_file.c_str(), "wb");
215 | ssize_t rdsz;
216 | char buf[128];
217 | while((rdsz = read(pfd[0], buf, sizeof buf - 1)) > 0) {
218 | if (fp) {
219 | fwrite(buf, rdsz, 1, fp);
220 | fflush(fp);
221 | }
222 | if(buf[rdsz - 1] == '\n') --rdsz;
223 | buf[rdsz] = 0; /* add null-terminator */
224 | __android_log_write(ANDROID_LOG_DEBUG, tag, buf);
225 | }
226 | }
227 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-playstore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/app/src/main/ic_launcher-playstore.png
--------------------------------------------------------------------------------
/app/src/main/java/io/elixirdesktop/example/Bridge.kt:
--------------------------------------------------------------------------------
1 | package io.elixirdesktop.example
2 |
3 | import android.annotation.SuppressLint
4 | import android.app.PendingIntent
5 | import android.content.ActivityNotFoundException
6 | import android.content.Context
7 | import android.content.Intent
8 | import android.net.Uri
9 | import android.os.Build
10 | import android.os.Message
11 | import android.system.Os
12 | import android.util.Log
13 | import android.webkit.WebChromeClient
14 | import android.webkit.WebSettings
15 | import android.webkit.WebView
16 | import android.webkit.WebViewClient
17 | import androidx.core.app.NotificationCompat
18 | import androidx.core.app.NotificationManagerCompat
19 | import androidx.core.content.ContextCompat
20 | import androidx.core.content.FileProvider
21 | import org.json.JSONArray
22 | import org.json.JSONObject
23 | import java.net.ServerSocket
24 | import kotlin.concurrent.thread
25 | import java.io.*
26 | import java.util.*
27 | import java.util.concurrent.ConcurrentHashMap
28 | import java.util.concurrent.locks.ReentrantLock
29 | import java.util.zip.ZipInputStream
30 |
31 |
32 | class Bridge(private val applicationContext : Context, private var webview : WebView) {
33 | private val server = ServerSocket(0)
34 | private var lastURL = String()
35 | private val assets = applicationContext.assets.list("")
36 | private var writers = ArrayList()
37 | private val writerLock = ReentrantLock()
38 |
39 | class Notification {
40 | var title = String()
41 | var message = String()
42 | var callback = 0uL
43 | var pid = JSONObject()
44 | var obj = JSONArray()
45 | }
46 |
47 | private val notifications = ConcurrentHashMap()
48 |
49 | init {
50 | Os.setenv("ELIXIR_DESKTOP_OS", "android", false)
51 | Os.setenv("BRIDGE_PORT", server.localPort.toString(), false)
52 | // not really the home directory, but persistent between app upgrades
53 | Os.setenv("HOME", applicationContext.filesDir.absolutePath, false)
54 |
55 | setWebView(webview)
56 |
57 | thread(start = true) {
58 | while (true) {
59 | val socket = server.accept()
60 | socket.tcpNoDelay = true
61 | println("Client connected: ${socket.inetAddress.hostAddress}")
62 | thread {
63 | val reader = DataInputStream(BufferedInputStream((socket.getInputStream())))
64 | val writer = DataOutputStream(socket.getOutputStream())
65 | writerLock.lock()
66 | writers.add(writer)
67 | writerLock.unlock()
68 | try {
69 | handle(reader, writer)
70 | } catch(e : EOFException) {
71 | println("Client disconnected: ${socket.inetAddress.hostAddress}")
72 | socket.close()
73 | }
74 | writerLock.lock()
75 | writers.remove(writer)
76 | writerLock.unlock()
77 | }
78 | }
79 | }
80 |
81 | // The possible values are armeabi, armeabi-v7a, arm64-v8a, x86, x86_64, mips, mips64.
82 | var prefix = ""
83 | for (abi in Build.SUPPORTED_ABIS) {
84 | when (abi) {
85 | "arm64-v8a", "armeabi-v7a", "x86_64" -> {
86 | prefix = abi
87 | break
88 | }
89 | "armeabi" -> {
90 | prefix = "armeabi-v7a"
91 | break
92 | }
93 | else -> continue
94 | }
95 | }
96 |
97 | if (prefix == "") {
98 | throw Exception("Could not find any supported ABI")
99 | }
100 |
101 | val runtime = "$prefix-runtime"
102 | Log.d("RUNTIME", runtime)
103 |
104 | thread(start = true) {
105 | val packageInfo = applicationContext.packageManager
106 | .getPackageInfo(applicationContext.packageName, 0)
107 |
108 | val nativeDir = packageInfo.applicationInfo.nativeLibraryDir
109 | val lastUpdateTime = (packageInfo.lastUpdateTime / 1000).toString()
110 |
111 | val releaseDir = applicationContext.filesDir.absolutePath + "/app"
112 | val doneFile = File("$releaseDir/done")
113 |
114 | // Delete old build if new is installed
115 | if (doneFile.exists() && doneFile.readText() != lastUpdateTime) {
116 | File(releaseDir).deleteRecursively()
117 | }
118 |
119 | // Cleaning deprecated build-xxx folders
120 | for (file in applicationContext.filesDir.list()!!) {
121 | if (file.startsWith("build-")) {
122 | File(applicationContext.filesDir.absolutePath + "/" + file).deleteRecursively()
123 | }
124 | }
125 |
126 | val binDir = "$releaseDir/bin"
127 |
128 | Os.setenv("UPDATE_DIR", "$releaseDir/update/", false)
129 | Os.setenv("BINDIR", binDir, false)
130 | Os.setenv("LIBERLANG", "$nativeDir/liberlang.so", false)
131 |
132 | if (!doneFile.exists()) {
133 | File(binDir).mkdirs()
134 | if (unpackAsset(releaseDir, "app") &&
135 | unpackAsset(releaseDir, runtime)) {
136 | for (lib in File("$releaseDir/lib").list()!!) {
137 | val parts = lib.split("-")
138 | val name = parts[0]
139 |
140 | val nif = "$prefix-nif-$name"
141 | unpackAsset("$releaseDir/lib/$lib/priv", nif)
142 | }
143 |
144 | doneFile.writeText(lastUpdateTime)
145 | }
146 | }
147 |
148 | if (!doneFile.exists()) {
149 | Log.e("ERROR", "Failed to extract runtime")
150 | throw Exception("Failed to extract runtime")
151 | }
152 |
153 | // Creating symlinks for binaries
154 | // Re-creating even on relaunch because we can't
155 | // be sure of the native libs directory
156 | // https://github.com/JeromeDeBretagne/erlanglauncher/issues/2
157 | for (file in File(nativeDir).list()!!) {
158 | if (file.startsWith("lib__")) {
159 | var name = File(file).name
160 | name = name.substring(5, name.length - 3)
161 | Log.d("BIN", "$nativeDir/$file -> $binDir/$name")
162 | File("$binDir/$name").delete()
163 | Os.symlink("$nativeDir/$file", "$binDir/$name")
164 | }
165 | }
166 |
167 | var logdir = applicationContext.getExternalFilesDir("")?.path
168 | if (logdir == null) {
169 | logdir = applicationContext.filesDir.absolutePath
170 | }
171 | Os.setenv("LOG_DIR", logdir!!, true)
172 | Log.d("ERLANG", "Starting beam...")
173 | val ret = startErlang(releaseDir, logdir)
174 | Log.d("ERLANG", ret)
175 | if (ret != "ok") {
176 | throw Exception(ret)
177 | }
178 | }
179 | }
180 |
181 |
182 | private fun unpackAsset(releaseDir: String, assetName: String): Boolean {
183 | assets!!
184 | //if (assets.contains("$assetName.zip.xz")) {
185 | // val input = BufferedInputStream(applicationContext.assets.open("$assetName.zip.xz"))
186 | // return unpackZip(releaseDir, XZInputStream(input))
187 | //}
188 | if (assets.contains("$assetName.zip")) {
189 | val input = BufferedInputStream(applicationContext.assets.open("$assetName.zip"))
190 | return unpackZip(releaseDir, input)
191 | }
192 | return false
193 | }
194 |
195 | private fun unpackZip(releaseDir: String, inputStream: InputStream): Boolean {
196 | Log.d("RELEASEDIR", releaseDir)
197 | File(releaseDir).mkdirs()
198 | try
199 | {
200 | val zis = ZipInputStream(BufferedInputStream(inputStream))
201 | val buffer = ByteArray(1024)
202 |
203 | var ze = zis.nextEntry
204 | while (ze != null)
205 | {
206 | val filename = ze.name
207 |
208 | // Need to create directories if not exists, or
209 | // it will generate an Exception...
210 | val fullpath = "$releaseDir/$filename"
211 | if (ze.isDirectory) {
212 | Log.d("DIR", fullpath)
213 | File(fullpath).mkdirs()
214 | zis.closeEntry()
215 | ze = zis.nextEntry
216 | continue
217 | }
218 |
219 | Log.d("FILE", fullpath)
220 | val fout = FileOutputStream(fullpath)
221 | var count = zis.read(buffer)
222 | while (count != -1) {
223 | fout.write(buffer, 0, count)
224 | count = zis.read(buffer)
225 | }
226 |
227 | fout.close()
228 | zis.closeEntry()
229 | ze = zis.nextEntry
230 | }
231 |
232 | zis.close()
233 | }
234 | catch(e: IOException)
235 | {
236 | e.printStackTrace()
237 | return false
238 | }
239 |
240 | return true
241 | }
242 |
243 | @SuppressLint("SetJavaScriptEnabled")
244 | fun setWebView(_webview: WebView) {
245 | webview = _webview
246 | webview.webChromeClient = object : WebChromeClient() {
247 | override fun onCreateWindow(
248 | view: WebView?,
249 | isDialog: Boolean,
250 | isUserGesture: Boolean,
251 | resultMsg: Message?
252 | ): Boolean {
253 | val newWebView = WebView(applicationContext)
254 | view?.addView(newWebView)
255 | val transport = resultMsg?.obj as WebView.WebViewTransport
256 |
257 | transport.webView = newWebView
258 | resultMsg.sendToTarget()
259 |
260 | newWebView.webViewClient = object : WebViewClient() {
261 | @Deprecated("Deprecated in Java")
262 | override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
263 | val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
264 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
265 | applicationContext.startActivity(intent)
266 | return true
267 | }
268 | }
269 | return true
270 | }
271 | }
272 |
273 | val settings = webview.settings
274 | settings.setSupportMultipleWindows(true)
275 | settings.javaScriptEnabled = true
276 | settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL
277 | settings.useWideViewPort = true
278 | // enable Web Storage: localStorage, sessionStorage
279 | settings.domStorageEnabled = true
280 | // webview.webViewClient = WebViewClient()
281 | if (lastURL.isNotBlank()) {
282 | webview.post { webview.loadUrl(lastURL) }
283 | }
284 | }
285 |
286 |
287 | fun getLocalPort(): Int {
288 | return server.localPort
289 | }
290 |
291 | private fun handle(reader : DataInputStream, writer : DataOutputStream) {
292 | val ref = ByteArray(8)
293 |
294 | while (true) {
295 | val length = reader.readInt()
296 | reader.readFully(ref)
297 | val data = ByteArray(length - ref.size)
298 | reader.readFully(data)
299 |
300 | val json = JSONArray(String(data))
301 |
302 | val module = json.getString(0)
303 | val method = json.getString(1)
304 | val args = json.getJSONArray(2)
305 |
306 | if (method == ":loadURL") {
307 | lastURL = args.getString(1)
308 | webview.post { webview.loadUrl(lastURL) }
309 |
310 | }
311 | if (method == ":launchDefaultBrowser") {
312 | val uri = Uri.parse(args.getString(0))
313 | if (uri.scheme == "http") {
314 | val browserIntent = Intent(Intent.ACTION_VIEW, uri)
315 | applicationContext.startActivity(browserIntent)
316 | } else if (uri.scheme == "file") {
317 | openFile(uri.path)
318 | }
319 | }
320 |
321 | var response = ref
322 | response += when (method) {
323 | ":getOsDescription" -> {
324 | val info = "Android ${Build.DEVICE} ${Build.BRAND} ${Build.VERSION.BASE_OS} ${
325 | Build.SUPPORTED_ABIS.joinToString(",")
326 | }"
327 | stringToList(info).toByteArray()
328 | }
329 | ":getCanonicalName" -> {
330 | val primaryLocale = getCurrentLocale(applicationContext)
331 | val locale = "${primaryLocale.language}_${primaryLocale.country}"
332 | stringToList(locale).toByteArray()
333 |
334 | }
335 | else -> {
336 | "use_mock".toByteArray()
337 | }
338 | }
339 | writerLock.lock()
340 | writer.writeInt(response.size)
341 | writer.write(response)
342 | writerLock.unlock() }
343 | }
344 |
345 | fun sendMessage(message : ByteArray) {
346 | thread {
347 | writerLock.lock()
348 | while (writers.isEmpty()) {
349 | writerLock.unlock()
350 | Thread.sleep(100)
351 | writerLock.lock()
352 | }
353 | for (writer in writers) {
354 | writer.writeInt(message.size)
355 | writer.write(message)
356 | }
357 | writerLock.unlock()
358 | }
359 | }
360 |
361 | private fun getCurrentLocale(context: Context): Locale {
362 | return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
363 | context.resources.configuration.locales[0]
364 | } else {
365 | context.resources.configuration.locale
366 | }
367 | }
368 |
369 | private fun openFile(filename: String?) {
370 | // Get URI and MIME type of file
371 | val file = File(filename)
372 | val uri =
373 | FileProvider.getUriForFile(applicationContext, applicationContext.packageName + ".fileprovider", File(filename))
374 |
375 | val mime: String? = if (file.isDirectory) {
376 | "resource/folder"
377 | } else {
378 | applicationContext.contentResolver.getType(uri)
379 | }
380 |
381 | // Open file with user selected app
382 | var intent = Intent()
383 | intent.action = Intent.ACTION_VIEW
384 | intent.setDataAndType(uri, mime)
385 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
386 | intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
387 | intent = Intent.createChooser(intent, "")
388 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
389 | try {
390 | applicationContext.startActivity(intent)
391 | } catch (e : ActivityNotFoundException) {
392 | Log.d("Exception", e.toString())
393 | }
394 | }
395 |
396 | private fun stringToList(str : String): String {
397 | val numbers = str.toByteArray().map { it.toInt().toString() }
398 | return "[${numbers.joinToString(",")}]"
399 | }
400 |
401 | private fun listToString(raw : JSONArray): String {
402 | var title = ""
403 | for (i in 0 until raw.length()) {
404 | title += raw.getInt(i).toChar()
405 | }
406 | return title
407 | }
408 |
409 | private fun getKeyword(keywords: JSONArray, searchKey : String) : Any {
410 | for (i in 0 until keywords.length()) {
411 | val tupleValues = keywords.getJSONObject(i).getJSONArray(":value")
412 | val key = tupleValues.getString(0)
413 | if (key == searchKey) return tupleValues.get(1)
414 | }
415 | return ""
416 | }
417 |
418 | /**
419 | * A native method that is implemented by the 'native-lib' native library,
420 | * which is packaged with this application.
421 | */
422 | private external fun startErlang(releaseDir: String, logdir: String): String
423 |
424 | companion object {
425 | // Used to load the 'native-lib' library on application startup.
426 | init {
427 | System.loadLibrary("native-lib")
428 | }
429 | }
430 | }
431 |
--------------------------------------------------------------------------------
/app/src/main/java/io/elixirdesktop/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package io.elixirdesktop.example
2 |
3 | import android.app.Activity
4 | import android.os.Bundle
5 | import android.system.Os
6 | import android.view.KeyEvent
7 | import android.view.View
8 | import io.elixirdesktop.example.databinding.ActivityMainBinding
9 | import java.io.*
10 | import java.util.*
11 | import android.webkit.WebView
12 |
13 | import android.webkit.WebViewClient
14 |
15 |
16 |
17 |
18 | class MainActivity : Activity() {
19 | private lateinit var binding: ActivityMainBinding
20 |
21 | override fun onCreate(savedInstanceState: Bundle?) {
22 | super.onCreate(savedInstanceState)
23 |
24 | binding = ActivityMainBinding.inflate(layoutInflater)
25 | setContentView(binding.root)
26 | binding.browser.webViewClient = object : WebViewClient() {
27 | override fun onPageFinished(view: WebView, url: String) {
28 | if (binding.browser.visibility != View.VISIBLE) {
29 | binding.browser.visibility = View.VISIBLE
30 | binding.splash.visibility = View.GONE
31 | reportFullyDrawn()
32 | }
33 | }
34 | }
35 |
36 | if (bridge != null) {
37 | // This happens on re-creation of the activity e.g. after rotating the screen
38 | bridge!!.setWebView(binding.browser)
39 | } else {
40 | // This happens only on the first time when starting the app
41 | bridge = Bridge(applicationContext, binding.browser)
42 | }
43 | }
44 |
45 | override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
46 | if (event.action == KeyEvent.ACTION_DOWN) {
47 | when (keyCode) {
48 | KeyEvent.KEYCODE_BACK -> {
49 | if (binding.browser.canGoBack()) {
50 | binding.browser.goBack()
51 | } else {
52 | finish()
53 | }
54 | return true
55 | }
56 | }
57 | }
58 | return super.onKeyDown(keyCode, event)
59 | }
60 |
61 | companion object {
62 | var bridge: Bridge? = null
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
18 |
19 |
24 |
25 |
26 |
27 |
28 |
29 |
37 |
44 |
45 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF2F243A
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | TodoApp
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/provider_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | ext.kotlin_version = "1.9.0"
4 | repositories {
5 | google()
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:8.3.0'
10 | classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | mavenCentral()
21 | jcenter() // Warning: this repository is going to shut down soon
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | android.defaults.buildfeatures.buildconfig=true
21 | android.nonTransitiveRClass=false
22 | android.nonFinalResIds=false
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Jun 22 14:56:47 CEST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/icon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elixir-desktop/android-example-app/aadf526691327271ad8c5d1b2328518b2094b536/icon.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = "TodoApp"
2 | include ':app'
3 |
--------------------------------------------------------------------------------