Skip to content

Commit bdc163e

Browse files
Merge pull request #1 from Gunock/android-app-modernization
Reimplemented android app using Kotlin and more modern approach
2 parents 9f16748 + 365ab6c commit bdc163e

File tree

71 files changed

+1596
-4517
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1596
-4517
lines changed

android/app/build.gradle

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,63 @@
11
apply plugin: 'com.android.application'
2-
apply plugin: 'de.undercouch.download'
2+
apply plugin: 'kotlin-android'
33

44
android {
5-
compileSdkVersion 28
5+
compileSdkVersion 30
66
buildToolsVersion '28.0.3'
7+
78
defaultConfig {
8-
applicationId "org.tensorflow.lite.examples.detection"
9-
minSdkVersion 21
10-
targetSdkVersion 28
9+
applicationId "org.tensorflow.lite.examples"
10+
minSdkVersion 23
11+
targetSdkVersion 30
1112
versionCode 1
1213
versionName "1.0"
13-
14-
// ndk {
15-
// abiFilters 'armeabi-v7a', 'arm64-v8a'
16-
// }
1714
}
15+
1816
buildTypes {
1917
release {
2018
minifyEnabled false
2119
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2220
}
2321
}
24-
aaptOptions {
25-
noCompress "tflite"
22+
23+
buildFeatures {
24+
viewBinding true
2625
}
26+
2727
compileOptions {
2828
sourceCompatibility = '1.8'
2929
targetCompatibility = '1.8'
3030
}
31+
3132
lintOptions {
3233
abortOnError false
3334
}
3435
}
3536

36-
// import DownloadModels task
37-
project.ext.ASSET_DIR = projectDir.toString() + '/src/main/assets'
38-
project.ext.TMP_DIR = project.buildDir.toString() + '/downloads'
37+
dependencies {
38+
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
39+
implementation project(':detector')
3940

40-
// Download default models; if you wish to use your own models then
41-
// place them in the "assets" directory and comment out this line.
42-
//apply from: "download_model.gradle"
41+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3'
4342

44-
apply from: 'download_model.gradle'
43+
implementation "androidx.camera:camera-camera2:1.0.0"
44+
implementation "androidx.camera:camera-lifecycle:1.0.0"
45+
implementation "androidx.camera:camera-view:1.0.0-alpha24"
4546

46-
dependencies {
47-
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
48-
implementation 'androidx.appcompat:appcompat:1.1.0'
47+
implementation 'androidx.appcompat:appcompat:1.2.0'
4948
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
50-
implementation 'com.google.android.material:material:1.1.0'
51-
// implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
52-
// implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly'
53-
implementation 'org.tensorflow:tensorflow-lite:2.2.0'
54-
implementation 'org.tensorflow:tensorflow-lite-gpu:2.2.0'
55-
// implementation 'org.tensorflow:tensorflow-lite:0.0.0-gpu-experimental'
56-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
49+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
50+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
51+
52+
implementation 'com.google.android.material:material:1.3.0'
5753
implementation 'com.google.code.gson:gson:2.8.6'
58-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
59-
androidTestImplementation 'com.android.support.test:rules:1.0.2'
60-
androidTestImplementation 'com.google.truth:truth:1.0.1'
54+
55+
// Uncomment if you want to enable memory leak detection
56+
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
57+
58+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
59+
// testImplementation "androidx.test:runner:1.3.0"
60+
// testImplementation "androidx.test.ext:junit:1.1.2"
61+
androidTestImplementation 'com.google.truth:truth:1.1.2'
62+
6163
}

android/app/detector/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

android/app/detector/build.gradle

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'kotlin-android'
4+
}
5+
6+
android {
7+
compileSdkVersion 30
8+
buildToolsVersion "30.0.3"
9+
10+
defaultConfig {
11+
minSdkVersion 23
12+
targetSdkVersion 30
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
consumerProguardFiles "consumer-rules.pro"
18+
}
19+
20+
buildTypes {
21+
release {
22+
minifyEnabled false
23+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24+
}
25+
}
26+
compileOptions {
27+
sourceCompatibility JavaVersion.VERSION_1_8
28+
targetCompatibility JavaVersion.VERSION_1_8
29+
}
30+
kotlinOptions {
31+
jvmTarget = '1.8'
32+
}
33+
}
34+
35+
dependencies {
36+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
37+
38+
implementation 'androidx.core:core-ktx:1.5.0'
39+
implementation 'androidx.appcompat:appcompat:1.2.0'
40+
41+
implementation 'com.google.android.material:material:1.3.0'
42+
43+
testImplementation 'junit:junit:4.13.2'
44+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
45+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
46+
}

android/app/detector/consumer-rules.pro

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.tensorflow.lite.examples.detector
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("org.tensorflow.lite.examples.detector.test", appContext.packageName)
23+
}
24+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="org.tensorflow.lite.examples.detector">
3+
4+
</manifest>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.tensorflow.lite.examples.detector
2+
3+
import org.junit.Test
4+
5+
import org.junit.Assert.*
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* See [testing documentation](http://d.android.com/tools/testing).
11+
*/
12+
class ExampleUnitTest {
13+
@Test
14+
fun addition_isCorrect() {
15+
assertEquals(4, 2 + 2)
16+
}
17+
}

android/app/download_model.gradle

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="org.tensorflow.lite.examples.detection">
2+
<manifest package="org.tensorflow.lite.examples.detector">
43
<uses-sdk />
54
</manifest>

0 commit comments

Comments
 (0)