android fixes

This commit is contained in:
John Smith 2022-08-22 19:25:00 -04:00
parent 1817679460
commit e112cc4527
7 changed files with 43 additions and 19 deletions

13
Cargo.lock generated
View File

@ -4736,6 +4736,17 @@ dependencies = [
"tracing-core",
]
[[package]]
name = "tracing-android"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12612be8f868a09c0ceae7113ff26afe79d81a24473a393cb9120ece162e86c0"
dependencies = [
"android_log-sys",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-appender"
version = "0.2.2"
@ -5102,7 +5113,6 @@ dependencies = [
name = "veilid-core"
version = "0.1.0"
dependencies = [
"android_logger 0.11.0",
"async-io",
"async-lock",
"async-std",
@ -5177,6 +5187,7 @@ dependencies = [
"tokio-stream",
"tokio-util 0.7.3",
"tracing",
"tracing-android",
"tracing-error",
"tracing-subscriber",
"tracing-wasm",

View File

@ -133,7 +133,7 @@ jni = "^0"
jni-sys = "^0"
ndk = { version = "^0", features = ["trace"] }
ndk-glue = { version = "^0", features = ["logger"] }
android_logger = { version = "^0" }
tracing-android = { version = "^0" }
backtrace = { version = "^0" }
# Dependenices for all Unix (Linux, Android, MacOS, iOS)

View File

@ -195,7 +195,7 @@ impl VeilidCoreContext {
) -> Result<VeilidCoreContext, VeilidAPIError> {
cfg_if! {
if #[cfg(target_os = "android")] {
if utils::android::ANDROID_GLOBALS.lock().is_none() {
if crate::intf::utils::android::ANDROID_GLOBALS.lock().is_none() {
error!("Android globals are not set up");
return Err(VeilidAPIError::Internal { message: "Android globals are not set up".to_owned() });
}

View File

@ -5,14 +5,17 @@
mod get_directories;
pub use get_directories::*;
use crate::veilid_config::VeilidConfigLogLevel;
use crate::xx::*;
use android_logger::{Config, FilterBuilder};
use crate::*;
use backtrace::Backtrace;
use jni::errors::Result as JniResult;
use jni::{objects::GlobalRef, objects::JObject, objects::JString, JNIEnv, JavaVM};
use lazy_static::*;
use log::*;
use std::panic;
use tracing::*;
use tracing_subscriber::prelude::*;
use tracing_subscriber::*;
pub struct AndroidGlobals {
pub vm: JavaVM,
@ -41,19 +44,25 @@ pub fn veilid_core_setup_android<'a>(
env: JNIEnv<'a>,
ctx: JObject<'a>,
log_tag: &'a str,
log_level: Level,
log_level: VeilidConfigLogLevel,
) {
android_logger::init_once(
Config::default()
.with_min_level(log_level)
.with_tag(log_tag)
.with_filter(
FilterBuilder::new()
.filter(Some(log_tag), log_level.to_level_filter())
.build(),
),
);
// Set up subscriber and layers
let subscriber = Registry::default();
let mut layers = Vec::new();
let mut filters = BTreeMap::new();
let filter = VeilidLayerFilter::new(log_level, None);
let layer = tracing_android::layer(log_tag)
.expect("failed to set up android logging")
.with_filter(filter.clone());
filters.insert("system", filter);
layers.push(layer.boxed());
let subscriber = subscriber.with(layers);
subscriber
.try_init()
.expect("failed to init android tracing");
// Set up panic hook for backtraces
panic::set_hook(Box::new(|panic_info| {
let bt = Backtrace::new();
if let Some(location) = panic_info.location() {

View File

@ -3,7 +3,6 @@ use super::*;
use futures_util::stream::FuturesUnordered;
use futures_util::FutureExt;
use stop_token::future::FutureExt as StopTokenFutureExt;
use tokio::task::spawn_blocking;
struct DetectedPublicDialInfo {
dial_info: DialInfo,

View File

@ -68,7 +68,7 @@ cargo {
prebuiltToolchains = true
profile = gradle.startParameter.taskNames.any{it.toLowerCase().contains("debug")} ? "debug" : "release"
features {
defaultAnd("android_tests")
defaultAnd("android_tests", "rt-tokio")
}
}

View File

@ -19,7 +19,12 @@ pub extern "system" fn Java_com_veilid_veilidcore_veilidcore_1android_1tests_Mai
_class: JClass,
ctx: JObject,
) {
crate::intf::utils::android::veilid_core_setup_android(env, ctx, "veilid_core", Level::Trace);
crate::intf::utils::android::veilid_core_setup_android(
env,
ctx,
"veilid_core",
crate::veilid_config::VeilidConfigLogLevel::Trace,
);
run_all_tests();
}