You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am building a Speech to text library for react-native.
So I need to import the thrid party library to my project
Here is the content of my build.gradle
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
}
}
def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}
apply plugin: 'com.android.library'
if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
}
def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['SttReactNative_' + name]
}
def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['SttReactNative_' + name]).toInteger()
}
android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
defaultConfig {
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
}
buildTypes {
release {
minifyEnabled false
}
}
lintOptions {
disable 'GradleCompatible'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}
repositories {
mavenCentral()
google()
def found = false
def defaultDir = null
def androidSourcesName = 'React Native sources'
if (rootProject.ext.has('reactNativeAndroidRoot')) {
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
defaultDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
)
}
if (defaultDir.exists()) {
maven {
url defaultDir.toString()
name androidSourcesName
}
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
found = true
} else {
def parentDir = rootProject.projectDir
1.upto(5, {
if (found) return true
parentDir = parentDir.parentFile
def androidSourcesDir = new File(
parentDir,
'node_modules/react-native'
)
def androidPrebuiltBinaryDir = new File(
parentDir,
'node_modules/react-native/android'
)
if (androidPrebuiltBinaryDir.exists()) {
maven {
url androidPrebuiltBinaryDir.toString()
name androidSourcesName
}
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
found = true
} else if (androidSourcesDir.exists()) {
maven {
url androidSourcesDir.toString()
name androidSourcesName
}
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
found = true
}
})
}
if (!found) {
throw new GradleException(
"${project.name}: unable to locate React Native android sources. " +
"Ensure you have you installed React Native as a dependency in your project and try again."
)
}
}
dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation (files("libs/libstt-1.4.0-alpha.6-release.aar"))
// From node_modules
}
if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
libraryName = "SttReactNative"
codegenJavaPackageName = "com.sttreactnative"
}
}
You can see that I am import the libstt-1.4.0-alpha.6-release.aar from the folder libs.
Its fine at the first but when I write a test for the library which is the function loadModel
package com.sttreactnative;
import android.os.Environment;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.module.annotations.ReactModule;
import ai.coqui.libstt.STTModel;
@ReactModule(name = SttReactNativeModule.NAME)
public class SttReactNativeModule extends ReactContextBaseJavaModule {
public static final String NAME = "SttReactNative";
private STTModel model;
public SttReactNativeModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
@NonNull
public String getName() {
return NAME;
}
// Example method
// See https://reactnative.dev/docs/native-modules-android
@ReactMethod
public void multiply(double a, double b, Promise promise) {
promise.resolve(a * b);
}
@ReactMethod
public void loadModel(String path, Promise promise) {
try {
model = new STTModel("file:/storage/emulated/0/Download/deepspeech-0.9.3-models.tflite");
promise.resolve(Environment.getExternalStorageDirectory().toURI().toString());
}catch (Exception ex) {
promise.reject("Failed to load the model.", ex);
}
}
}
If I remove the line of code model = new STTModel("file:/storage/emulated/0/Download/deepspeech-0.9.3-models.tflite"); there is no error throwed but If I add the line of code there is an error says:
Here is the loadModel function I defined in the src/index.tsx
import { NativeModules, Platform } from 'react-native';
const LINKING_ERROR =
`The package 'stt-react-native' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';
const SttReactNative = NativeModules.SttReactNative
? NativeModules.SttReactNative
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);
export function multiply(a: number, b: number): Promise<number> {
return SttReactNative.multiply(a, b);
}
export function loadModel(path: string): Promise<void> {
return SttReactNative.loadModel(path);
}
And in the example/src/App.tsx I call the function loadModel
import * as React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { multiply, loadModel } from 'stt-react-native';
export default function App() {
const [result, setResult] = React.useState<number | string | undefined>();
React.useEffect(() => {
loadModel("sdf").then((rs) => {
console.info(`The rs is ${rs}`)
setResult(rs)
}).catch((err) => {
console.error(`The error is ${err}`)
setResult("Failed")
})
}, []);
return (
<View style={styles.container}>
<Text>Result: {result}</Text>
</View>
);
}
Its not just that library will throw this error, I installed the implementation 'org.mozilla.deepspeech:libdeepspeech:0.9.2' still will throw an exception says couldnt find xxx.so`
Any ideas? Thanks.
Packages
create-react-native-library
react-native-builder-bob
Selected options
✔ What is the name of the npm package? … react-native-test
✔ What is the description for the package? … ds
✔ What is the name of package author? … test
✔ What is the email address for the package author? … [email protected]
✔ What is the URL for the package author? … test
✔ What is the URL for the repository? … test
✔ What type of library do you want to develop? › Native module
✔ Which languages do you want to use? › Java & Objective-C
Link to repro
No response
Environment
From the root folder
info Fetching system and libraries information...
System:
OS: Linux 5.15 Manjaro Linux
CPU: (16) x64 Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
Memory: 1.29 GB / 15.33 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 19.0.1 - /usr/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 8.19.2 - /usr/bin/npm
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: AI-213.7172.25.2113.9123335
Languages:
Java: 11.0.17 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.6 => 0.70.6
npmGlobalPackages:
*react-native*: Not Found
From the example folder
info Fetching system and libraries information...
System:
OS: Linux 5.15 Manjaro Linux
CPU: (16) x64 Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
Memory: 1.26 GB / 15.33 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 19.0.1 - /usr/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 8.19.2 - /usr/bin/npm
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: AI-213.7172.25.2113.9123335
Languages:
Java: 11.0.17 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.6 => 0.70.6
npmGlobalPackages:
*react-native*: Not Found
This discussion was converted from issue #337 on November 29, 2022 16:53.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Description
I am building a Speech to text library for react-native.
So I need to import the thrid party library to my project
Here is the content of my
build.gradle
You can see that I am import the
libstt-1.4.0-alpha.6-release.aar
from the folder libs.Its fine at the first but when I write a test for the library which is the function
loadModel
If I remove the line of code
model = new STTModel("file:/storage/emulated/0/Download/deepspeech-0.9.3-models.tflite");
there is no error throwed but If I add the line of code there is an error says:Here is the
loadModel
function I defined in thesrc/index.tsx
And in the
example/src/App.tsx
I call the functionloadModel
Its not just that library will throw this error, I installed the
implementation 'org.mozilla.deepspeech:libdeepspeech:0.9.2'
still will throw an exception sayscouldn
t find xxx.so`Any ideas? Thanks.
Packages
Selected options
Link to repro
No response
Environment
From the root folder
From the
example
folderBeta Was this translation helpful? Give feedback.
All reactions