Skip to content

Commit 2e2af8e

Browse files
committed
add android app files
1 parent 779733a commit 2e2af8e

38 files changed

+874
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
plugins {
2+
id("com.android.application")
3+
id("org.jetbrains.kotlin.android")
4+
}
5+
6+
android {
7+
namespace = "com.onnxruntime.example.modeltester"
8+
compileSdk = 33
9+
10+
defaultConfig {
11+
applicationId = "com.onnxruntime.example.modeltester"
12+
minSdk = 24
13+
targetSdk = 33
14+
versionCode = 1
15+
versionName = "1.0"
16+
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18+
}
19+
20+
buildTypes {
21+
release {
22+
isMinifyEnabled = false
23+
proguardFiles(
24+
getDefaultProguardFile("proguard-android-optimize.txt"),
25+
"proguard-rules.pro"
26+
)
27+
}
28+
}
29+
compileOptions {
30+
sourceCompatibility = JavaVersion.VERSION_1_8
31+
targetCompatibility = JavaVersion.VERSION_1_8
32+
}
33+
kotlinOptions {
34+
jvmTarget = "1.8"
35+
}
36+
externalNativeBuild {
37+
cmake {
38+
path = file("src/main/cpp/CMakeLists.txt")
39+
version = "3.22.1"
40+
}
41+
}
42+
buildFeatures {
43+
viewBinding = true
44+
}
45+
}
46+
47+
dependencies {
48+
49+
implementation("androidx.core:core-ktx:1.9.0")
50+
implementation("androidx.appcompat:appcompat:1.7.0")
51+
implementation("com.google.android.material:material:1.12.0")
52+
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
53+
testImplementation("junit:junit:4.13.2")
54+
androidTestImplementation("androidx.test.ext:junit:1.2.1")
55+
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
56+
}
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.onnxruntime.example.modeltester
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("com.onnxruntime.example.modeltester", appContext.packageName)
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.ModelTester"
14+
tools:targetApi="31">
15+
<activity
16+
android:name=".MainActivity"
17+
android:exported="true">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</manifest>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
# For more examples on how to use CMake, see https://github.com/android/ndk-samples.
4+
5+
# Sets the minimum CMake version required for this project.
6+
cmake_minimum_required(VERSION 3.22.1)
7+
8+
# Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
9+
# Since this is the top level CMakeLists.txt, the project name is also accessible
10+
# with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
11+
# build script scope).
12+
project("modeltester")
13+
14+
# Creates and names a library, sets it as either STATIC
15+
# or SHARED, and provides the relative paths to its source code.
16+
# You can define multiple libraries, and CMake builds them for you.
17+
# Gradle automatically packages shared libraries with your APK.
18+
#
19+
# In this top level CMakeLists.txt, ${CMAKE_PROJECT_NAME} is used to define
20+
# the target library name; in the sub-module's CMakeLists.txt, ${PROJECT_NAME}
21+
# is preferred for the same purpose.
22+
#
23+
# In order to load a library into your app from Java/Kotlin, you must call
24+
# System.loadLibrary() and pass the name of the library defined here;
25+
# for GameActivity/NativeActivity derived applications, the same library name must be
26+
# used in the AndroidManifest.xml file.
27+
add_library(${CMAKE_PROJECT_NAME} SHARED
28+
# List C/C++ source files with relative paths to this CMakeLists.txt.
29+
native-lib.cpp)
30+
31+
# Specifies libraries CMake should link to your target library. You
32+
# can link libraries from various origins, such as libraries defined in this
33+
# build script, prebuilt third-party libraries, or Android system libraries.
34+
target_link_libraries(${CMAKE_PROJECT_NAME}
35+
# List libraries link to the target library
36+
android
37+
log)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <jni.h>
2+
#include <string>
3+
4+
extern "C" JNIEXPORT jstring JNICALL
5+
Java_com_onnxruntime_example_modeltester_MainActivity_stringFromJNI(
6+
JNIEnv* env,
7+
jobject /* this */) {
8+
std::string hello = "Hello from C++";
9+
return env->NewStringUTF(hello.c_str());
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.onnxruntime.example.modeltester
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
import android.widget.TextView
6+
import com.onnxruntime.example.modeltester.databinding.ActivityMainBinding
7+
8+
class MainActivity : AppCompatActivity() {
9+
10+
private lateinit var binding: ActivityMainBinding
11+
12+
override fun onCreate(savedInstanceState: Bundle?) {
13+
super.onCreate(savedInstanceState)
14+
15+
binding = ActivityMainBinding.inflate(layoutInflater)
16+
setContentView(binding.root)
17+
18+
// Example of a call to a native method
19+
binding.sampleText.text = stringFromJNI()
20+
}
21+
22+
/**
23+
* A native method that is implemented by the 'modeltester' native library,
24+
* which is packaged with this application.
25+
*/
26+
external fun stringFromJNI(): String
27+
28+
companion object {
29+
// Used to load the 'modeltester' library on application startup.
30+
init {
31+
System.loadLibrary("modeltester")
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)