Skip to content

Commit dc2d0b5

Browse files
committed
Add android client for tensorflow models
1 parent 1bd3899 commit dc2d0b5

37 files changed

Lines changed: 845 additions & 2 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ Following are the supported features.
1212
- [x] [TensorFlow serving](./cpp_predict_server/)
1313
- [x] [Python gRPC server](./python_predict_server/)
1414
- [x] [Python HTTP server](./http_service/)
15-
- [ ] Predict Client
15+
- [x] Predict Client
1616
- [x] [Python gPRC client](./python_predict_client/)
1717
- [x] [Java gPRC client](./java_predict_client/)
1818
- [x] [Scala gPRC client](./java_predict_client/)
1919
- [x] [Golang gRPC client](./golang_predict_client/)
2020
- [x] [C++ gRPC client](./cpp_predict_client/)
2121
- [x] [Spark client](./java_predict_client/)
22-
- [ ] Android client
22+
- [x] [Android client](./android_client/)
2323
- [x] Use Cases
2424
- [x] Train model
2525
- [x] Export model

android_client/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

android_client/app/.gitignore

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

android_client/app/CMakeLists.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.4.1)
7+
8+
# Creates and names a library, sets it as either STATIC
9+
# or SHARED, and provides the relative paths to its source code.
10+
# You can define multiple libraries, and CMake builds them for you.
11+
# Gradle automatically packages shared libraries with your APK.
12+
13+
add_library( # Sets the name of the library.
14+
native-lib
15+
16+
# Sets the library as a shared library.
17+
SHARED
18+
19+
# Provides a relative path to your source file(s).
20+
src/main/cpp/native-lib.cpp )
21+
22+
# Searches for a specified prebuilt library and stores the path as a
23+
# variable. Because CMake includes system libraries in the search path by
24+
# default, you only need to specify the name of the public NDK library
25+
# you want to add. CMake verifies that the library exists before
26+
# completing its build.
27+
28+
find_library( # Sets the name of the path variable.
29+
log-lib
30+
31+
# Specifies the name of the NDK library that
32+
# you want CMake to locate.
33+
log )
34+
35+
# Specifies libraries CMake should link to your target library. You
36+
# can link multiple libraries, such as libraries you define in this
37+
# build script, prebuilt third-party libraries, or system libraries.
38+
39+
target_link_libraries( # Specifies the target library.
40+
native-lib
41+
42+
# Links the target library to the log library
43+
# included in the NDK.
44+
${log-lib} )

android_client/app/build.gradle

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 26
5+
defaultConfig {
6+
applicationId "com.tobe.androidclient"
7+
minSdkVersion 23
8+
targetSdkVersion 26
9+
versionCode 1
10+
versionName "1.0"
11+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
externalNativeBuild {
13+
cmake {
14+
cppFlags ""
15+
}
16+
}
17+
}
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
externalNativeBuild {
25+
cmake {
26+
path "CMakeLists.txt"
27+
}
28+
}
29+
}
30+
31+
dependencies {
32+
implementation fileTree(dir: 'libs', include: ['*.jar'])
33+
implementation 'com.android.support:appcompat-v7:26.1.0'
34+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
35+
testImplementation 'junit:junit:4.12'
36+
androidTestImplementation 'com.android.support.test:runner:1.0.1'
37+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
38+
39+
40+
compile 'org.tensorflow:tensorflow-android:+'
41+
}
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.tobe.androidclient;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.tobe.androidclient", appContext.getPackageName());
25+
}
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.tobe.androidclient">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <jni.h>
2+
#include <string>
3+
4+
extern "C"
5+
JNIEXPORT jstring
6+
7+
JNICALL
8+
Java_com_tobe_androidclient_MainActivity_stringFromJNI(
9+
JNIEnv *env,
10+
jobject /* this */) {
11+
12+
13+
std::string hello = "Hello from C++";
14+
return env->NewStringUTF(hello.c_str());
15+
16+
17+
}
18+
19+

0 commit comments

Comments
 (0)