Skip to content

Commit 885fb69

Browse files
Ma-DanMa-Dan
andauthored
Add android runtime. (#110)
* Add android runtime. * Remove fst files in assets. --------- Co-authored-by: Ma-Dan <dan@madandeMacBook-Air.local>
1 parent f60d9e4 commit 885fb69

46 files changed

Lines changed: 1088 additions & 36 deletions

Some content is hidden

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

runtime/android/.gitignore

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

runtime/android/app/.gitignore

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

runtime/android/app/build.gradle

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
repositories {
6+
jcenter()
7+
maven {
8+
url "https://oss.sonatype.org/content/repositories/snapshots"
9+
}
10+
}
11+
12+
android {
13+
signingConfigs {
14+
release {
15+
storeFile file('wenet.keystore')
16+
storePassword '123456'
17+
keyAlias 'wenet'
18+
keyPassword '123456'
19+
}
20+
}
21+
packagingOptions {
22+
pickFirst 'lib/arm64-v8a/libc++_shared.so'
23+
}
24+
configurations {
25+
extractForNativeBuild
26+
}
27+
compileSdkVersion 30
28+
buildToolsVersion "30.0.3"
29+
30+
defaultConfig {
31+
applicationId "com.mobvoi.WeTextProcessing"
32+
minSdkVersion 21
33+
targetSdkVersion 30
34+
versionCode 1
35+
versionName "1.0"
36+
37+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
38+
externalNativeBuild {
39+
cmake {
40+
targets "wetextprocessing"
41+
cppFlags "-std=c++14", "-DC10_USE_GLOG", "-DC10_USE_MINIMAL_GLOG", "-DANDROID", "-Wno-c++11-narrowing", "-fexceptions"
42+
}
43+
}
44+
45+
ndkVersion '21.1.6352462'
46+
ndk {
47+
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
48+
}
49+
}
50+
51+
buildTypes {
52+
release {
53+
minifyEnabled false
54+
signingConfig signingConfigs.release
55+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
56+
}
57+
}
58+
externalNativeBuild {
59+
cmake {
60+
path "src/main/cpp/CMakeLists.txt"
61+
}
62+
}
63+
compileOptions {
64+
sourceCompatibility JavaVersion.VERSION_1_8
65+
targetCompatibility JavaVersion.VERSION_1_8
66+
}
67+
}
68+
69+
dependencies {
70+
71+
implementation 'androidx.appcompat:appcompat:1.2.0'
72+
implementation 'com.google.android.material:material:1.2.1'
73+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
74+
testImplementation 'junit:junit:4.+'
75+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
76+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
77+
78+
implementation 'com.github.pengzhendong:wenet-openfst-android:1.0.2'
79+
extractForNativeBuild 'com.github.pengzhendong:wenet-openfst-android:1.0.2'
80+
}
81+
82+
task extractAARForNativeBuild {
83+
doLast {
84+
configurations.extractForNativeBuild.files.each {
85+
def file = it.absoluteFile
86+
copy {
87+
from zipTree(file)
88+
into "$buildDir/$file.name"
89+
include "headers/**"
90+
include "jni/**"
91+
}
92+
}
93+
}
94+
}
95+
96+
tasks.whenTaskAdded { task ->
97+
if (task.name.contains('externalNativeBuild')) {
98+
task.dependsOn(extractAARForNativeBuild)
99+
}
100+
}
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.mobvoi.WeTextProcessing;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.mobvoi.WeTextProcessing", appContext.getPackageName());
25+
}
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
package="com.mobvoi.WeTextProcessing">
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+
tools:replace="android:theme"
12+
android:theme="@style/Theme.Wenet">
13+
<activity android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
put tagger.fst and verbalizer.fst here.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required(VERSION 3.4.1)
2+
set(TARGET wetextprocessing)
3+
project(${TARGET} CXX)
4+
set(CMAKE_CXX_STANDARD 14)
5+
include(ExternalProject)
6+
7+
set(CMAKE_VERBOSE_MAKEFILE on)
8+
set(build_DIR ${CMAKE_SOURCE_DIR}/../../../build)
9+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
10+
string(REPLACE "-Wl,--exclude-libs,libgcc_real.a" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
11+
12+
include(openfst)
13+
14+
include_directories(
15+
${CMAKE_SOURCE_DIR}
16+
)
17+
18+
add_subdirectory(utils)
19+
add_subdirectory(processor)
20+
21+
link_libraries(processor android)
22+
add_library(${TARGET} SHARED wetextprocessing.cc)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../cmake
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../../patch

0 commit comments

Comments
 (0)