mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-18 21:49:36 +00:00
Update Android dependencies and example.
This commit is contained in:
parent
f5716c48f5
commit
d42d20189a
|
@ -45,8 +45,9 @@ wasm-bindgen = "0.2"
|
|||
web-sys = { version = "0.3", features = ["EventTarget", "SpeechSynthesis", "SpeechSynthesisErrorCode", "SpeechSynthesisErrorEvent", "SpeechSynthesisEvent", "SpeechSynthesisUtterance", "SpeechSynthesisVoice", "Window", ] }
|
||||
|
||||
[target.'cfg(target_os="android")'.dependencies]
|
||||
jni = "0.19"
|
||||
ndk-glue = "0.6"
|
||||
jni = "0.20"
|
||||
ndk-context = "0.1"
|
||||
ndk-glue = "0.7"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
no-default-features = true
|
|
@ -1,16 +1,16 @@
|
|||
plugins {
|
||||
id "com.android.application"
|
||||
id "kotlin-android"
|
||||
id "org.mozilla.rust-android-gradle.rust-android"
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.3"
|
||||
|
||||
namespace "rs.tts"
|
||||
compileSdkVersion 33
|
||||
ndkVersion "25.1.8937393"
|
||||
defaultConfig {
|
||||
applicationId "rs.tts"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
targetSdkVersion 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
|
@ -21,27 +21,27 @@ android {
|
|||
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation "androidx.core:core-ktx:1.2.0"
|
||||
implementation "androidx.annotation:annotation:1.1.0"
|
||||
implementation "com.google.android.material:material:1.1.0"
|
||||
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
|
||||
}
|
||||
|
||||
apply plugin: "com.github.willir.rust.cargo-ndk-android"
|
||||
apply plugin: "org.mozilla.rust-android-gradle.rust-android"
|
||||
|
||||
cargoNdk {
|
||||
cargo {
|
||||
module = "."
|
||||
libname = "tts"
|
||||
targets = ["arm", "x86"]
|
||||
}
|
||||
|
||||
tasks.whenTaskAdded { task ->
|
||||
if ((task.name == 'javaPreCompileDebug' || task.name == 'javaPreCompileRelease')) {
|
||||
task.dependsOn "cargoBuild"
|
||||
}
|
||||
}
|
||||
|
||||
project.afterEvaluate {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="rs.tts">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application android:allowBackup="true" android:label="@string/app_name">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity android:name=".MainActivity" android:exported="true">
|
||||
<meta-data android:name="android.app.lib_name" android:value="hello_world" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.3.72"
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven {
|
||||
url "https://plugins.gradle.org/m2/"
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:4.1.1"
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "gradle.plugin.com.github.willir.rust:plugin:0.3.4"
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "com.android.application" version "7.3.0" apply false
|
||||
id "com.android.library" version "7.3.0" apply false
|
||||
id "org.jetbrains.kotlin.android" version "1.7.21" apply false
|
||||
id "org.mozilla.rust-android-gradle.rust-android" version "0.9.3" apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
|
|
|
@ -10,5 +10,5 @@ edition = "2018"
|
|||
crate-type = ["dylib"]
|
||||
|
||||
[dependencies]
|
||||
ndk-glue = "0.6"
|
||||
ndk-glue = "0.7"
|
||||
tts = { path = "../.." }
|
|
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
|
|
|
@ -1 +1,8 @@
|
|||
include ":app"
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
include ":app"
|
||||
|
|
|
@ -179,8 +179,9 @@ impl Android {
|
|||
let id = BackendId::Android(bid);
|
||||
*backend_id += 1;
|
||||
drop(backend_id);
|
||||
let native_activity = ndk_glue::native_activity();
|
||||
let vm = Self::vm()?;
|
||||
let ctx = ndk_context::android_context();
|
||||
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
|
||||
let context = unsafe { JObject::from_raw(ctx.context().cast()) };
|
||||
let env = vm.attach_current_thread_permanently()?;
|
||||
let bridge = BRIDGE.lock().unwrap();
|
||||
if let Some(bridge) = &*bridge {
|
||||
|
@ -188,7 +189,7 @@ impl Android {
|
|||
let tts = env.new_object(
|
||||
"android/speech/tts/TextToSpeech",
|
||||
"(Landroid/content/Context;Landroid/speech/tts/TextToSpeech$OnInitListener;)V",
|
||||
&[native_activity.activity().into(), bridge.into()],
|
||||
&[context.into(), bridge.into()],
|
||||
)?;
|
||||
env.call_method(
|
||||
tts,
|
||||
|
@ -229,9 +230,8 @@ impl Android {
|
|||
}
|
||||
|
||||
fn vm() -> Result<JavaVM, jni::errors::Error> {
|
||||
let native_activity = ndk_glue::native_activity();
|
||||
let vm_ptr = native_activity.vm();
|
||||
unsafe { jni::JavaVM::from_raw(vm_ptr) }
|
||||
let ctx = ndk_context::android_context();
|
||||
unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user